From eb8bceb30a85d6023fdada3f1e8805ad0cbe3476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Wed, 1 Jul 2026 19:02:19 +0200 Subject: [PATCH 1/3] fix(background-job): complete constructor property promotion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Finish the property modernization started in #158. Promote the remaining IDBConnection and IConfig deps in NotifyUnsetPassword to readonly promoted constructor params, drop the legacy @var docblocks and manual assignments, and add readonly to the already-promoted props in ExpireUnverifiedAccounts for consistency with the rest of the app. Assisted-by: ClaudeCode:claude-opus-4-8 Signed-off-by: John Molakvoæ (skjnldsv) --- lib/BackgroundJob/ExpireUnverifiedAccounts.php | 10 +++++----- lib/BackgroundJob/NotifyUnsetPassword.php | 16 +++------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/lib/BackgroundJob/ExpireUnverifiedAccounts.php b/lib/BackgroundJob/ExpireUnverifiedAccounts.php index 66fbfcf..0471d32 100644 --- a/lib/BackgroundJob/ExpireUnverifiedAccounts.php +++ b/lib/BackgroundJob/ExpireUnverifiedAccounts.php @@ -24,11 +24,11 @@ class ExpireUnverifiedAccounts extends TimedJob { public function __construct( ITimeFactory $timeFactory, - private IConfig $config, - private LoggerInterface $logger, - private IDBConnection $connection, - private VerifyMailHelper $mailHelper, - private IUserManager $userManager, + private readonly IConfig $config, + private readonly LoggerInterface $logger, + private readonly IDBConnection $connection, + private readonly VerifyMailHelper $mailHelper, + private readonly IUserManager $userManager, ) { parent::__construct($timeFactory); diff --git a/lib/BackgroundJob/NotifyUnsetPassword.php b/lib/BackgroundJob/NotifyUnsetPassword.php index cf85055..1eda101 100644 --- a/lib/BackgroundJob/NotifyUnsetPassword.php +++ b/lib/BackgroundJob/NotifyUnsetPassword.php @@ -18,26 +18,16 @@ class NotifyUnsetPassword extends TimedJob { - /** @var string */ - private $appName; - - /** @var IDBConnection */ - private $connection; - - /** @var IConfig */ - private $config; + private string $appName = 'preferred_providers'; public function __construct( ITimeFactory $timeFactory, private readonly LoggerInterface $logger, - IDBConnection $connection, + private readonly IDBConnection $connection, private readonly SetPasswordMailHelper $mailHelper, - IConfig $config, + private readonly IConfig $config, ) { parent::__construct($timeFactory); - $this->appName = 'preferred_providers'; - $this->connection = $connection; - $this->config = $config; // Run once per 5 minutes $this->setInterval(5 * 60); From 125a6ebe39044d0bb5db6e0e7ec7fd16024c3b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Wed, 1 Jul 2026 19:06:13 +0200 Subject: [PATCH 2/3] refactor: use Application::APP_ID const instead of hardcoded app id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the 'preferred_providers' string literals scattered across the background jobs, settings, controller and templates with the existing Application::APP_ID constant, so the app id is hardcoded in a single place. Assisted-by: ClaudeCode:claude-opus-4-8 Signed-off-by: John Molakvoæ (skjnldsv) --- lib/BackgroundJob/ExpireUnverifiedAccounts.php | 5 ++--- lib/BackgroundJob/NotifyUnsetPassword.php | 7 +++---- lib/Controller/SettingsController.php | 7 ++++--- lib/Settings/Admin.php | 3 ++- lib/Settings/Section.php | 5 +++-- templates/flow-login.php | 4 ++-- templates/password-public.php | 4 ++-- templates/settings-admin.php | 4 ++-- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/BackgroundJob/ExpireUnverifiedAccounts.php b/lib/BackgroundJob/ExpireUnverifiedAccounts.php index 0471d32..2e19f5c 100644 --- a/lib/BackgroundJob/ExpireUnverifiedAccounts.php +++ b/lib/BackgroundJob/ExpireUnverifiedAccounts.php @@ -8,6 +8,7 @@ namespace OCA\Preferred_Providers\BackgroundJob; +use OCA\Preferred_Providers\AppInfo\Application; use OCA\Preferred_Providers\Helper\ExpireUserTrait; use OCA\Preferred_Providers\Mailer\VerifyMailHelper; use OCP\AppFramework\Utility\ITimeFactory; @@ -20,8 +21,6 @@ class ExpireUnverifiedAccounts extends TimedJob { use ExpireUserTrait; - private string $appName = 'preferred_providers'; - public function __construct( ITimeFactory $timeFactory, private readonly IConfig $config, @@ -42,7 +41,7 @@ public function __construct( #[\Override] public function run($argument) { // process if token is 5min old - $users = $this->getUsersForUserLowerThanValue($this->appName, 'disable_user_after', strval(time())); + $users = $this->getUsersForUserLowerThanValue(Application::APP_ID, 'disable_user_after', strval(time())); foreach ($users as $userId) { $this->expireUser($userId); } diff --git a/lib/BackgroundJob/NotifyUnsetPassword.php b/lib/BackgroundJob/NotifyUnsetPassword.php index 1eda101..26d7496 100644 --- a/lib/BackgroundJob/NotifyUnsetPassword.php +++ b/lib/BackgroundJob/NotifyUnsetPassword.php @@ -9,6 +9,7 @@ namespace OCA\Preferred_Providers\BackgroundJob; use Exception; +use OCA\Preferred_Providers\AppInfo\Application; use OCA\Preferred_Providers\Mailer\SetPasswordMailHelper; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; @@ -18,8 +19,6 @@ class NotifyUnsetPassword extends TimedJob { - private string $appName = 'preferred_providers'; - public function __construct( ITimeFactory $timeFactory, private readonly LoggerInterface $logger, @@ -39,13 +38,13 @@ public function __construct( #[\Override] public function run($argument) { // process if token is 5min old - $users = $this->getUsersForUserLowerThanValue($this->appName, 'remind_password', strval(time() - 5 * 60)); + $users = $this->getUsersForUserLowerThanValue(Application::APP_ID, 'remind_password', strval(time() - 5 * 60)); foreach ($users as $userId) { $emailTemplate = $this->mailHelper->generateTemplate($userId); try { $this->mailHelper->sendMail($userId, $emailTemplate); // only send one mail - $this->config->deleteUserValue($userId, $this->appName, 'remind_password'); + $this->config->deleteUserValue($userId, Application::APP_ID, 'remind_password'); $this->logger->debug('Password definition mail sent to ' . $userId); } catch (Exception) { $this->logger->debug('Error while sending the password definition mail to ' . $userId); diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 89dde6b..276d6ed 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -9,6 +9,7 @@ namespace OCA\Preferred_Providers\Controller; +use OCA\Preferred_Providers\AppInfo\Application; use OCA\Preferred_Providers\Mailer\VerifyMailHelper; use OCP\App\IAppManager; use OCP\AppFramework\Http\Attribute\ApiRoute; @@ -60,7 +61,7 @@ public function __construct( #[ApiRoute(verb: 'GET', url: '/api/v1/token/new')] public function resetToken(): DataResponse { $provider_token = md5($this->secureRandom->generate(10)); - $this->appConfig->setValueString('preferred_providers', 'provider_token', $provider_token); + $this->appConfig->setValueString(Application::APP_ID, 'provider_token', $provider_token); return new DataResponse(['token' => $provider_token]); } @@ -81,9 +82,9 @@ public function setGroups(array $groups = [], string $for = 'all'): DataResponse } if ($for === 'all') { - $this->appConfig->setValueString('preferred_providers', 'provider_groups', implode(',', $groups)); + $this->appConfig->setValueString(Application::APP_ID, 'provider_groups', implode(',', $groups)); } elseif ($for === 'confirmed' || $for === 'unconfirmed') { - $this->appConfig->setValueString('preferred_providers', 'provider_groups_' . $for, implode(',', $groups)); + $this->appConfig->setValueString(Application::APP_ID, 'provider_groups_' . $for, implode(',', $groups)); } else { throw new OCSBadRequestException(); } diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index f14602e..c864441 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -8,6 +8,7 @@ namespace OCA\Preferred_Providers\Settings; +use OCA\Preferred_Providers\AppInfo\Application; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IGroupManager; @@ -76,7 +77,7 @@ public function getForm() { */ #[\Override] public function getSection() { - return 'preferred_providers'; + return Application::APP_ID; } /** diff --git a/lib/Settings/Section.php b/lib/Settings/Section.php index 5d46a7e..f0d36b9 100644 --- a/lib/Settings/Section.php +++ b/lib/Settings/Section.php @@ -8,6 +8,7 @@ namespace OCA\Preferred_Providers\Settings; +use OCA\Preferred_Providers\AppInfo\Application; use OCP\IL10N; use OCP\IURLGenerator; use OCP\Settings\IIconSection; @@ -35,7 +36,7 @@ public function __construct(IURLGenerator $url, IL10N $l) { */ #[\Override] public function getID() { - return 'preferred_providers'; + return Application::APP_ID; } /** @@ -66,6 +67,6 @@ public function getPriority() { */ #[\Override] public function getIcon() { - return $this->url->imagePath('preferred_providers', 'app-dark.svg'); + return $this->url->imagePath(Application::APP_ID, 'app-dark.svg'); } } diff --git a/templates/flow-login.php b/templates/flow-login.php index 939b766..711ee98 100644 --- a/templates/flow-login.php +++ b/templates/flow-login.php @@ -5,8 +5,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -\OCP\Util::addScript('preferred_providers', 'flow-login'); -\OCP\Util::addStyle('preferred_providers', 'password-public'); +\OCP\Util::addScript(\OCA\Preferred_Providers\AppInfo\Application::APP_ID, 'flow-login'); +\OCP\Util::addStyle(\OCA\Preferred_Providers\AppInfo\Application::APP_ID, 'password-public'); ?>