diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/User/BackgroundJobs/CleanupDeletedUsers.php | 17 | ||||
-rw-r--r-- | lib/private/User/PartiallyDeletedUsersBackend.php (renamed from lib/private/User/FailedUsersBackend.php) | 14 | ||||
-rw-r--r-- | lib/private/User/User.php | 6 |
3 files changed, 28 insertions, 9 deletions
diff --git a/lib/private/User/BackgroundJobs/CleanupDeletedUsers.php b/lib/private/User/BackgroundJobs/CleanupDeletedUsers.php index 46ca2175c16..3c1b73637ac 100644 --- a/lib/private/User/BackgroundJobs/CleanupDeletedUsers.php +++ b/lib/private/User/BackgroundJobs/CleanupDeletedUsers.php @@ -8,10 +8,11 @@ declare(strict_types=1); */ namespace OC\User\BackgroundJobs; -use OC\User\FailedUsersBackend; use OC\User\Manager; +use OC\User\PartiallyDeletedUsersBackend; use OC\User\User; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\IJob; use OCP\BackgroundJob\TimedJob; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; @@ -25,11 +26,12 @@ class CleanupDeletedUsers extends TimedJob { private LoggerInterface $logger, ) { parent::__construct($time); - $this->setInterval(3600); + $this->setTimeSensitivity(IJob::TIME_INSENSITIVE); + $this->setInterval(24 * 3600); } protected function run($argument): void { - $backend = new FailedUsersBackend($this->config); + $backend = new PartiallyDeletedUsersBackend($this->config); $users = $backend->getUsers(); if (empty($users)) { @@ -38,12 +40,19 @@ class CleanupDeletedUsers extends TimedJob { } foreach ($users as $userId) { + if ($this->userManager->userExists($userId)) { + $this->logger->info('Skipping user {userId}, marked as deleted, as they still exists in user backend.', ['userId' => $userId]); + $backend->unmarkUser($userId); + continue; + } + try { $user = new User( $userId, $backend, \OCP\Server::get(IEventDispatcher::class), - config: $this->config, + $this->userManager, + $this->config, ); $user->delete(); $this->logger->info('Cleaned up deleted user {userId}', ['userId' => $userId]); diff --git a/lib/private/User/FailedUsersBackend.php b/lib/private/User/PartiallyDeletedUsersBackend.php index 934ceea17da..298ddaff6c6 100644 --- a/lib/private/User/FailedUsersBackend.php +++ b/lib/private/User/PartiallyDeletedUsersBackend.php @@ -15,7 +15,7 @@ use OCP\User\Backend\IGetHomeBackend; * but not properly removed from Nextcloud (e.g. an exception occurred). * This backend is only needed because some APIs in user-deleted-events require a "real" user with backend. */ -class FailedUsersBackend extends Backend implements IGetHomeBackend, IUserBackend { +class PartiallyDeletedUsersBackend extends Backend implements IGetHomeBackend, IUserBackend { public function __construct( private IConfig $config, @@ -36,11 +36,21 @@ class FailedUsersBackend extends Backend implements IGetHomeBackend, IUserBacken } public function getHome(string $uid): string|false { - return $this->config->getUserValue($uid, 'core', 'deleted.backup-home') ?: false; + return $this->config->getUserValue($uid, 'core', 'deleted.home-path') ?: false; } public function getUsers($search = '', $limit = null, $offset = null) { return $this->config->getUsersForUserValue('core', 'deleted', 'true'); } + /** + * Unmark a user as deleted. + * This typically the case if the user deletion failed in the backend but before the backend deleted the user, + * meaning the user still exists so we unmark them as it still can be accessed (and deleted) normally. + */ + public function unmarkUser(string $userId): void { + $this->config->deleteUserValue($userId, 'core', 'deleted'); + $this->config->deleteUserValue($userId, 'core', 'deleted.home-path'); + } + } diff --git a/lib/private/User/User.php b/lib/private/User/User.php index d030f987e5e..6e1085b4fe3 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -250,7 +250,7 @@ class User implements IUser { // because we can not restore the user meaning we could not rollback to any stable state otherwise. $this->config->setUserValue($this->uid, 'core', 'deleted', 'true'); // We also need to backup the home path as this can not be reconstructed later if the original backend uses custom home paths - $this->config->setUserValue($this->uid, 'core', 'deleted.backup-home', $this->getHome()); + $this->config->setUserValue($this->uid, 'core', 'deleted.home-path', $this->getHome()); // Try to delete the user on the backend $result = $this->backend->deleteUser($this->uid); @@ -296,7 +296,7 @@ class User implements IUser { $this->config->deleteAllUserValues($this->uid); // But again set flag that this user is about to be deleted $this->config->setUserValue($this->uid, 'core', 'deleted', 'true'); - $this->config->setUserValue($this->uid, 'core', 'deleted.backup-home', $this->getHome()); + $this->config->setUserValue($this->uid, 'core', 'deleted.home-path', $this->getHome()); // Commit the transaction so we are in a defined state: either the preferences are removed or an exception occurred but the delete flag is still present $database->commit(); } catch (\Throwable $e) { @@ -304,7 +304,7 @@ class User implements IUser { throw $e; } - if ($this->emitter) { + if ($this->emitter !== null) { /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ $this->emitter->emit('\OC\User', 'postDelete', [$this]); } |