Skip to content

Commit 8d88db3

Browse files
authored
Merge pull request #19784 from nextcloud/backport/19392/stable18
[stable18] Introduce a default refresh rate app setting for calendar subscriptions
2 parents 89b7955 + 4e4cff2 commit 8d88db3

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

apps/dav/lib/BackgroundJob/RefreshWebcalJob.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OC\BackgroundJob\Job;
3333
use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
3434
use OCP\AppFramework\Utility\ITimeFactory;
35+
use OCP\IConfig;
3536
use OCP\ILogger;
3637
use Sabre\VObject\DateTimeParser;
3738
use Sabre\VObject\InvalidDataException;
@@ -43,6 +44,11 @@ class RefreshWebcalJob extends Job {
4344
*/
4445
private $refreshWebcalService;
4546

47+
/**
48+
* @var IConfig
49+
*/
50+
private $config;
51+
4652
/** @var ILogger */
4753
private $logger;
4854

@@ -53,11 +59,13 @@ class RefreshWebcalJob extends Job {
5359
* RefreshWebcalJob constructor.
5460
*
5561
* @param RefreshWebcalService $refreshWebcalService
62+
* @param IConfig $config
5663
* @param ILogger $logger
5764
* @param ITimeFactory $timeFactory
5865
*/
59-
public function __construct(RefreshWebcalService $refreshWebcalService, ILogger $logger, ITimeFactory $timeFactory) {
66+
public function __construct(RefreshWebcalService $refreshWebcalService, IConfig $config, ILogger $logger, ITimeFactory $timeFactory) {
6067
$this->refreshWebcalService = $refreshWebcalService;
68+
$this->config = $config;
6169
$this->logger = $logger;
6270
$this->timeFactory = $timeFactory;
6371
}
@@ -76,12 +84,14 @@ public function execute($jobList, ILogger $logger = null) {
7684
$this->fixSubscriptionRowTyping($subscription);
7785

7886
// if no refresh rate was configured, just refresh once a week
87+
$defaultRefreshRate = $this->config->getAppValue('dav', 'calendarSubscriptionRefreshRate', 'P1W');
88+
$refreshRate = $subscription[RefreshWebcalService::REFRESH_RATE] ?? $defaultRefreshRate;
89+
7990
$subscriptionId = $subscription['id'];
80-
$refreshrate = $subscription[RefreshWebcalService::REFRESH_RATE] ?? 'P1W';
8191

8292
try {
8393
/** @var DateInterval $dateInterval */
84-
$dateInterval = DateTimeParser::parseDuration($refreshrate);
94+
$dateInterval = DateTimeParser::parseDuration($refreshRate);
8595
} catch(InvalidDataException $ex) {
8696
$this->logger->logException($ex);
8797
$this->logger->warning("Subscription $subscriptionId could not be refreshed, refreshrate in database is invalid");

apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
3030
use OCP\AppFramework\Utility\ITimeFactory;
3131
use OCP\BackgroundJob\IJobList;
32+
use OCP\IConfig;
3233
use OCP\ILogger;
3334
use PHPUnit\Framework\MockObject\MockObject;
3435

@@ -39,6 +40,9 @@ class RefreshWebcalJobTest extends TestCase {
3940
/** @var RefreshWebcalService | MockObject */
4041
private $refreshWebcalService;
4142

43+
/** @var IConfig | MockObject */
44+
private $config;
45+
4246
/** @var ILogger | MockObject */
4347
private $logger;
4448

@@ -52,6 +56,7 @@ protected function setUp(): void {
5256
parent::setUp();
5357

5458
$this->refreshWebcalService = $this->createMock(RefreshWebcalService::class);
59+
$this->config = $this->createMock(IConfig::class);
5560
$this->logger = $this->createMock(ILogger::class);
5661
$this->timeFactory = $this->createMock(ITimeFactory::class);
5762

@@ -67,7 +72,7 @@ protected function setUp(): void {
6772
* @dataProvider runDataProvider
6873
*/
6974
public function testRun(int $lastRun, int $time, bool $process) {
70-
$backgroundJob = new RefreshWebcalJob($this->refreshWebcalService, $this->logger, $this->timeFactory);
75+
$backgroundJob = new RefreshWebcalJob($this->refreshWebcalService, $this->config, $this->logger, $this->timeFactory);
7176

7277
$backgroundJob->setArgument([
7378
'principaluri' => 'principals/users/testuser',
@@ -88,6 +93,11 @@ public function testRun(int $lastRun, int $time, bool $process) {
8893
'source' => 'webcal://foo.bar/bla'
8994
]);
9095

96+
$this->config->expects($this->once())
97+
->method('getAppValue')
98+
->with('dav', 'calendarSubscriptionRefreshRate', 'P1W')
99+
->will($this->returnValue('P1W'));
100+
91101
$this->timeFactory->expects($this->once())
92102
->method('getTime')
93103
->willReturn($time);

0 commit comments

Comments
 (0)