Merge pull request #19229 from nextcloud/backport/19215/stable17
[stable17] WebcalRefreshJob: Fix reading refresh rate
This commit is contained in:
commit
79617a2b23
3 changed files with 51 additions and 23 deletions
|
@ -63,6 +63,11 @@ class RefreshWebcalJob extends Job {
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $subscription;
|
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.
|
* RefreshWebcalJob constructor.
|
||||||
*
|
*
|
||||||
|
@ -91,9 +96,11 @@ class RefreshWebcalJob extends Job {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->fixSubscriptionRowTyping($subscription);
|
||||||
|
|
||||||
// if no refresh rate was configured, just refresh once a week
|
// if no refresh rate was configured, just refresh once a week
|
||||||
$subscriptionId = $subscription['id'];
|
$subscriptionId = $subscription['id'];
|
||||||
$refreshrate = $subscription['refreshrate'] ?? 'P1W';
|
$refreshrate = $subscription[self::REFRESH_RATE] ?? 'P1W';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/** @var \DateInterval $dateInterval */
|
/** @var \DateInterval $dateInterval */
|
||||||
|
@ -127,9 +134,9 @@ class RefreshWebcalJob extends Job {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$stripTodos = $subscription['striptodos'] ?? 1;
|
$stripTodos = ($subscription[self::STRIP_TODOS] ?? 1) === 1;
|
||||||
$stripAlarms = $subscription['stripalarms'] ?? 1;
|
$stripAlarms = ($subscription[self::STRIP_ALARMS] ?? 1) === 1;
|
||||||
$stripAttachments = $subscription['stripattachments'] ?? 1;
|
$stripAttachments = ($subscription[self::STRIP_ATTACHMENTS] ?? 1) === 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$splitter = new ICalendar($webcalData, Reader::OPTION_FORGIVING);
|
$splitter = new ICalendar($webcalData, Reader::OPTION_FORGIVING);
|
||||||
|
@ -175,7 +182,7 @@ class RefreshWebcalJob extends Job {
|
||||||
|
|
||||||
$newRefreshRate = $this->checkWebcalDataForRefreshRate($subscription, $webcalData);
|
$newRefreshRate = $this->checkWebcalDataForRefreshRate($subscription, $webcalData);
|
||||||
if ($newRefreshRate) {
|
if ($newRefreshRate) {
|
||||||
$mutations['{http://apple.com/ns/ical/}refreshrate'] = $newRefreshRate;
|
$mutations[self::REFRESH_RATE] = $newRefreshRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->updateSubscription($subscription, $mutations);
|
$this->updateSubscription($subscription, $mutations);
|
||||||
|
@ -374,33 +381,33 @@ class RefreshWebcalJob extends Job {
|
||||||
private function checkWebcalDataForRefreshRate($subscription, $webcalData) {
|
private function checkWebcalDataForRefreshRate($subscription, $webcalData) {
|
||||||
// if there is no refreshrate stored in the database, check the webcal feed
|
// 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
|
// 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var Component\VCalendar $vCalendar */
|
/** @var Component\VCalendar $vCalendar */
|
||||||
$vCalendar = Reader::read($webcalData);
|
$vCalendar = Reader::read($webcalData);
|
||||||
|
|
||||||
$newRefreshrate = null;
|
$newRefreshRate = null;
|
||||||
if (isset($vCalendar->{'X-PUBLISHED-TTL'})) {
|
if (isset($vCalendar->{'X-PUBLISHED-TTL'})) {
|
||||||
$newRefreshrate = $vCalendar->{'X-PUBLISHED-TTL'}->getValue();
|
$newRefreshRate = $vCalendar->{'X-PUBLISHED-TTL'}->getValue();
|
||||||
}
|
}
|
||||||
if (isset($vCalendar->{'REFRESH-INTERVAL'})) {
|
if (isset($vCalendar->{'REFRESH-INTERVAL'})) {
|
||||||
$newRefreshrate = $vCalendar->{'REFRESH-INTERVAL'}->getValue();
|
$newRefreshRate = $vCalendar->{'REFRESH-INTERVAL'}->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$newRefreshrate) {
|
if (!$newRefreshRate) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if new refresh rate is even valid
|
// check if new refresh rate is even valid
|
||||||
try {
|
try {
|
||||||
DateTimeParser::parseDuration($newRefreshrate);
|
DateTimeParser::parseDuration($newRefreshRate);
|
||||||
} catch(InvalidDataException $ex) {
|
} catch(InvalidDataException $ex) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $newRefreshrate;
|
return $newRefreshRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -457,4 +464,25 @@ class RefreshWebcalJob extends Job {
|
||||||
|
|
||||||
return $cleanURL;
|
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,21 +95,21 @@ class RefreshWebcalJobTest extends TestCase {
|
||||||
->with('principals/users/testuser')
|
->with('principals/users/testuser')
|
||||||
->will($this->returnValue([
|
->will($this->returnValue([
|
||||||
[
|
[
|
||||||
'id' => 99,
|
'id' => '99',
|
||||||
'uri' => 'sub456',
|
'uri' => 'sub456',
|
||||||
'refreshreate' => 'P1D',
|
'{http://apple.com/ns/ical/}refreshrate' => 'P1D',
|
||||||
'striptodos' => 1,
|
'{http://calendarserver.org/ns/}subscribed-strip-todos' => '1',
|
||||||
'stripalarms' => 1,
|
'{http://calendarserver.org/ns/}subscribed-strip-alarms' => '1',
|
||||||
'stripattachments' => 1,
|
'{http://calendarserver.org/ns/}subscribed-strip-attachments' => '1',
|
||||||
'source' => 'webcal://foo.bar/bla'
|
'source' => 'webcal://foo.bar/bla'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => 42,
|
'id' => '42',
|
||||||
'uri' => 'sub123',
|
'uri' => 'sub123',
|
||||||
'refreshreate' => 'P1H',
|
'{http://apple.com/ns/ical/}refreshrate' => 'PT1H',
|
||||||
'striptodos' => 1,
|
'{http://calendarserver.org/ns/}subscribed-strip-todos' => '1',
|
||||||
'stripalarms' => 1,
|
'{http://calendarserver.org/ns/}subscribed-strip-alarms' => '1',
|
||||||
'stripattachments' => 1,
|
'{http://calendarserver.org/ns/}subscribed-strip-attachments' => '1',
|
||||||
'source' => 'webcal://foo.bar/bla2'
|
'source' => 'webcal://foo.bar/bla2'
|
||||||
],
|
],
|
||||||
]));
|
]));
|
||||||
|
|
|
@ -274,7 +274,7 @@ class JobList implements IJobList {
|
||||||
}
|
}
|
||||||
|
|
||||||
$job->setId((int) $row['id']);
|
$job->setId((int) $row['id']);
|
||||||
$job->setLastRun($row['last_run']);
|
$job->setLastRun((int) $row['last_run']);
|
||||||
$job->setArgument(json_decode($row['argument'], true));
|
$job->setArgument(json_decode($row['argument'], true));
|
||||||
return $job;
|
return $job;
|
||||||
} catch (AutoloadNotAllowedException $e) {
|
} catch (AutoloadNotAllowedException $e) {
|
||||||
|
|
Loading…
Reference in a new issue