Skip to content

Commit ffa611e

Browse files
committed
fix(updatenotification): spread the use of new iappconfig
Signed-off-by: Maxence Lange <[email protected]>
1 parent 007731d commit ffa611e

File tree

9 files changed

+64
-79
lines changed

9 files changed

+64
-79
lines changed

apps/settings/lib/Settings/Admin/Server.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use OCP\AppFramework\Http\TemplateResponse;
3131
use OCP\AppFramework\Services\IInitialState;
3232
use OCP\AppFramework\Utility\ITimeFactory;
33+
use OCP\IAppConfig;
3334
use OCP\IConfig;
3435
use OCP\IDBConnection;
3536
use OCP\IL10N;
@@ -39,28 +40,16 @@
3940
class Server implements IDelegatedSettings {
4041
use TProfileHelper;
4142

42-
private IDBConnection $connection;
43-
private IInitialState $initialStateService;
44-
private ProfileManager $profileManager;
45-
private ITimeFactory $timeFactory;
46-
private IConfig $config;
47-
private IL10N $l;
48-
private IURLGenerator $urlGenerator;
49-
50-
public function __construct(IDBConnection $connection,
51-
IInitialState $initialStateService,
52-
ProfileManager $profileManager,
53-
ITimeFactory $timeFactory,
54-
IURLGenerator $urlGenerator,
55-
IConfig $config,
56-
IL10N $l) {
57-
$this->connection = $connection;
58-
$this->initialStateService = $initialStateService;
59-
$this->profileManager = $profileManager;
60-
$this->timeFactory = $timeFactory;
61-
$this->config = $config;
62-
$this->l = $l;
63-
$this->urlGenerator = $urlGenerator;
43+
public function __construct(
44+
private IDBConnection $connection,
45+
private IInitialState $initialStateService,
46+
private ProfileManager $profileManager,
47+
private ITimeFactory $timeFactory,
48+
private IURLGenerator $urlGenerator,
49+
private IConfig $config,
50+
private IAppConfig $appConfig,
51+
private IL10N $l,
52+
) {
6453
}
6554

6655
/**
@@ -69,7 +58,7 @@ public function __construct(IDBConnection $connection,
6958
public function getForm() {
7059
// Background jobs
7160
$this->initialStateService->provideInitialState('backgroundJobsMode', $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'));
72-
$this->initialStateService->provideInitialState('lastCron', (int)$this->config->getAppValue('core', 'lastcron', '0'));
61+
$this->initialStateService->provideInitialState('lastCron', $this->appConfig->getValueInt('core', 'lastcron', 0));
7362
$this->initialStateService->provideInitialState('cronMaxAge', $this->cronMaxAge());
7463
$this->initialStateService->provideInitialState('cronErrors', $this->config->getAppValue('core', 'cronErrors'));
7564
$this->initialStateService->provideInitialState('cliBasedCronPossible', function_exists('posix_getpwuid'));

apps/settings/lib/SetupChecks/CronInfo.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
namespace OCA\Settings\SetupChecks;
2828

29+
use OCP\IAppConfig;
2930
use OCP\IConfig;
3031
use OCP\IDateTimeFormatter;
3132
use OCP\IL10N;
@@ -37,6 +38,7 @@ class CronInfo implements ISetupCheck {
3738
public function __construct(
3839
private IL10N $l10n,
3940
private IConfig $config,
41+
private IAppConfig $appConfig,
4042
private IURLGenerator $urlGenerator,
4143
private IDateTimeFormatter $dateTimeFormatter,
4244
) {
@@ -51,7 +53,7 @@ public function getName(): string {
5153
}
5254

5355
public function run(): SetupResult {
54-
$lastCronRun = (int)$this->config->getAppValue('core', 'lastcron', '0');
56+
$lastCronRun = $this->appConfig->getValueInt('core', 'lastcron', 0);
5557
$relativeTime = $this->dateTimeFormatter->formatTimeSpan($lastCronRun);
5658

5759
if ((time() - $lastCronRun) > 3600) {

apps/updatenotification/lib/Settings/Admin.php

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OCA\UpdateNotification\UpdateChecker;
3434
use OCP\AppFramework\Http\TemplateResponse;
3535
use OCP\AppFramework\Services\IInitialState;
36+
use OCP\IAppConfig;
3637
use OCP\IConfig;
3738
use OCP\IDateTimeFormatter;
3839
use OCP\IGroupManager;
@@ -45,40 +46,22 @@
4546
use Psr\Log\LoggerInterface;
4647

4748
class Admin implements ISettings {
48-
private IConfig $config;
49-
private UpdateChecker $updateChecker;
50-
private IGroupManager $groupManager;
51-
private IDateTimeFormatter $dateTimeFormatter;
52-
private IFactory $l10nFactory;
53-
private IRegistry $subscriptionRegistry;
54-
private IUserManager $userManager;
55-
private LoggerInterface $logger;
56-
private IInitialState $initialState;
57-
5849
public function __construct(
59-
IConfig $config,
60-
UpdateChecker $updateChecker,
61-
IGroupManager $groupManager,
62-
IDateTimeFormatter $dateTimeFormatter,
63-
IFactory $l10nFactory,
64-
IRegistry $subscriptionRegistry,
65-
IUserManager $userManager,
66-
LoggerInterface $logger,
67-
IInitialState $initialState
50+
private IConfig $config,
51+
private IAppConfig $appConfig,
52+
private UpdateChecker $updateChecker,
53+
private IGroupManager $groupManager,
54+
private IDateTimeFormatter $dateTimeFormatter,
55+
private IFactory $l10nFactory,
56+
private IRegistry $subscriptionRegistry,
57+
private IUserManager $userManager,
58+
private LoggerInterface $logger,
59+
private IInitialState $initialState
6860
) {
69-
$this->config = $config;
70-
$this->updateChecker = $updateChecker;
71-
$this->groupManager = $groupManager;
72-
$this->dateTimeFormatter = $dateTimeFormatter;
73-
$this->l10nFactory = $l10nFactory;
74-
$this->subscriptionRegistry = $subscriptionRegistry;
75-
$this->userManager = $userManager;
76-
$this->logger = $logger;
77-
$this->initialState = $initialState;
7861
}
7962

8063
public function getForm(): TemplateResponse {
81-
$lastUpdateCheckTimestamp = (int)$this->config->getAppValue('core', 'lastupdatedat');
64+
$lastUpdateCheckTimestamp = $this->appConfig->getValueInt('core', 'lastupdatedat');
8265
$lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
8366

8467
$channels = [

apps/updatenotification/tests/Settings/AdminTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use OCA\UpdateNotification\UpdateChecker;
3535
use OCP\AppFramework\Http\TemplateResponse;
3636
use OCP\AppFramework\Services\IInitialState;
37+
use OCP\IAppConfig;
3738
use OCP\IConfig;
3839
use OCP\IDateTimeFormatter;
3940
use OCP\IGroup;
@@ -55,6 +56,8 @@ class AdminTest extends TestCase {
5556
private $admin;
5657
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
5758
private $config;
59+
/** @var IAppConfig|\PHPUnit\Framework\MockObject\MockObject */
60+
private $appConfig;
5861
/** @var UpdateChecker|\PHPUnit\Framework\MockObject\MockObject */
5962
private $updateChecker;
6063
/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
@@ -74,6 +77,7 @@ protected function setUp(): void {
7477
parent::setUp();
7578

7679
$this->config = $this->createMock(IConfig::class);
80+
$this->appConfig = $this->createMock(IAppConfig::class);
7781
$this->updateChecker = $this->createMock(UpdateChecker::class);
7882
$this->groupManager = $this->createMock(IGroupManager::class);
7983
$this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class);
@@ -85,6 +89,7 @@ protected function setUp(): void {
8589

8690
$this->admin = new Admin(
8791
$this->config,
92+
$this->appConfig,
8893
$this->updateChecker,
8994
$this->groupManager,
9095
$this->dateTimeFormatter,

lib/private/Setup.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
use OCP\AppFramework\Utility\ITimeFactory;
6363
use OCP\BackgroundJob\IJobList;
6464
use OCP\Defaults;
65+
use OCP\IAppConfig;
6566
use OCP\IConfig;
6667
use OCP\IGroup;
6768
use OCP\IGroupManager;
@@ -382,7 +383,8 @@ public function install(array $options, ?IOutput $output = null): array {
382383

383384
$config = Server::get(IConfig::class);
384385
$config->setAppValue('core', 'installedat', (string)microtime(true));
385-
$config->setAppValue('core', 'lastupdatedat', (string)microtime(true));
386+
$appConfig = Server::get(IAppConfig::class);
387+
$appConfig->setValueInt('core', 'lastupdatedat', time());
386388

387389
$vendorData = $this->getVendorData();
388390
$config->setAppValue('core', 'vendor', $vendorData['vendor']);

lib/private/Updater.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
use OCP\EventDispatcher\Event;
6060
use OCP\EventDispatcher\IEventDispatcher;
6161
use OCP\HintException;
62+
use OCP\IAppConfig;
6263
use OCP\IConfig;
6364
use OCP\ILogger;
6465
use OCP\Util;
@@ -74,34 +75,21 @@
7475
* - failure(string $message)
7576
*/
7677
class Updater extends BasicEmitter {
77-
/** @var LoggerInterface */
78-
private $log;
79-
80-
/** @var IConfig */
81-
private $config;
82-
83-
/** @var Checker */
84-
private $checker;
85-
86-
/** @var Installer */
87-
private $installer;
88-
89-
private $logLevelNames = [
78+
private array $logLevelNames = [
9079
0 => 'Debug',
9180
1 => 'Info',
9281
2 => 'Warning',
9382
3 => 'Error',
9483
4 => 'Fatal',
9584
];
9685

97-
public function __construct(IConfig $config,
98-
Checker $checker,
99-
?LoggerInterface $log,
100-
Installer $installer) {
101-
$this->log = $log;
102-
$this->config = $config;
103-
$this->checker = $checker;
104-
$this->installer = $installer;
86+
public function __construct(
87+
private IConfig $config,
88+
private IAppConfig $appConfig,
89+
private Checker $checker,
90+
private ?LoggerInterface $log,
91+
private Installer $installer
92+
) {
10593
}
10694

10795
/**
@@ -303,7 +291,7 @@ private function doUpgrade(string $currentVersion, string $installedVersion): vo
303291
$repair->run();
304292

305293
//Invalidate update feed
306-
$this->config->setAppValue('core', 'lastupdatedat', '0');
294+
$this->appConfig->setValueInt('core', 'lastupdatedat', 0);
307295

308296
// Check for code integrity if not disabled
309297
if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) {

lib/private/Updater/VersionCheck.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
namespace OC\Updater;
2828

2929
use OCP\Http\Client\IClientService;
30+
use OCP\IAppConfig;
3031
use OCP\IConfig;
3132
use OCP\IUserManager;
3233
use OCP\Support\Subscription\IRegistry;
@@ -37,6 +38,7 @@ class VersionCheck {
3738
public function __construct(
3839
private IClientService $clientService,
3940
private IConfig $config,
41+
private IAppConfig $appConfig,
4042
private IUserManager $userManager,
4143
private IRegistry $registry,
4244
private LoggerInterface $logger,
@@ -56,21 +58,21 @@ public function check() {
5658
}
5759

5860
// Look up the cache - it is invalidated all 30 minutes
59-
if (((int)$this->config->getAppValue('core', 'lastupdatedat') + 1800) > time()) {
61+
if (($this->appConfig->getValueInt('core', 'lastupdatedat') + 1800) > time()) {
6062
return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true);
6163
}
6264

6365
$updaterUrl = $this->config->getSystemValueString('updater.server.url', 'https://updates.nextcloud.com/updater_server/');
6466

65-
$this->config->setAppValue('core', 'lastupdatedat', (string)time());
67+
$this->appConfig->setValueInt('core', 'lastupdatedat', time());
6668

6769
if ($this->config->getAppValue('core', 'installedat', '') === '') {
6870
$this->config->setAppValue('core', 'installedat', (string)microtime(true));
6971
}
7072

7173
$version = Util::getVersion();
7274
$version['installed'] = $this->config->getAppValue('core', 'installedat');
73-
$version['updated'] = $this->config->getAppValue('core', 'lastupdatedat');
75+
$version['updated'] = $this->appConfig->getValueInt('core', 'lastupdatedat');
7476
$version['updatechannel'] = \OC_Util::getChannel();
7577
$version['edition'] = '';
7678
$version['build'] = \OC_Util::getBuild();

tests/lib/Updater/VersionCheckTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
use OC\Updater\VersionCheck;
2626
use OCP\Http\Client\IClientService;
27+
use OCP\IAppConfig;
2728
use OCP\IConfig;
2829
use OCP\IUserManager;
2930
use OCP\Support\Subscription\IRegistry;
@@ -33,6 +34,8 @@
3334
class VersionCheckTest extends \Test\TestCase {
3435
/** @var IConfig| \PHPUnit\Framework\MockObject\MockObject */
3536
private $config;
37+
/** @var IAppConfig| \PHPUnit\Framework\MockObject\MockObject */
38+
private $appConfig;
3639
/** @var VersionCheck | \PHPUnit\Framework\MockObject\MockObject*/
3740
private $updater;
3841
/** @var IRegistry | \PHPUnit\Framework\Mo2ckObject\MockObject*/
@@ -45,6 +48,9 @@ protected function setUp(): void {
4548
$this->config = $this->getMockBuilder(IConfig::class)
4649
->disableOriginalConstructor()
4750
->getMock();
51+
$this->appConfig = $this->getMockBuilder(IAppConfig::class)
52+
->disableOriginalConstructor()
53+
->getMock();
4854
$clientService = $this->getMockBuilder(IClientService::class)
4955
->disableOriginalConstructor()
5056
->getMock();
@@ -59,6 +65,7 @@ protected function setUp(): void {
5965
->setConstructorArgs([
6066
$clientService,
6167
$this->config,
68+
$this->appConfig,
6269
$this->createMock(IUserManager::class),
6370
$this->registry,
6471
$this->logger,

tests/lib/UpdaterTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@
2525
use OC\Installer;
2626
use OC\IntegrityCheck\Checker;
2727
use OC\Updater;
28+
use OCP\IAppConfig;
2829
use OCP\IConfig;
2930
use PHPUnit\Framework\MockObject\MockObject;
3031
use Psr\Log\LoggerInterface;
3132

3233
class UpdaterTest extends TestCase {
3334
/** @var IConfig|MockObject */
3435
private $config;
36+
/** @var IAppConfig|MockObject */
37+
private $appConfig;
3538
/** @var LoggerInterface|MockObject */
3639
private $logger;
3740
/** @var Updater */
@@ -46,6 +49,9 @@ protected function setUp(): void {
4649
$this->config = $this->getMockBuilder(IConfig::class)
4750
->disableOriginalConstructor()
4851
->getMock();
52+
$this->appConfig = $this->getMockBuilder(IAppConfig::class)
53+
->disableOriginalConstructor()
54+
->getMock();
4955
$this->logger = $this->getMockBuilder(LoggerInterface::class)
5056
->disableOriginalConstructor()
5157
->getMock();
@@ -58,6 +64,7 @@ protected function setUp(): void {
5864

5965
$this->updater = new Updater(
6066
$this->config,
67+
$this->appConfig,
6168
$this->checker,
6269
$this->logger,
6370
$this->installer

0 commit comments

Comments
 (0)