Skip to content

Commit cb519bb

Browse files
committed
refactor(MailQueueHandler): inject IAppConfig instead of using deprecated IConfig::getAppValue
Reviewer suggestion: inject IAppConfig and use getValueString() to check the enable_email toggle, avoiding the deprecated getAppValue() path. AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent fed304c commit cb519bb

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use OCP\AppFramework\Bootstrap\IBootstrap;
3232
use OCP\AppFramework\Bootstrap\IRegistrationContext;
3333
use OCP\DB\Events\AddMissingIndicesEvent;
34+
use OCP\IAppConfig;
3435
use OCP\IConfig;
3536
use OCP\IDateTimeFormatter;
3637
use OCP\IDBConnection;
@@ -117,6 +118,7 @@ public function register(IRegistrationContext $context): void {
117118
$c->get(IFactory::class),
118119
$c->get(IManager::class),
119120
$c->get(IValidator::class),
121+
$c->get(IAppConfig::class),
120122
$c->get(IConfig::class),
121123
$c->get(LoggerInterface::class),
122124
$c->get(Data::class),

lib/MailQueueHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OCP\Activity\IManager;
1212
use OCP\DB\QueryBuilder\IQueryBuilder;
1313
use OCP\Defaults;
14+
use OCP\IAppConfig;
1415
use OCP\IConfig;
1516
use OCP\IDateTimeFormatter;
1617
use OCP\IDBConnection;
@@ -51,6 +52,7 @@ public function __construct(
5152
protected IFactory $lFactory,
5253
protected IManager $activityManager,
5354
protected IValidator $richObjectValidator,
55+
protected IAppConfig $appConfig,
5456
protected IConfig $config,
5557
protected LoggerInterface $logger,
5658
protected Data $data,
@@ -70,7 +72,7 @@ public function __construct(
7072
* @return int Number of users we sent an email to
7173
*/
7274
public function sendEmails(int $limit, int $sendTime, bool $forceSending = false, ?int $restrictEmails = null): int {
73-
if ($this->config->getAppValue('activity', 'enable_email', 'yes') === 'no') {
75+
if ($this->appConfig->getValueString('activity', 'enable_email', 'yes') === 'no') {
7476
return 0;
7577
}
7678

tests/MailQueueHandlerTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use OCA\Activity\UserSettings;
3535
use OCP\Activity\IEvent;
3636
use OCP\Activity\IManager;
37+
use OCP\IAppConfig;
3738
use OCP\IConfig;
3839
use OCP\IDateTimeFormatter;
3940
use OCP\IDBConnection;
@@ -65,6 +66,7 @@ class MailQueueHandlerTest extends TestCase {
6566
protected IFactory&MockObject $lFactory;
6667
protected IManager&MockObject $activityManager;
6768
protected IValidator&MockObject $richObjectValidator;
69+
protected IAppConfig&MockObject $appConfig;
6870
protected IConfig&MockObject $config;
6971
protected MockObject&LoggerInterface $logger;
7072

@@ -81,6 +83,10 @@ protected function setUp(): void {
8183
$app = self::getUniqueID('MailQueueHandlerTest', 10);
8284
$this->userManager = $this->createMock(IUserManager::class);
8385
$this->lFactory = $this->createMock(IFactory::class);
86+
$this->appConfig = $this->createMock(IAppConfig::class);
87+
$this->appConfig->method('getValueString')
88+
->with('activity', 'enable_email', 'yes')
89+
->willReturn('yes');
8490
$this->config = $this->createMock(IConfig::class);
8591
$this->logger = $this->createMock(LoggerInterface::class);
8692
$this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class);
@@ -141,6 +147,7 @@ protected function setUp(): void {
141147
$this->lFactory,
142148
$this->activityManager,
143149
$this->richObjectValidator,
150+
$this->appConfig,
144151
$this->config,
145152
$this->logger,
146153
$this->data,
@@ -373,7 +380,7 @@ public function testSendEmailsDeletesQueueOnSendReturnFalse(): void {
373380
public function testSendEmailsSkipsWhenAdminEmailDisabled(): void {
374381
$maxTime = 200;
375382

376-
$this->config->method('getAppValue')
383+
$this->appConfig->method('getValueString')
377384
->with('activity', 'enable_email', 'yes')
378385
->willReturn('no');
379386

0 commit comments

Comments
 (0)