aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-03-13 10:06:39 +0100
committerGitHub <noreply@github.com>2024-03-13 10:06:39 +0100
commit0ce35c707f81c56678bb8533bfb9b64af8cc84bf (patch)
treee3d30f7527f8d434e287dd541210cdc891a53ab8 /apps
parent463a68f0c9aafa6cacfac7fd8f1ddc6554561d59 (diff)
parent519e4345739876d2ae7e064e347d19524905b090 (diff)
downloadnextcloud-server-0ce35c707f81c56678bb8533bfb9b64af8cc84bf.tar.gz
nextcloud-server-0ce35c707f81c56678bb8533bfb9b64af8cc84bf.zip
Merge pull request #44165 from nextcloud/fix/noid/spread-appconfig-on-updatenotif1
fix(updatenotification): spread the use of new iappconfig
Diffstat (limited to 'apps')
-rw-r--r--apps/settings/lib/Settings/Admin/Server.php35
-rw-r--r--apps/settings/lib/SetupChecks/CronInfo.php4
-rw-r--r--apps/settings/tests/Settings/Admin/ServerTest.php5
-rw-r--r--apps/updatenotification/lib/Settings/Admin.php41
-rw-r--r--apps/updatenotification/tests/Settings/AdminTest.php47
5 files changed, 62 insertions, 70 deletions
diff --git a/apps/settings/lib/Settings/Admin/Server.php b/apps/settings/lib/Settings/Admin/Server.php
index 9aa8b1ed56d..d6d36432b42 100644
--- a/apps/settings/lib/Settings/Admin/Server.php
+++ b/apps/settings/lib/Settings/Admin/Server.php
@@ -30,6 +30,7 @@ use OC\Profile\TProfileHelper;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
@@ -39,28 +40,16 @@ use OCP\Settings\IDelegatedSettings;
class Server implements IDelegatedSettings {
use TProfileHelper;
- private IDBConnection $connection;
- private IInitialState $initialStateService;
- private ProfileManager $profileManager;
- private ITimeFactory $timeFactory;
- private IConfig $config;
- private IL10N $l;
- private IURLGenerator $urlGenerator;
-
- public function __construct(IDBConnection $connection,
- IInitialState $initialStateService,
- ProfileManager $profileManager,
- ITimeFactory $timeFactory,
- IURLGenerator $urlGenerator,
- IConfig $config,
- IL10N $l) {
- $this->connection = $connection;
- $this->initialStateService = $initialStateService;
- $this->profileManager = $profileManager;
- $this->timeFactory = $timeFactory;
- $this->config = $config;
- $this->l = $l;
- $this->urlGenerator = $urlGenerator;
+ public function __construct(
+ private IDBConnection $connection,
+ private IInitialState $initialStateService,
+ private ProfileManager $profileManager,
+ private ITimeFactory $timeFactory,
+ private IURLGenerator $urlGenerator,
+ private IConfig $config,
+ private IAppConfig $appConfig,
+ private IL10N $l,
+ ) {
}
/**
@@ -69,7 +58,7 @@ class Server implements IDelegatedSettings {
public function getForm() {
// Background jobs
$this->initialStateService->provideInitialState('backgroundJobsMode', $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'));
- $this->initialStateService->provideInitialState('lastCron', (int)$this->config->getAppValue('core', 'lastcron', '0'));
+ $this->initialStateService->provideInitialState('lastCron', $this->appConfig->getValueInt('core', 'lastcron', 0));
$this->initialStateService->provideInitialState('cronMaxAge', $this->cronMaxAge());
$this->initialStateService->provideInitialState('cronErrors', $this->config->getAppValue('core', 'cronErrors'));
$this->initialStateService->provideInitialState('cliBasedCronPossible', function_exists('posix_getpwuid'));
diff --git a/apps/settings/lib/SetupChecks/CronInfo.php b/apps/settings/lib/SetupChecks/CronInfo.php
index d08bb6852a8..de72f7b42e7 100644
--- a/apps/settings/lib/SetupChecks/CronInfo.php
+++ b/apps/settings/lib/SetupChecks/CronInfo.php
@@ -26,6 +26,7 @@ declare(strict_types=1);
namespace OCA\Settings\SetupChecks;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IL10N;
@@ -37,6 +38,7 @@ class CronInfo implements ISetupCheck {
public function __construct(
private IL10N $l10n,
private IConfig $config,
+ private IAppConfig $appConfig,
private IURLGenerator $urlGenerator,
private IDateTimeFormatter $dateTimeFormatter,
) {
@@ -51,7 +53,7 @@ class CronInfo implements ISetupCheck {
}
public function run(): SetupResult {
- $lastCronRun = (int)$this->config->getAppValue('core', 'lastcron', '0');
+ $lastCronRun = $this->appConfig->getValueInt('core', 'lastcron', 0);
$relativeTime = $this->dateTimeFormatter->formatTimeSpan($lastCronRun);
if ((time() - $lastCronRun) > 3600) {
diff --git a/apps/settings/tests/Settings/Admin/ServerTest.php b/apps/settings/tests/Settings/Admin/ServerTest.php
index c070dbe3db1..99392612de9 100644
--- a/apps/settings/tests/Settings/Admin/ServerTest.php
+++ b/apps/settings/tests/Settings/Admin/ServerTest.php
@@ -36,6 +36,7 @@ use OCA\Settings\Settings\Admin\Server;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
@@ -59,6 +60,8 @@ class ServerTest extends TestCase {
private $timeFactory;
/** @var IConfig|MockObject */
private $config;
+ /** @var IAppConfig|MockObject */
+ private $appConfig;
/** @var IL10N|MockObject */
private $l10n;
/** @var IUrlGenerator|MockObject */
@@ -71,6 +74,7 @@ class ServerTest extends TestCase {
$this->profileManager = $this->createMock(ProfileManager::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
$this->l10n = $this->createMock(IL10N::class);
$this->urlGenerator = $this->createMock(IUrlGenerator::class);
@@ -83,6 +87,7 @@ class ServerTest extends TestCase {
$this->timeFactory,
$this->urlGenerator,
$this->config,
+ $this->appConfig,
$this->l10n,
])
->getMock();
diff --git a/apps/updatenotification/lib/Settings/Admin.php b/apps/updatenotification/lib/Settings/Admin.php
index 730be5601a2..b95f3dec196 100644
--- a/apps/updatenotification/lib/Settings/Admin.php
+++ b/apps/updatenotification/lib/Settings/Admin.php
@@ -33,6 +33,7 @@ use OC\User\Backend;
use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IGroupManager;
@@ -45,40 +46,22 @@ use OCP\Util;
use Psr\Log\LoggerInterface;
class Admin implements ISettings {
- private IConfig $config;
- private UpdateChecker $updateChecker;
- private IGroupManager $groupManager;
- private IDateTimeFormatter $dateTimeFormatter;
- private IFactory $l10nFactory;
- private IRegistry $subscriptionRegistry;
- private IUserManager $userManager;
- private LoggerInterface $logger;
- private IInitialState $initialState;
-
public function __construct(
- IConfig $config,
- UpdateChecker $updateChecker,
- IGroupManager $groupManager,
- IDateTimeFormatter $dateTimeFormatter,
- IFactory $l10nFactory,
- IRegistry $subscriptionRegistry,
- IUserManager $userManager,
- LoggerInterface $logger,
- IInitialState $initialState
+ private IConfig $config,
+ private IAppConfig $appConfig,
+ private UpdateChecker $updateChecker,
+ private IGroupManager $groupManager,
+ private IDateTimeFormatter $dateTimeFormatter,
+ private IFactory $l10nFactory,
+ private IRegistry $subscriptionRegistry,
+ private IUserManager $userManager,
+ private LoggerInterface $logger,
+ private IInitialState $initialState
) {
- $this->config = $config;
- $this->updateChecker = $updateChecker;
- $this->groupManager = $groupManager;
- $this->dateTimeFormatter = $dateTimeFormatter;
- $this->l10nFactory = $l10nFactory;
- $this->subscriptionRegistry = $subscriptionRegistry;
- $this->userManager = $userManager;
- $this->logger = $logger;
- $this->initialState = $initialState;
}
public function getForm(): TemplateResponse {
- $lastUpdateCheckTimestamp = (int)$this->config->getAppValue('core', 'lastupdatedat');
+ $lastUpdateCheckTimestamp = $this->appConfig->getValueInt('core', 'lastupdatedat');
$lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
$channels = [
diff --git a/apps/updatenotification/tests/Settings/AdminTest.php b/apps/updatenotification/tests/Settings/AdminTest.php
index bdde25aceca..7776fa692cd 100644
--- a/apps/updatenotification/tests/Settings/AdminTest.php
+++ b/apps/updatenotification/tests/Settings/AdminTest.php
@@ -34,6 +34,7 @@ use OCA\UpdateNotification\Settings\Admin;
use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IGroup;
@@ -55,6 +56,8 @@ class AdminTest extends TestCase {
private $admin;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $config;
+ /** @var IAppConfig|\PHPUnit\Framework\MockObject\MockObject */
+ private $appConfig;
/** @var UpdateChecker|\PHPUnit\Framework\MockObject\MockObject */
private $updateChecker;
/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
@@ -74,6 +77,7 @@ class AdminTest extends TestCase {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
$this->updateChecker = $this->createMock(UpdateChecker::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class);
@@ -85,6 +89,7 @@ class AdminTest extends TestCase {
$this->admin = new Admin(
$this->config,
+ $this->appConfig,
$this->updateChecker,
$this->groupManager,
$this->dateTimeFormatter,
@@ -143,14 +148,16 @@ class AdminTest extends TestCase {
if ($currentChannel === 'git') {
$channels[] = 'git';
}
-
+ $this->appConfig
+ ->expects($this->once())
+ ->method('getValueInt')
+ ->with('core', 'lastupdatedat', 0)
+ ->willReturn(12345);
$this->config
- ->expects($this->exactly(2))
+ ->expects($this->once())
->method('getAppValue')
- ->willReturnMap([
- ['core', 'lastupdatedat', '', '12345'],
- ['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
- ]);
+ ->with('updatenotification', 'notify_groups', '["admin"]')
+ ->willReturn('["admin"]');
$this->config
->method('getSystemValue')
->willReturnMap([
@@ -160,7 +167,7 @@ class AdminTest extends TestCase {
$this->dateTimeFormatter
->expects($this->once())
->method('formatDateTime')
- ->with('12345')
+ ->with(12345)
->willReturn('LastCheckedReturnValue');
$this->updateChecker
->expects($this->once())
@@ -268,13 +275,16 @@ class AdminTest extends TestCase {
$channels[] = 'git';
}
+ $this->appConfig
+ ->expects($this->once())
+ ->method('getValueInt')
+ ->with('core', 'lastupdatedat', 0)
+ ->willReturn(12345);
$this->config
- ->expects($this->exactly(2))
+ ->expects($this->once())
->method('getAppValue')
- ->willReturnMap([
- ['core', 'lastupdatedat', '', '12345'],
- ['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
- ]);
+ ->with('updatenotification', 'notify_groups', '["admin"]')
+ ->willReturn('["admin"]');
$this->config
->method('getSystemValue')
->willReturnMap([
@@ -392,13 +402,16 @@ class AdminTest extends TestCase {
$channels[] = 'git';
}
+ $this->appConfig
+ ->expects($this->once())
+ ->method('getValueInt')
+ ->with('core', 'lastupdatedat', 0)
+ ->willReturn(12345);
$this->config
- ->expects($this->exactly(2))
+ ->expects($this->once())
->method('getAppValue')
- ->willReturnMap([
- ['core', 'lastupdatedat', '', '12345'],
- ['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
- ]);
+ ->with('updatenotification', 'notify_groups', '["admin"]')
+ ->willReturn('["admin"]');
$this->config
->method('getSystemValue')
->willReturnMap([