Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions apps/dav/lib/BackgroundJob/RefreshWebcalJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand All @@ -40,6 +41,11 @@ class RefreshWebcalJob extends Job {
*/
private $refreshWebcalService;

/**
* @var IConfig
*/
private $config;

/** @var ILogger */
private $logger;

Expand All @@ -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;
}
Expand All @@ -73,12 +81,14 @@ public function execute($jobList, ILogger $logger = null) {
$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");
Expand Down
12 changes: 11 additions & 1 deletion apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand All @@ -39,6 +40,9 @@ class RefreshWebcalJobTest extends TestCase {
/** @var RefreshWebcalService | MockObject */
private $refreshWebcalService;

/** @var IConfig | MockObject */
private $config;

/** @var ILogger | MockObject */
private $logger;

Expand All @@ -52,6 +56,7 @@ protected function setUp() {
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);

Expand All @@ -67,7 +72,7 @@ protected function setUp() {
* @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',
Expand All @@ -88,6 +93,11 @@ public function testRun(int $lastRun, int $time, bool $process) {
'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);
Expand Down