summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-01-31 08:18:09 +0100
committerGitHub <noreply@github.com>2020-01-31 08:18:09 +0100
commit4765f5b3db6e8e3d2acae19a0c00f616729c1155 (patch)
tree003c379c9aa8a5505427e65be3549ce0d86a53c3
parent2f91ac0865b4d6e3ab60744bd82adc90bec398dc (diff)
parent98edf44c668427018e3f6f3780a5c1007647c412 (diff)
downloadnextcloud-server-4765f5b3db6e8e3d2acae19a0c00f616729c1155.tar.gz
nextcloud-server-4765f5b3db6e8e3d2acae19a0c00f616729c1155.zip
Merge pull request #19215 from nextcloud/bugfix/19146/webcal_not_updated
WebcalRefreshJob: Fix reading refresh rate
-rw-r--r--apps/dav/lib/BackgroundJob/RefreshWebcalJob.php52
-rw-r--r--apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php20
-rw-r--r--lib/private/BackgroundJob/JobList.php2
3 files changed, 51 insertions, 23 deletions
diff --git a/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php b/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php
index 1c0d185e90b..89f941c14d5 100644
--- a/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php
+++ b/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php
@@ -67,6 +67,11 @@ class RefreshWebcalJob extends Job {
/** @var array */
private $subscription;
+ private const REFRESH_RATE = '{http://apple.com/ns/ical/}refreshrate';
+ private const STRIP_ALARMS = '{http://calendarserver.org/ns/}subscribed-strip-alarms';
+ private const STRIP_ATTACHMENTS = '{http://calendarserver.org/ns/}subscribed-strip-attachments';
+ private const STRIP_TODOS = '{http://calendarserver.org/ns/}subscribed-strip-todos';
+
/**
* RefreshWebcalJob constructor.
*
@@ -95,9 +100,11 @@ class RefreshWebcalJob extends Job {
return;
}
+ $this->fixSubscriptionRowTyping($subscription);
+
// if no refresh rate was configured, just refresh once a week
$subscriptionId = $subscription['id'];
- $refreshrate = $subscription['refreshrate'] ?? 'P1W';
+ $refreshrate = $subscription[self::REFRESH_RATE] ?? 'P1W';
try {
/** @var \DateInterval $dateInterval */
@@ -131,9 +138,9 @@ class RefreshWebcalJob extends Job {
return;
}
- $stripTodos = $subscription['striptodos'] ?? 1;
- $stripAlarms = $subscription['stripalarms'] ?? 1;
- $stripAttachments = $subscription['stripattachments'] ?? 1;
+ $stripTodos = ($subscription[self::STRIP_TODOS] ?? 1) === 1;
+ $stripAlarms = ($subscription[self::STRIP_ALARMS] ?? 1) === 1;
+ $stripAttachments = ($subscription[self::STRIP_ATTACHMENTS] ?? 1) === 1;
try {
$splitter = new ICalendar($webcalData, Reader::OPTION_FORGIVING);
@@ -179,7 +186,7 @@ class RefreshWebcalJob extends Job {
$newRefreshRate = $this->checkWebcalDataForRefreshRate($subscription, $webcalData);
if ($newRefreshRate) {
- $mutations['{http://apple.com/ns/ical/}refreshrate'] = $newRefreshRate;
+ $mutations[self::REFRESH_RATE] = $newRefreshRate;
}
$this->updateSubscription($subscription, $mutations);
@@ -378,33 +385,33 @@ class RefreshWebcalJob extends Job {
private function checkWebcalDataForRefreshRate($subscription, $webcalData) {
// if there is no refreshrate stored in the database, check the webcal feed
// whether it suggests any refresh rate and store that in the database
- if (isset($subscription['refreshrate']) && $subscription['refreshrate'] !== null) {
+ if (isset($subscription[self::REFRESH_RATE]) && $subscription[self::REFRESH_RATE] !== null) {
return null;
}
/** @var Component\VCalendar $vCalendar */
$vCalendar = Reader::read($webcalData);
- $newRefreshrate = null;
+ $newRefreshRate = null;
if (isset($vCalendar->{'X-PUBLISHED-TTL'})) {
- $newRefreshrate = $vCalendar->{'X-PUBLISHED-TTL'}->getValue();
+ $newRefreshRate = $vCalendar->{'X-PUBLISHED-TTL'}->getValue();
}
if (isset($vCalendar->{'REFRESH-INTERVAL'})) {
- $newRefreshrate = $vCalendar->{'REFRESH-INTERVAL'}->getValue();
+ $newRefreshRate = $vCalendar->{'REFRESH-INTERVAL'}->getValue();
}
- if (!$newRefreshrate) {
+ if (!$newRefreshRate) {
return null;
}
// check if new refresh rate is even valid
try {
- DateTimeParser::parseDuration($newRefreshrate);
+ DateTimeParser::parseDuration($newRefreshRate);
} catch(InvalidDataException $ex) {
return null;
}
- return $newRefreshrate;
+ return $newRefreshRate;
}
/**
@@ -461,4 +468,25 @@ class RefreshWebcalJob extends Job {
return $cleanURL;
}
+
+ /**
+ * Fixes types of rows
+ *
+ * @param array $row
+ */
+ private function fixSubscriptionRowTyping(array &$row):void {
+ $forceInt = [
+ 'id',
+ 'lastmodified',
+ self::STRIP_ALARMS,
+ self::STRIP_ATTACHMENTS,
+ self::STRIP_TODOS,
+ ];
+
+ foreach($forceInt as $column) {
+ if (isset($row[$column])) {
+ $row[$column] = (int) $row[$column];
+ }
+ }
+ }
}
diff --git a/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php b/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php
index 088a7230374..255ad21f042 100644
--- a/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php
+++ b/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php
@@ -97,21 +97,21 @@ class RefreshWebcalJobTest extends TestCase {
->with('principals/users/testuser')
->will($this->returnValue([
[
- 'id' => 99,
+ 'id' => '99',
'uri' => 'sub456',
- 'refreshreate' => 'P1D',
- 'striptodos' => 1,
- 'stripalarms' => 1,
- 'stripattachments' => 1,
+ '{http://apple.com/ns/ical/}refreshrate' => 'P1D',
+ '{http://calendarserver.org/ns/}subscribed-strip-todos' => '1',
+ '{http://calendarserver.org/ns/}subscribed-strip-alarms' => '1',
+ '{http://calendarserver.org/ns/}subscribed-strip-attachments' => '1',
'source' => 'webcal://foo.bar/bla'
],
[
- 'id' => 42,
+ 'id' => '42',
'uri' => 'sub123',
- 'refreshreate' => 'P1H',
- 'striptodos' => 1,
- 'stripalarms' => 1,
- 'stripattachments' => 1,
+ '{http://apple.com/ns/ical/}refreshrate' => 'PT1H',
+ '{http://calendarserver.org/ns/}subscribed-strip-todos' => '1',
+ '{http://calendarserver.org/ns/}subscribed-strip-alarms' => '1',
+ '{http://calendarserver.org/ns/}subscribed-strip-attachments' => '1',
'source' => 'webcal://foo.bar/bla2'
],
]));
diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php
index 12da0c4da10..23695bfbe03 100644
--- a/lib/private/BackgroundJob/JobList.php
+++ b/lib/private/BackgroundJob/JobList.php
@@ -276,7 +276,7 @@ class JobList implements IJobList {
}
$job->setId((int) $row['id']);
- $job->setLastRun($row['last_run']);
+ $job->setLastRun((int) $row['last_run']);
$job->setArgument(json_decode($row['argument'], true));
return $job;
} catch (AutoloadNotAllowedException $e) {