Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-03-05 17:36:58 +0300
committerGitHub <noreply@github.com>2020-03-05 17:36:58 +0300
commit50ea452682fd3d0335242d82d8b1db5af8cf43fa (patch)
tree62b047ce35927c167286e376858fa23e6a921f12
parent369e05889c9dba310e93432dbfac2618c480c626 (diff)
parent4319e654bb14d39f750695eb0cf8965970d3e0bc (diff)
Merge pull request #19785 from nextcloud/backport/19392/stable17
[stable17] Introduce a default refresh rate app setting for calendar subscriptions
-rw-r--r--apps/dav/lib/BackgroundJob/RefreshWebcalJob.php16
-rw-r--r--apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php12
2 files changed, 24 insertions, 4 deletions
diff --git a/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php b/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php
index 7a5f7445b1f..e32e5c90a10 100644
--- a/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php
+++ b/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php
@@ -29,6 +29,7 @@ use DateInterval;
use OC\BackgroundJob\Job;
use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IConfig;
use OCP\ILogger;
use Sabre\VObject\DateTimeParser;
use Sabre\VObject\InvalidDataException;
@@ -40,6 +41,11 @@ class RefreshWebcalJob extends Job {
*/
private $refreshWebcalService;
+ /**
+ * @var IConfig
+ */
+ private $config;
+
/** @var ILogger */
private $logger;
@@ -50,11 +56,13 @@ class RefreshWebcalJob extends Job {
* RefreshWebcalJob constructor.
*
* @param RefreshWebcalService $refreshWebcalService
+ * @param IConfig $config
* @param ILogger $logger
* @param ITimeFactory $timeFactory
*/
- public function __construct(RefreshWebcalService $refreshWebcalService, ILogger $logger, ITimeFactory $timeFactory) {
+ public function __construct(RefreshWebcalService $refreshWebcalService, IConfig $config, ILogger $logger, ITimeFactory $timeFactory) {
$this->refreshWebcalService = $refreshWebcalService;
+ $this->config = $config;
$this->logger = $logger;
$this->timeFactory = $timeFactory;
}
@@ -73,12 +81,14 @@ class RefreshWebcalJob extends Job {
$this->fixSubscriptionRowTyping($subscription);
// if no refresh rate was configured, just refresh once a week
+ $defaultRefreshRate = $this->config->getAppValue('dav', 'calendarSubscriptionRefreshRate', 'P1W');
+ $refreshRate = $subscription[RefreshWebcalService::REFRESH_RATE] ?? $defaultRefreshRate;
+
$subscriptionId = $subscription['id'];
- $refreshrate = $subscription[RefreshWebcalService::REFRESH_RATE] ?? 'P1W';
try {
/** @var DateInterval $dateInterval */
- $dateInterval = DateTimeParser::parseDuration($refreshrate);
+ $dateInterval = DateTimeParser::parseDuration($refreshRate);
} catch(InvalidDataException $ex) {
$this->logger->logException($ex);
$this->logger->warning("Subscription $subscriptionId could not be refreshed, refreshrate in database is invalid");
diff --git a/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php b/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php
index ca0cf7a8ca0..6498cf58dc1 100644
--- a/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php
+++ b/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php
@@ -28,6 +28,7 @@ use OCA\DAV\BackgroundJob\RefreshWebcalJob;
use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
+use OCP\IConfig;
use OCP\ILogger;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@@ -39,6 +40,9 @@ class RefreshWebcalJobTest extends TestCase {
/** @var RefreshWebcalService | MockObject */
private $refreshWebcalService;
+ /** @var IConfig | MockObject */
+ private $config;
+
/** @var ILogger | MockObject */
private $logger;
@@ -52,6 +56,7 @@ class RefreshWebcalJobTest extends TestCase {
parent::setUp();
$this->refreshWebcalService = $this->createMock(RefreshWebcalService::class);
+ $this->config = $this->createMock(IConfig::class);
$this->logger = $this->createMock(ILogger::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
@@ -67,7 +72,7 @@ class RefreshWebcalJobTest extends TestCase {
* @dataProvider runDataProvider
*/
public function testRun(int $lastRun, int $time, bool $process) {
- $backgroundJob = new RefreshWebcalJob($this->refreshWebcalService, $this->logger, $this->timeFactory);
+ $backgroundJob = new RefreshWebcalJob($this->refreshWebcalService, $this->config, $this->logger, $this->timeFactory);
$backgroundJob->setArgument([
'principaluri' => 'principals/users/testuser',
@@ -88,6 +93,11 @@ class RefreshWebcalJobTest extends TestCase {
'source' => 'webcal://foo.bar/bla'
]);
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('dav', 'calendarSubscriptionRefreshRate', 'P1W')
+ ->will($this->returnValue('P1W'));
+
$this->timeFactory->expects($this->once())
->method('getTime')
->willReturn($time);