@@ -67,6 +67,11 @@ class RefreshWebcalJob extends Job {
6767 /** @var array */
6868 private $ subscription ;
6969
70+ private const REFRESH_RATE = '{http://apple.com/ns/ical/}refreshrate ' ;
71+ private const STRIP_ALARMS = '{http://calendarserver.org/ns/}subscribed-strip-alarms ' ;
72+ private const STRIP_ATTACHMENTS = '{http://calendarserver.org/ns/}subscribed-strip-attachments ' ;
73+ private const STRIP_TODOS = '{http://calendarserver.org/ns/}subscribed-strip-todos ' ;
74+
7075 /**
7176 * RefreshWebcalJob constructor.
7277 *
@@ -95,9 +100,11 @@ public function execute($jobList, ILogger $logger = null) {
95100 return ;
96101 }
97102
103+ $ this ->fixSubscriptionRowTyping ($ subscription );
104+
98105 // if no refresh rate was configured, just refresh once a week
99106 $ subscriptionId = $ subscription ['id ' ];
100- $ refreshrate = $ subscription [' refreshrate ' ] ?? 'P1W ' ;
107+ $ refreshrate = $ subscription [self :: REFRESH_RATE ] ?? 'P1W ' ;
101108
102109 try {
103110 /** @var \DateInterval $dateInterval */
@@ -131,9 +138,9 @@ protected function run($argument) {
131138 return ;
132139 }
133140
134- $ stripTodos = $ subscription [' striptodos ' ] ?? 1 ;
135- $ stripAlarms = $ subscription [' stripalarms ' ] ?? 1 ;
136- $ stripAttachments = $ subscription [' stripattachments ' ] ?? 1 ;
141+ $ stripTodos = ( $ subscription [self :: STRIP_TODOS ] ?? 1 ) === 1 ;
142+ $ stripAlarms = ( $ subscription [self :: STRIP_ALARMS ] ?? 1 ) === 1 ;
143+ $ stripAttachments = ( $ subscription [self :: STRIP_ATTACHMENTS ] ?? 1 ) === 1 ;
137144
138145 try {
139146 $ splitter = new ICalendar ($ webcalData , Reader::OPTION_FORGIVING );
@@ -179,7 +186,7 @@ protected function run($argument) {
179186
180187 $ newRefreshRate = $ this ->checkWebcalDataForRefreshRate ($ subscription , $ webcalData );
181188 if ($ newRefreshRate ) {
182- $ mutations [' {http://apple.com/ns/ical/}refreshrate ' ] = $ newRefreshRate ;
189+ $ mutations [self :: REFRESH_RATE ] = $ newRefreshRate ;
183190 }
184191
185192 $ this ->updateSubscription ($ subscription , $ mutations );
@@ -378,33 +385,33 @@ private function getIntervalFromDateInterval(\DateInterval $interval):int {
378385 private function checkWebcalDataForRefreshRate ($ subscription , $ webcalData ) {
379386 // if there is no refreshrate stored in the database, check the webcal feed
380387 // whether it suggests any refresh rate and store that in the database
381- if (isset ($ subscription [' refreshrate ' ]) && $ subscription [' refreshrate ' ] !== null ) {
388+ if (isset ($ subscription [self :: REFRESH_RATE ]) && $ subscription [self :: REFRESH_RATE ] !== null ) {
382389 return null ;
383390 }
384391
385392 /** @var Component\VCalendar $vCalendar */
386393 $ vCalendar = Reader::read ($ webcalData );
387394
388- $ newRefreshrate = null ;
395+ $ newRefreshRate = null ;
389396 if (isset ($ vCalendar ->{'X-PUBLISHED-TTL ' })) {
390- $ newRefreshrate = $ vCalendar ->{'X-PUBLISHED-TTL ' }->getValue ();
397+ $ newRefreshRate = $ vCalendar ->{'X-PUBLISHED-TTL ' }->getValue ();
391398 }
392399 if (isset ($ vCalendar ->{'REFRESH-INTERVAL ' })) {
393- $ newRefreshrate = $ vCalendar ->{'REFRESH-INTERVAL ' }->getValue ();
400+ $ newRefreshRate = $ vCalendar ->{'REFRESH-INTERVAL ' }->getValue ();
394401 }
395402
396- if (!$ newRefreshrate ) {
403+ if (!$ newRefreshRate ) {
397404 return null ;
398405 }
399406
400407 // check if new refresh rate is even valid
401408 try {
402- DateTimeParser::parseDuration ($ newRefreshrate );
409+ DateTimeParser::parseDuration ($ newRefreshRate );
403410 } catch (InvalidDataException $ ex ) {
404411 return null ;
405412 }
406413
407- return $ newRefreshrate ;
414+ return $ newRefreshRate ;
408415 }
409416
410417 /**
@@ -461,4 +468,25 @@ private function cleanURL(string $url) {
461468
462469 return $ cleanURL ;
463470 }
471+
472+ /**
473+ * Fixes types of rows
474+ *
475+ * @param array $row
476+ */
477+ private function fixSubscriptionRowTyping (array &$ row ):void {
478+ $ forceInt = [
479+ 'id ' ,
480+ 'lastmodified ' ,
481+ self ::STRIP_ALARMS ,
482+ self ::STRIP_ATTACHMENTS ,
483+ self ::STRIP_TODOS ,
484+ ];
485+
486+ foreach ($ forceInt as $ column ) {
487+ if (isset ($ row [$ column ])) {
488+ $ row [$ column ] = (int ) $ row [$ column ];
489+ }
490+ }
491+ }
464492}
0 commit comments