From 777b0f10520efd4f98df666f774d431576132ec6 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Tue, 7 Oct 2025 21:23:25 +0200 Subject: [PATCH] fix: ensure user object is available for email reset Signed-off-by: Daniel Kesselberg --- lib/Repair/ResetEmails.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Repair/ResetEmails.php b/lib/Repair/ResetEmails.php index 616b41ad..27b79933 100644 --- a/lib/Repair/ResetEmails.php +++ b/lib/Repair/ResetEmails.php @@ -15,6 +15,7 @@ use OCP\IUserManager; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; +use Psr\Log\LoggerInterface; class ResetEmails implements IRepairStep { public function __construct( @@ -22,6 +23,7 @@ public function __construct( private readonly IUserManager $userManager, private readonly IAppConfig $appConfig, private readonly IConfig $config, + private readonly LoggerInterface $logger, ) { } @@ -39,9 +41,17 @@ public function run(IOutput $output) { foreach ($this->guestManager->listGuests() as $guestId) { $guest = $this->userManager->get($guestId); + if ($guest === null) { + $output->warning('Unable to find user object for guest with id "' . $guestId . '"'); + $this->logger->warning('Unable to find user object for guest', ['guestId' => $guestId]); + continue; + } + $expectedEmail = $this->config->getUserValue($guestId, Application::APP_ID, 'email', strtolower($guestId)); - if (strtolower($guest?->getSystemEMailAddress() ?? '') !== $expectedEmail) { - $this->config->setUserValue($guestId, 'guests', 'old_email', $guest?->getSystemEMailAddress() ?? ''); + $currentEmail = $guest->getSystemEMailAddress() ?? ''; + + if (strtolower($currentEmail) !== $expectedEmail) { + $this->config->setUserValue($guestId, 'guests', 'old_email', $currentEmail); $guest->setSystemEMailAddress($expectedEmail); } }