|
9 | 9 |
|
10 | 10 | namespace OCA\DAV\CalDAV\WebcalCaching; |
11 | 11 |
|
| 12 | +use Exception; |
12 | 13 | use OCA\DAV\CalDAV\CalDavBackend; |
13 | 14 | use OCA\DAV\CalDAV\Import\ImportService; |
| 15 | +use OCA\DAV\Exception\InvalidSubscriptionPayload; |
| 16 | +use OCA\DAV\Exception\InvalidSubscriptionUrl; |
14 | 17 | use OCP\AppFramework\Utility\ITimeFactory; |
| 18 | +use OCP\Http\Client\LocalServerException; |
15 | 19 | use Psr\Log\LoggerInterface; |
16 | 20 | use Sabre\DAV\PropPatch; |
17 | 21 | use Sabre\VObject\Component; |
@@ -54,19 +58,18 @@ public function refreshSubscription(string $principalUri, string $uri) { |
54 | 58 | } |
55 | 59 | } |
56 | 60 |
|
57 | | - $result = $this->connection->queryWebcalFeed($subscription); |
58 | | - if (!$result) { |
59 | | - return; |
60 | | - } |
| 61 | + $data = null; |
| 62 | + |
| 63 | + try { |
| 64 | + $result = $this->connection->queryWebcalFeed($subscription); |
61 | 65 |
|
62 | | - $data = $result['data']; |
63 | | - $format = $result['format']; |
| 66 | + $data = $result['data']; |
| 67 | + $format = $result['format']; |
64 | 68 |
|
65 | | - $stripTodos = ($subscription[self::STRIP_TODOS] ?? 1) === 1; |
66 | | - $stripAlarms = ($subscription[self::STRIP_ALARMS] ?? 1) === 1; |
67 | | - $stripAttachments = ($subscription[self::STRIP_ATTACHMENTS] ?? 1) === 1; |
| 69 | + $stripTodos = ($subscription[self::STRIP_TODOS] ?? 1) === 1; |
| 70 | + $stripAlarms = ($subscription[self::STRIP_ALARMS] ?? 1) === 1; |
| 71 | + $stripAttachments = ($subscription[self::STRIP_ATTACHMENTS] ?? 1) === 1; |
68 | 72 |
|
69 | | - try { |
70 | 73 | $existingObjects = $this->calDavBackend->getLimitedCalendarObjects((int)$subscription['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION, ['id', 'uid', 'etag', 'uri']); |
71 | 74 |
|
72 | 75 | $generator = match ($format) { |
@@ -158,11 +161,21 @@ public function refreshSubscription(string $principalUri, string $uri) { |
158 | 161 | if (isset($vObject)) { |
159 | 162 | $this->updateRefreshRate($subscription, $vObject); |
160 | 163 | } |
| 164 | + |
| 165 | + $this->calDavBackend->trackSubscriptionError($subscription['id'], null, null); |
161 | 166 | } catch (ParseException $ex) { |
162 | | - $this->logger->error('Subscription {subscriptionId} could not be refreshed due to a parsing error', ['exception' => $ex, 'subscriptionId' => $subscription['id']]); |
| 167 | + $this->calDavBackend->trackSubscriptionError($subscription['id'], $ex, 'Parsing error'); |
| 168 | + } catch (LocalServerException $ex) { |
| 169 | + $this->calDavBackend->trackSubscriptionError($subscription['id'], $ex, 'Subscription violates local access rules'); |
| 170 | + } catch (InvalidSubscriptionUrl $ex) { |
| 171 | + $this->calDavBackend->trackSubscriptionError($subscription['id'], $ex, 'Invalid URL'); |
| 172 | + } catch (InvalidSubscriptionPayload $ex) { |
| 173 | + $this->calDavBackend->trackSubscriptionError($subscription['id'], $ex, 'Invalid contents'); |
| 174 | + } catch (Exception $ex) { |
| 175 | + $this->calDavBackend->trackSubscriptionError($subscription['id'], $ex, 'Network error'); |
163 | 176 | } finally { |
164 | 177 | // Close the data stream to free resources |
165 | | - if (is_resource($data)) { |
| 178 | + if ($data && is_resource($data)) { |
166 | 179 | fclose($data); |
167 | 180 | } |
168 | 181 | } |
|
0 commit comments