3737use OCP \Http \Client \IClientService ;
3838use OCP \Http \Client \LocalServerException ;
3939use OCP \IConfig ;
40- use OCP \ILogger ;
4140use Psr \Http \Message \RequestInterface ;
4241use Psr \Http \Message \ResponseInterface ;
42+ use Psr \Log \LoggerInterface ;
4343use Sabre \DAV \Exception \BadRequest ;
4444use Sabre \DAV \PropPatch ;
4545use Sabre \DAV \Xml \Property \Href ;
5656class RefreshWebcalService {
5757
5858 /** @var CalDavBackend */
59- private $ calDavBackend ;
59+ private CalDavBackend $ calDavBackend ;
6060
6161 /** @var IClientService */
62- private $ clientService ;
62+ private IClientService $ clientService ;
6363
6464 /** @var IConfig */
65- private $ config ;
65+ private IConfig $ config ;
6666
67- /** @var ILogger */
68- private $ logger ;
67+ /** @var LoggerInterface */
68+ private LoggerInterface $ logger ;
6969
7070 public const REFRESH_RATE = '{http://apple.com/ns/ical/}refreshrate ' ;
7171 public const STRIP_ALARMS = '{http://calendarserver.org/ns/}subscribed-strip-alarms ' ;
7272 public const STRIP_ATTACHMENTS = '{http://calendarserver.org/ns/}subscribed-strip-attachments ' ;
7373 public const STRIP_TODOS = '{http://calendarserver.org/ns/}subscribed-strip-todos ' ;
7474
75- /**
76- * RefreshWebcalJob constructor.
77- *
78- * @param CalDavBackend $calDavBackend
79- * @param IClientService $clientService
80- * @param IConfig $config
81- * @param ILogger $logger
82- */
83- public function __construct (CalDavBackend $ calDavBackend , IClientService $ clientService , IConfig $ config , ILogger $ logger ) {
75+ public function __construct (CalDavBackend $ calDavBackend , IClientService $ clientService , IConfig $ config , LoggerInterface $ logger ) {
8476 $ this ->calDavBackend = $ calDavBackend ;
8577 $ this ->clientService = $ clientService ;
8678 $ this ->config = $ config ;
@@ -143,7 +135,7 @@ public function refreshSubscription(string $principalUri, string $uri) {
143135 try {
144136 $ this ->calDavBackend ->createCalendarObject ($ subscription ['id ' ], $ uri , $ calendarData , CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION );
145137 } catch (NoInstancesException | BadRequest $ ex ) {
146- $ this ->logger ->logException ( $ ex );
138+ $ this ->logger ->error ( ' Unable to create calendar object from subscription ' , [ ' exception ' => $ ex] );
147139 }
148140 }
149141
@@ -155,20 +147,14 @@ public function refreshSubscription(string $principalUri, string $uri) {
155147 $ this ->updateSubscription ($ subscription , $ mutations );
156148 } catch (ParseException $ ex ) {
157149 $ subscriptionId = $ subscription ['id ' ];
158-
159- $ this ->logger ->logException ($ ex );
160- $ this ->logger ->warning ("Subscription $ subscriptionId could not be refreshed due to a parsing error " );
150+ $ this ->logger ->warning ("Subscription $ subscriptionId could not be refreshed due to a parsing error " , ['exception ' => $ ex ]);
161151 }
162152 }
163153
164154 /**
165155 * loads subscription from backend
166- *
167- * @param string $principalUri
168- * @param string $uri
169- * @return array|null
170156 */
171- public function getSubscription (string $ principalUri , string $ uri ) {
157+ public function getSubscription (string $ principalUri , string $ uri ): ? array {
172158 $ subscriptions = array_values (array_filter (
173159 $ this ->calDavBackend ->getSubscriptionsForUser ($ principalUri ),
174160 function ($ sub ) use ($ uri ) {
@@ -185,12 +171,8 @@ function ($sub) use ($uri) {
185171
186172 /**
187173 * gets webcal feed from remote server
188- *
189- * @param array $subscription
190- * @param array &$mutations
191- * @return null|string
192174 */
193- private function queryWebcalFeed (array $ subscription , array &$ mutations ) {
175+ private function queryWebcalFeed (array $ subscription , array &$ mutations ): ? string {
194176 $ client = $ this ->clientService ->newClient ();
195177
196178 $ didBreak301Chain = false ;
@@ -252,7 +234,7 @@ private function queryWebcalFeed(array $subscription, array &$mutations) {
252234 $ jCalendar = Reader::readJson ($ body , Reader::OPTION_FORGIVING );
253235 } catch (Exception $ ex ) {
254236 // In case of a parsing error return null
255- $ this ->logger ->debug ("Subscription $ subscriptionId could not be parsed " );
237+ $ this ->logger ->warning ("Subscription $ subscriptionId could not be parsed " , [ ' exception ' => $ ex ] );
256238 return null ;
257239 }
258240 return $ jCalendar ->serialize ();
@@ -262,7 +244,7 @@ private function queryWebcalFeed(array $subscription, array &$mutations) {
262244 $ xCalendar = Reader::readXML ($ body );
263245 } catch (Exception $ ex ) {
264246 // In case of a parsing error return null
265- $ this ->logger ->debug ("Subscription $ subscriptionId could not be parsed " );
247+ $ this ->logger ->warning ("Subscription $ subscriptionId could not be parsed " , [ ' exception ' => $ ex ] );
266248 return null ;
267249 }
268250 return $ xCalendar ->serialize ();
@@ -273,22 +255,20 @@ private function queryWebcalFeed(array $subscription, array &$mutations) {
273255 $ vCalendar = Reader::read ($ body );
274256 } catch (Exception $ ex ) {
275257 // In case of a parsing error return null
276- $ this ->logger ->debug ("Subscription $ subscriptionId could not be parsed " );
258+ $ this ->logger ->warning ("Subscription $ subscriptionId could not be parsed " , [ ' exception ' => $ ex ] );
277259 return null ;
278260 }
279261 return $ vCalendar ->serialize ();
280262 }
281263 } catch (LocalServerException $ ex ) {
282- $ this ->logger ->logException ($ ex , [
283- 'message ' => "Subscription $ subscriptionId was not refreshed because it violates local access rules " ,
284- 'level ' => ILogger::WARN ,
264+ $ this ->logger ->warning ("Subscription $ subscriptionId was not refreshed because it violates local access rules " , [
265+ 'exception ' => $ ex ,
285266 ]);
286267
287268 return null ;
288269 } catch (Exception $ ex ) {
289- $ this ->logger ->logException ($ ex , [
290- 'message ' => "Subscription $ subscriptionId could not be refreshed due to a network error " ,
291- 'level ' => ILogger::WARN ,
270+ $ this ->logger ->warning ("Subscription $ subscriptionId could not be refreshed due to a network error " , [
271+ 'exception ' => $ ex ,
292272 ]);
293273
294274 return null ;
@@ -301,11 +281,8 @@ private function queryWebcalFeed(array $subscription, array &$mutations) {
301281 * - the webcal feed suggests a refreshrate
302282 * - return suggested refreshrate if user didn't set a custom one
303283 *
304- * @param array $subscription
305- * @param string $webcalData
306- * @return string|null
307284 */
308- private function checkWebcalDataForRefreshRate ($ subscription , $ webcalData ) {
285+ private function checkWebcalDataForRefreshRate (array $ subscription , string $ webcalData ): ? string {
309286 // if there is no refreshrate stored in the database, check the webcal feed
310287 // whether it suggests any refresh rate and store that in the database
311288 if (isset ($ subscription [self ::REFRESH_RATE ]) && $ subscription [self ::REFRESH_RATE ] !== null ) {
@@ -363,7 +340,7 @@ private function updateSubscription(array $subscription, array $mutations) {
363340 * @param string $url
364341 * @return string|null
365342 */
366- private function cleanURL (string $ url ) {
343+ private function cleanURL (string $ url ): ? string {
367344 $ parsed = parse_url ($ url );
368345 if ($ parsed === false ) {
369346 return null ;
0 commit comments