From 915528a7e727cc6cef3440f589a4ebc4d2ddcbc2 Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Tue, 10 Dec 2024 10:47:16 +0530 Subject: [PATCH 1/7] Invalidate session and reset last login --- .../InvalidateSessionsAndResetLastLogin.php | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 lib/Command/InvalidateSessionsAndResetLastLogin.php diff --git a/lib/Command/InvalidateSessionsAndResetLastLogin.php b/lib/Command/InvalidateSessionsAndResetLastLogin.php new file mode 100644 index 00000000..179a9448 --- /dev/null +++ b/lib/Command/InvalidateSessionsAndResetLastLogin.php @@ -0,0 +1,100 @@ +userManager = $userManager; + $this->dbConnection = $dbConnection; + parent::__construct(); + } + + protected function configure(): void { + $this + ->setName('ecloud-accounts:invalidate-sessions-reset-lastlogin') + ->setDescription('Invalidates user sessions and resets lastlogin for users created after a specified date') + ->addOption( + 'created-after', + null, + InputOption::VALUE_REQUIRED, + 'Users created after this date (format: YYYY-MM-DD)', + '' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + try { + $this->commandOutput = $output; + $createdAfter = $input->getOption('created-after'); + + if (empty($createdAfter) || !strtotime($createdAfter)) { + $output->writeln('Invalid or missing date for --created-after.'); + return 1; + } + + $users = $this->getUsersCreatedAfter($createdAfter); + if (empty($users)) { + $output->writeln('No users found created after ' . $createdAfter . '.'); + return 0; + } + + $this->invalidateSessions($users); + $this->resetLastLogin($users); + + $output->writeln('Successfully invalidated sessions and reset lastlogin for users:'); + $output->writeln(implode(', ', $users)); + + return 0; + } catch (\Exception $e) { + $this->commandOutput->writeln('' . $e->getMessage() . ''); + return 1; + } + } + + private function getUsersCreatedAfter(string $date): array { + $queryBuilder = $this->dbConnection->getQueryBuilder(); + $queryBuilder->select('uid') + ->from('users') + ->where($queryBuilder->expr()->gt('creation_date', $queryBuilder->createNamedParameter($date, IQueryBuilder::PARAM_STR))); + + $result = $queryBuilder->executeQuery(); + return $result->fetchFirstColumn(); + } + + private function invalidateSessions(array $userIds): void { + $queryBuilder = $this->dbConnection->getQueryBuilder(); + $queryBuilder->delete('authtoken') + ->where($queryBuilder->expr()->in('user', $queryBuilder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY))); + + $queryBuilder->executeStatement(); + $this->commandOutput->writeln('Invalidated sessions for ' . count($userIds) . ' users.'); + } + + private function resetLastLogin(array $userIds): void { + $queryBuilder = $this->dbConnection->getQueryBuilder(); + $queryBuilder->update('preferences') + ->set('configvalue', $queryBuilder->createNamedParameter(null)) + ->where($queryBuilder->expr()->in('user_id', $queryBuilder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY))) + ->andWhere($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('login'))) + ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('lastlogin'))); + + $queryBuilder->executeStatement(); + $this->commandOutput->writeln('Reset lastlogin for ' . count($userIds) . ' users.'); + } +} -- GitLab From 3b0af6a1da34d4ae49f5ccbc78f8349e3cb934d5 Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Tue, 10 Dec 2024 11:09:32 +0530 Subject: [PATCH 2/7] fetch ldap records and logout session --- .../InvalidateSessionsAndResetLastLogin.php | 100 ---------------- lib/Command/ResetUserSessions.php | 112 ++++++++++++++++++ lib/Service/LDAPConnectionService.php | 35 ++++++ 3 files changed, 147 insertions(+), 100 deletions(-) delete mode 100644 lib/Command/InvalidateSessionsAndResetLastLogin.php create mode 100644 lib/Command/ResetUserSessions.php diff --git a/lib/Command/InvalidateSessionsAndResetLastLogin.php b/lib/Command/InvalidateSessionsAndResetLastLogin.php deleted file mode 100644 index 179a9448..00000000 --- a/lib/Command/InvalidateSessionsAndResetLastLogin.php +++ /dev/null @@ -1,100 +0,0 @@ -userManager = $userManager; - $this->dbConnection = $dbConnection; - parent::__construct(); - } - - protected function configure(): void { - $this - ->setName('ecloud-accounts:invalidate-sessions-reset-lastlogin') - ->setDescription('Invalidates user sessions and resets lastlogin for users created after a specified date') - ->addOption( - 'created-after', - null, - InputOption::VALUE_REQUIRED, - 'Users created after this date (format: YYYY-MM-DD)', - '' - ); - } - - protected function execute(InputInterface $input, OutputInterface $output): int { - try { - $this->commandOutput = $output; - $createdAfter = $input->getOption('created-after'); - - if (empty($createdAfter) || !strtotime($createdAfter)) { - $output->writeln('Invalid or missing date for --created-after.'); - return 1; - } - - $users = $this->getUsersCreatedAfter($createdAfter); - if (empty($users)) { - $output->writeln('No users found created after ' . $createdAfter . '.'); - return 0; - } - - $this->invalidateSessions($users); - $this->resetLastLogin($users); - - $output->writeln('Successfully invalidated sessions and reset lastlogin for users:'); - $output->writeln(implode(', ', $users)); - - return 0; - } catch (\Exception $e) { - $this->commandOutput->writeln('' . $e->getMessage() . ''); - return 1; - } - } - - private function getUsersCreatedAfter(string $date): array { - $queryBuilder = $this->dbConnection->getQueryBuilder(); - $queryBuilder->select('uid') - ->from('users') - ->where($queryBuilder->expr()->gt('creation_date', $queryBuilder->createNamedParameter($date, IQueryBuilder::PARAM_STR))); - - $result = $queryBuilder->executeQuery(); - return $result->fetchFirstColumn(); - } - - private function invalidateSessions(array $userIds): void { - $queryBuilder = $this->dbConnection->getQueryBuilder(); - $queryBuilder->delete('authtoken') - ->where($queryBuilder->expr()->in('user', $queryBuilder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY))); - - $queryBuilder->executeStatement(); - $this->commandOutput->writeln('Invalidated sessions for ' . count($userIds) . ' users.'); - } - - private function resetLastLogin(array $userIds): void { - $queryBuilder = $this->dbConnection->getQueryBuilder(); - $queryBuilder->update('preferences') - ->set('configvalue', $queryBuilder->createNamedParameter(null)) - ->where($queryBuilder->expr()->in('user_id', $queryBuilder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY))) - ->andWhere($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('login'))) - ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('lastlogin'))); - - $queryBuilder->executeStatement(); - $this->commandOutput->writeln('Reset lastlogin for ' . count($userIds) . ' users.'); - } -} diff --git a/lib/Command/ResetUserSessions.php b/lib/Command/ResetUserSessions.php new file mode 100644 index 00000000..8e2fbd84 --- /dev/null +++ b/lib/Command/ResetUserSessions.php @@ -0,0 +1,112 @@ +ldapService = $ldapService; + $this->db = $db; + parent::__construct(); + } + /** + * How to run: `occ ecloud-accounts:reset-user-sessions --date=20241201000000Z` + * @return void + */ + protected function configure(): void { + $this + ->setName('ecloud-accounts:reset-user-sessions') + ->setDescription('Invalidate sessions and reset first login for users created after a specific date') + ->addOption( + 'date', + null, + InputOption::VALUE_REQUIRED, + 'Date in YYYYMMDDHHMMSSZ format (e.g., 20241201000000Z)', + null + ); + } + /** + * Execute function + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Symfony\Component\Console\Output\OutputInterface $output + * @return int + */ + protected function execute(InputInterface $input, OutputInterface $output): int { + $date = $input->getOption('date'); + + if (!$date) { + $output->writeln('Date option is required.'); + return Command::INVALID; + } + + try { + $users = $this->ldapService->getUsersCreatedAfter($date); + foreach ($users as $user) { + if (!$user['username']) { + continue; + } + + $output->writeln("Processing user: " . $user['username']); + + // Invalidate sessions + $this->invalidateUserSessions($user['username']); + $output->writeln("Invalidated session for user: " . $user['username']); + + // Reset first login + $this->resetFirstLogin($user['username']); + $output->writeln("Reset first login for user: " . $user['username']); + } + + $output->writeln('All sessions invalidated and first login reset for eligible users.'); + return Command::SUCCESS; + } catch (\Exception $e) { + $output->writeln('Error:' . $e->getMessage()); + return Command::FAILURE; + } + } + /** + * Invalidate user sessions for username + * @param string $username + * @return void + */ + private function invalidateUserSessions(string $username): void { + $qb = $this->db->getQueryBuilder(); + + $qb->delete('authtoken') + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($username, IQueryBuilder::PARAM_STR))); + + $qb->executeStatement(); + } + /** + * Reset firsst login + * @param string $username + * @return void + */ + private function resetFirstLogin(string $username): void { + $qb = $this->db->getQueryBuilder(); + + $qb->update('preferences') + ->set('configvalue', $qb->createNamedParameter('0', IQueryBuilder::PARAM_STR)) + ->where($qb->expr()->eq('userid', $qb->createNamedParameter($username, IQueryBuilder::PARAM_STR))) + ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('firstLogin', IQueryBuilder::PARAM_STR))); + + $qb->executeStatement(); + } +} diff --git a/lib/Service/LDAPConnectionService.php b/lib/Service/LDAPConnectionService.php index f7609941..7aa63157 100644 --- a/lib/Service/LDAPConnectionService.php +++ b/lib/Service/LDAPConnectionService.php @@ -122,4 +122,39 @@ class LDAPConnectionService { $this->closeLDAPConnection($conn); } + public function getUsersCreatedAfter(string $date): array { + if (!$this->isLDAPEnabled()) { + throw new Exception('LDAP backend is not enabled'); + } + + // Convert the provided date to LDAP Generalized Time format: YYYYMMDDHHMMSSZ + $formattedDate = (new \DateTime($date))->format('YmdHis') . 'Z'; + + $conn = $this->getLDAPConnection(); + $baseDn = implode(',', $this->getLDAPBaseUsers()); + $filter = sprintf('(createTimestamp>=%s)', $formattedDate); + + $searchResult = ldap_search($conn, $baseDn, $filter, ['dn', 'username', 'createTimestamp']); + if (!$searchResult) { + $this->closeLDAPConnection($conn); + throw new Exception('LDAP search failed for createTimestamp after: ' . $date); + } + + $entries = ldap_get_entries($conn, $searchResult); + $this->closeLDAPConnection($conn); + + $users = []; + if ($entries['count'] > 0) { + for ($i = 0; $i < $entries['count']; $i++) { + $users[] = [ + 'dn' => $entries[$i]['dn'], + 'username' => $entries[$i]['username'][0] ?? null, + 'createTimestamp' => $entries[$i]['createtimestamp'][0] ?? null, + ]; + } + } + + return $users; + } + } -- GitLab From f209b53ae1f6d82137c79893bdadb2f077a6cb2f Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Tue, 10 Dec 2024 11:34:38 +0530 Subject: [PATCH 3/7] code changes --- lib/Command/ResetUserPreferences.php | 96 +++++++++++++++++++++++ lib/Command/ResetUserSessions.php | 112 --------------------------- 2 files changed, 96 insertions(+), 112 deletions(-) create mode 100644 lib/Command/ResetUserPreferences.php delete mode 100644 lib/Command/ResetUserSessions.php diff --git a/lib/Command/ResetUserPreferences.php b/lib/Command/ResetUserPreferences.php new file mode 100644 index 00000000..35c7e277 --- /dev/null +++ b/lib/Command/ResetUserPreferences.php @@ -0,0 +1,96 @@ +ldapService = $ldapService; + $this->db = $db; + parent::__construct(); + } + + protected function configure(): void { + $this + ->setName('ecloud-accounts:reset-user-preferences') + ->setDescription('Invalidate sessions and remove preferences for users created after a specific date') + ->addOption( + 'date', + null, + InputOption::VALUE_REQUIRED, + 'Date in YYYYMMDDHHMMSSZ format (e.g., 20241201000000Z)', + null + ); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + $date = $input->getOption('date'); + + if (!$date) { + $output->writeln('Date option is required.'); + return Command::INVALID; + } + + try { + // Fetch users from LDAP + $users = $this->ldapService->getUsersCreatedAfter($date); + + foreach ($users as $user) { + if (!$user['username']) { + continue; + } + + $username = $user['username']; + $output->writeln("Processing user: $username"); + + // Invalidate user sessions + $this->invalidateUserSessions($username); + $output->writeln("Invalidated session for user: $username"); + + // Delete specific preferences + $this->deletePreference($username, 'firstLoginAccomplished'); + $output->writeln("Deleted 'firstLoginAccomplished' preference for user: $username"); + + $this->deletePreference($username, 'lastLogin'); + $output->writeln("Deleted 'lastLogin' preference for user: $username"); + } + + $output->writeln('All sessions invalidated and preferences deleted for eligible users.'); + return Command::SUCCESS; + } catch (\Exception $e) { + $output->writeln('' . $e->getMessage() . ''); + return Command::FAILURE; + } + } + + private function invalidateUserSessions(string $username): void { + $qb = $this->db->getQueryBuilder(); + + $qb->delete('authtoken') + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($username, IQueryBuilder::PARAM_STR))); + + $qb->executeStatement(); + } + + private function deletePreference(string $username, string $key): void { + $qb = $this->db->getQueryBuilder(); + + $qb->delete('preferences') + ->where($qb->expr()->eq('userid', $qb->createNamedParameter($username, IQueryBuilder::PARAM_STR))) + ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter($key, IQueryBuilder::PARAM_STR))); + + $qb->executeStatement(); + } +} diff --git a/lib/Command/ResetUserSessions.php b/lib/Command/ResetUserSessions.php deleted file mode 100644 index 8e2fbd84..00000000 --- a/lib/Command/ResetUserSessions.php +++ /dev/null @@ -1,112 +0,0 @@ -ldapService = $ldapService; - $this->db = $db; - parent::__construct(); - } - /** - * How to run: `occ ecloud-accounts:reset-user-sessions --date=20241201000000Z` - * @return void - */ - protected function configure(): void { - $this - ->setName('ecloud-accounts:reset-user-sessions') - ->setDescription('Invalidate sessions and reset first login for users created after a specific date') - ->addOption( - 'date', - null, - InputOption::VALUE_REQUIRED, - 'Date in YYYYMMDDHHMMSSZ format (e.g., 20241201000000Z)', - null - ); - } - /** - * Execute function - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Symfony\Component\Console\Output\OutputInterface $output - * @return int - */ - protected function execute(InputInterface $input, OutputInterface $output): int { - $date = $input->getOption('date'); - - if (!$date) { - $output->writeln('Date option is required.'); - return Command::INVALID; - } - - try { - $users = $this->ldapService->getUsersCreatedAfter($date); - foreach ($users as $user) { - if (!$user['username']) { - continue; - } - - $output->writeln("Processing user: " . $user['username']); - - // Invalidate sessions - $this->invalidateUserSessions($user['username']); - $output->writeln("Invalidated session for user: " . $user['username']); - - // Reset first login - $this->resetFirstLogin($user['username']); - $output->writeln("Reset first login for user: " . $user['username']); - } - - $output->writeln('All sessions invalidated and first login reset for eligible users.'); - return Command::SUCCESS; - } catch (\Exception $e) { - $output->writeln('Error:' . $e->getMessage()); - return Command::FAILURE; - } - } - /** - * Invalidate user sessions for username - * @param string $username - * @return void - */ - private function invalidateUserSessions(string $username): void { - $qb = $this->db->getQueryBuilder(); - - $qb->delete('authtoken') - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($username, IQueryBuilder::PARAM_STR))); - - $qb->executeStatement(); - } - /** - * Reset firsst login - * @param string $username - * @return void - */ - private function resetFirstLogin(string $username): void { - $qb = $this->db->getQueryBuilder(); - - $qb->update('preferences') - ->set('configvalue', $qb->createNamedParameter('0', IQueryBuilder::PARAM_STR)) - ->where($qb->expr()->eq('userid', $qb->createNamedParameter($username, IQueryBuilder::PARAM_STR))) - ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('firstLogin', IQueryBuilder::PARAM_STR))); - - $qb->executeStatement(); - } -} -- GitLab From f9d311063c985677fc69f0173811b60c7184830a Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Tue, 10 Dec 2024 11:35:45 +0530 Subject: [PATCH 4/7] code changes --- lib/Command/ResetUserPreferences.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Command/ResetUserPreferences.php b/lib/Command/ResetUserPreferences.php index 35c7e277..91ae0ec9 100644 --- a/lib/Command/ResetUserPreferences.php +++ b/lib/Command/ResetUserPreferences.php @@ -21,7 +21,10 @@ class ResetUserPreferences extends Command { $this->db = $db; parent::__construct(); } - + /** + * run: occ ecloud-accounts:reset-user-preferences --date=20241201000000Z + * @return void + */ protected function configure(): void { $this ->setName('ecloud-accounts:reset-user-preferences') @@ -39,7 +42,7 @@ class ResetUserPreferences extends Command { $date = $input->getOption('date'); if (!$date) { - $output->writeln('Date option is required.'); + $output->writeln('Date option is required.'); return Command::INVALID; } @@ -67,10 +70,10 @@ class ResetUserPreferences extends Command { $output->writeln("Deleted 'lastLogin' preference for user: $username"); } - $output->writeln('All sessions invalidated and preferences deleted for eligible users.'); + $output->writeln('All sessions invalidated and preferences deleted for eligible users.'); return Command::SUCCESS; } catch (\Exception $e) { - $output->writeln('' . $e->getMessage() . ''); + $output->writeln('Error: ' . $e->getMessage() ); return Command::FAILURE; } } -- GitLab From 7ba1ec2a50f2336768903b026b03e1127ec069b2 Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Tue, 10 Dec 2024 12:50:02 +0530 Subject: [PATCH 5/7] php fs --- lib/Command/ResetUserPreferences.php | 166 +++++++++++++-------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/lib/Command/ResetUserPreferences.php b/lib/Command/ResetUserPreferences.php index 91ae0ec9..13c855e8 100644 --- a/lib/Command/ResetUserPreferences.php +++ b/lib/Command/ResetUserPreferences.php @@ -13,87 +13,87 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class ResetUserPreferences extends Command { - private LDAPConnectionService $ldapService; - private IDBConnection $db; - - public function __construct(LDAPConnectionService $ldapService, IDBConnection $db) { - $this->ldapService = $ldapService; - $this->db = $db; - parent::__construct(); - } - /** - * run: occ ecloud-accounts:reset-user-preferences --date=20241201000000Z - * @return void - */ - protected function configure(): void { - $this - ->setName('ecloud-accounts:reset-user-preferences') - ->setDescription('Invalidate sessions and remove preferences for users created after a specific date') - ->addOption( - 'date', - null, - InputOption::VALUE_REQUIRED, - 'Date in YYYYMMDDHHMMSSZ format (e.g., 20241201000000Z)', - null - ); - } - - protected function execute(InputInterface $input, OutputInterface $output): int { - $date = $input->getOption('date'); - - if (!$date) { - $output->writeln('Date option is required.'); - return Command::INVALID; - } - - try { - // Fetch users from LDAP - $users = $this->ldapService->getUsersCreatedAfter($date); - - foreach ($users as $user) { - if (!$user['username']) { - continue; - } - - $username = $user['username']; - $output->writeln("Processing user: $username"); - - // Invalidate user sessions - $this->invalidateUserSessions($username); - $output->writeln("Invalidated session for user: $username"); - - // Delete specific preferences - $this->deletePreference($username, 'firstLoginAccomplished'); - $output->writeln("Deleted 'firstLoginAccomplished' preference for user: $username"); - - $this->deletePreference($username, 'lastLogin'); - $output->writeln("Deleted 'lastLogin' preference for user: $username"); - } - - $output->writeln('All sessions invalidated and preferences deleted for eligible users.'); - return Command::SUCCESS; - } catch (\Exception $e) { - $output->writeln('Error: ' . $e->getMessage() ); - return Command::FAILURE; - } - } - - private function invalidateUserSessions(string $username): void { - $qb = $this->db->getQueryBuilder(); - - $qb->delete('authtoken') - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($username, IQueryBuilder::PARAM_STR))); - - $qb->executeStatement(); - } - - private function deletePreference(string $username, string $key): void { - $qb = $this->db->getQueryBuilder(); - - $qb->delete('preferences') - ->where($qb->expr()->eq('userid', $qb->createNamedParameter($username, IQueryBuilder::PARAM_STR))) - ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter($key, IQueryBuilder::PARAM_STR))); - - $qb->executeStatement(); - } + private LDAPConnectionService $ldapService; + private IDBConnection $db; + + public function __construct(LDAPConnectionService $ldapService, IDBConnection $db) { + $this->ldapService = $ldapService; + $this->db = $db; + parent::__construct(); + } + /** + * run: occ ecloud-accounts:reset-user-preferences --date=20241201000000Z + * @return void + */ + protected function configure(): void { + $this + ->setName('ecloud-accounts:reset-user-preferences') + ->setDescription('Invalidate sessions and remove preferences for users created after a specific date') + ->addOption( + 'date', + null, + InputOption::VALUE_REQUIRED, + 'Date in YYYYMMDDHHMMSSZ format (e.g., 20241201000000Z)', + null + ); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + $date = $input->getOption('date'); + + if (!$date) { + $output->writeln('Date option is required.'); + return Command::INVALID; + } + + try { + // Fetch users from LDAP + $users = $this->ldapService->getUsersCreatedAfter($date); + + foreach ($users as $user) { + if (!$user['username']) { + continue; + } + + $username = $user['username']; + $output->writeln("Processing user: $username"); + + // Invalidate user sessions + $this->invalidateUserSessions($username); + $output->writeln("Invalidated session for user: $username"); + + // Delete specific preferences + $this->deletePreference($username, 'firstLoginAccomplished'); + $output->writeln("Deleted 'firstLoginAccomplished' preference for user: $username"); + + $this->deletePreference($username, 'lastLogin'); + $output->writeln("Deleted 'lastLogin' preference for user: $username"); + } + + $output->writeln('All sessions invalidated and preferences deleted for eligible users.'); + return Command::SUCCESS; + } catch (\Exception $e) { + $output->writeln('Error: ' . $e->getMessage()); + return Command::FAILURE; + } + } + + private function invalidateUserSessions(string $username): void { + $qb = $this->db->getQueryBuilder(); + + $qb->delete('authtoken') + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($username, IQueryBuilder::PARAM_STR))); + + $qb->executeStatement(); + } + + private function deletePreference(string $username, string $key): void { + $qb = $this->db->getQueryBuilder(); + + $qb->delete('preferences') + ->where($qb->expr()->eq('userid', $qb->createNamedParameter($username, IQueryBuilder::PARAM_STR))) + ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter($key, IQueryBuilder::PARAM_STR))); + + $qb->executeStatement(); + } } -- GitLab From 1a3bf47ddbe8d7fce2ba18a467d18a60967661d3 Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Tue, 10 Dec 2024 13:04:30 +0530 Subject: [PATCH 6/7] php fs --- lib/Command/ResetUserPreferences.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Command/ResetUserPreferences.php b/lib/Command/ResetUserPreferences.php index 13c855e8..15b5189a 100644 --- a/lib/Command/ResetUserPreferences.php +++ b/lib/Command/ResetUserPreferences.php @@ -33,7 +33,7 @@ class ResetUserPreferences extends Command { 'date', null, InputOption::VALUE_REQUIRED, - 'Date in YYYYMMDDHHMMSSZ format (e.g., 20241201000000Z)', + 'Date in YYYY-MM-DD HH-MM-SS format (e.g., 2024-12-01 00:00:00)', null ); } -- GitLab From 6f5d9375c59cabd7b68abd85a3339fd5a06c8319 Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Tue, 10 Dec 2024 13:09:20 +0530 Subject: [PATCH 7/7] command added in info.xml --- appinfo/info.xml | 1 + lib/Command/ResetUserPreferences.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 35a9b216..078c5641 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -28,5 +28,6 @@ OCA\EcloudAccounts\Command\Migrate2FASecrets OCA\EcloudAccounts\Command\MigrateWebmailAddressbooks OCA\EcloudAccounts\Command\MapActiveAttributetoLDAP + OCA\EcloudAccounts\Command\ResetUserPreferences diff --git a/lib/Command/ResetUserPreferences.php b/lib/Command/ResetUserPreferences.php index 15b5189a..1bef4c86 100644 --- a/lib/Command/ResetUserPreferences.php +++ b/lib/Command/ResetUserPreferences.php @@ -22,7 +22,7 @@ class ResetUserPreferences extends Command { parent::__construct(); } /** - * run: occ ecloud-accounts:reset-user-preferences --date=20241201000000Z + * run: occ ecloud-accounts:reset-user-preferences --date='2024-12-01 00:00:00' * @return void */ protected function configure(): void { -- GitLab