diff --git a/apps/user_ldap/lib/Command/CheckUser.php b/apps/user_ldap/lib/Command/CheckUser.php index 022662d35c0a7..e6b5a634a24a9 100644 --- a/apps/user_ldap/lib/Command/CheckUser.php +++ b/apps/user_ldap/lib/Command/CheckUser.php @@ -91,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $uid = $input->getArgument('ocName'); $this->isAllowed($input->getOption('force')); $this->confirmUserIsMapped($uid); - $exists = $this->backend->userExistsOnLDAP($uid); + $exists = $this->backend->userExistsOnLDAP($uid, true); if ($exists === true) { $output->writeln('The user is still available on LDAP.'); if ($input->getOption('update')) { diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php index fdc7b0c3fbdb9..b1d4da9514d6b 100644 --- a/apps/user_ldap/lib/User_LDAP.php +++ b/apps/user_ldap/lib/User_LDAP.php @@ -296,11 +296,10 @@ public function getUsers($search = '', $limit = 10, $offset = 0) { * * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user * name or an instance of that user - * @return bool * @throws \Exception * @throws \OC\ServerNotAvailableException */ - public function userExistsOnLDAP($user) { + public function userExistsOnLDAP($user, bool $ignoreCache = false): bool { if (is_string($user)) { $user = $this->access->userManager->get($user); } @@ -309,9 +308,11 @@ public function userExistsOnLDAP($user) { } $uid = $user instanceof User ? $user->getUsername() : $user->getOCName(); $cacheKey = 'userExistsOnLDAP' . $uid; - $userExists = $this->access->connection->getFromCache($cacheKey); - if (!is_null($userExists)) { - return (bool)$userExists; + if (!$ignoreCache) { + $userExists = $this->access->connection->getFromCache($cacheKey); + if (!is_null($userExists)) { + return (bool)$userExists; + } } $dn = $user->getDN(); @@ -389,13 +390,27 @@ public function deleteUser($uid) { } } - $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); - if ((int)$marked === 0) { - $this->logger->notice( - 'User '.$uid . ' is not marked as deleted, not cleaning up.', - ['app' => 'user_ldap'] - ); - return false; + $marked = (int)$this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); + if ($marked === 0) { + try { + $user = $this->access->userManager->get($uid); + if (($user instanceof User) && !$this->userExistsOnLDAP($uid, true)) { + $user->markUser(); + $marked = 1; + } + } catch (\Exception $e) { + $this->logger->debug( + $e->getMessage(), + ['app' => 'user_ldap', 'exception' => $e] + ); + } + if ($marked === 0) { + $this->logger->notice( + 'User '.$uid . ' is not marked as deleted, not cleaning up.', + ['app' => 'user_ldap'] + ); + return false; + } } $this->logger->info('Cleaning up after user ' . $uid, ['app' => 'user_ldap']); diff --git a/apps/user_ldap/lib/User_Proxy.php b/apps/user_ldap/lib/User_Proxy.php index 1fdd3cf44b3ec..5731f314aedeb 100644 --- a/apps/user_ldap/lib/User_Proxy.php +++ b/apps/user_ldap/lib/User_Proxy.php @@ -204,11 +204,10 @@ public function userExists($uid) { * * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user * name or an instance of that user - * @return boolean */ - public function userExistsOnLDAP($user) { + public function userExistsOnLDAP($user, bool $ignoreCache = false): bool { $id = ($user instanceof User) ? $user->getUsername() : $user; - return $this->handleRequest($id, 'userExistsOnLDAP', [$user]); + return $this->handleRequest($id, 'userExistsOnLDAP', [$user, $ignoreCache]); } /**