diff options
Diffstat (limited to 'apps/dav/lib')
-rw-r--r-- | apps/dav/lib/BackgroundJob/RefreshWebcalJob.php | 438 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/CachedSubscription.php | 198 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/CachedSubscriptionObject.php | 64 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/CalDavBackend.php | 465 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/CalendarHome.php | 20 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/WebcalCaching/Plugin.php | 145 | ||||
-rw-r--r-- | apps/dav/lib/Migration/RefreshWebcalJobRegistrar.php | 83 | ||||
-rw-r--r-- | apps/dav/lib/Migration/Version1006Date20180628111625.php | 105 | ||||
-rw-r--r-- | apps/dav/lib/Server.php | 3 |
9 files changed, 1405 insertions, 116 deletions
diff --git a/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php b/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php new file mode 100644 index 00000000000..871734aab55 --- /dev/null +++ b/apps/dav/lib/BackgroundJob/RefreshWebcalJob.php @@ -0,0 +1,438 @@ +<?php +declare(strict_types=1); +/** + * @copyright 2018 Georg Ehrke <oc.list@georgehrke.com> + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +namespace OCA\DAV\BackgroundJob; + +use GuzzleHttp\HandlerStack; +use GuzzleHttp\Middleware; +use OC\BackgroundJob\Job; +use OCA\DAV\CalDAV\CalDavBackend; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Http\Client\IClientService; +use OCP\IConfig; +use OCP\ILogger; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; +use Sabre\DAV\Exception\BadRequest; +use Sabre\DAV\PropPatch; +use Sabre\DAV\Xml\Property\Href; +use Sabre\VObject\Component; +use Sabre\VObject\DateTimeParser; +use Sabre\VObject\InvalidDataException; +use Sabre\VObject\ParseException; +use Sabre\VObject\Reader; +use Sabre\VObject\Splitter\ICalendar; + +class RefreshWebcalJob extends Job { + + /** @var CalDavBackend */ + private $calDavBackend; + + /** @var IClientService */ + private $clientService; + + /** @var IConfig */ + private $config; + + /** @var ILogger */ + private $logger; + + /** @var ITimeFactory */ + private $timeFactory; + + /** @var array */ + private $subscription; + + /** + * RefreshWebcalJob constructor. + * + * @param CalDavBackend $calDavBackend + * @param IClientService $clientService + * @param IConfig $config + * @param ILogger $logger + * @param ITimeFactory $timeFactory + */ + public function __construct(CalDavBackend $calDavBackend, IClientService $clientService, IConfig $config, ILogger $logger, ITimeFactory $timeFactory) { + $this->calDavBackend = $calDavBackend; + $this->clientService = $clientService; + $this->config = $config; + $this->logger = $logger; + $this->timeFactory = $timeFactory; + } + + /** + * this function is called at most every hour + * + * @inheritdoc + */ + public function execute($jobList, ILogger $logger = null) { + $subscription = $this->getSubscription($this->argument['principaluri'], $this->argument['uri']); + if (!$subscription) { + return; + } + + // if no refresh rate was configured, just refresh once a week + $subscriptionId = $subscription['id']; + $refreshrate = $subscription['refreshrate'] ?? 'P1W'; + + try { + /** @var \DateInterval $dateInterval */ + $dateInterval = DateTimeParser::parseDuration($refreshrate); + } catch(InvalidDataException $ex) { + $this->logger->logException($ex); + $this->logger->warning("Subscription $subscriptionId could not be refreshed, refreshrate in database is invalid"); + return; + } + + $interval = $this->getIntervalFromDateInterval($dateInterval); + if (($this->timeFactory->getTime() - $this->lastRun) <= $interval) { + return; + } + + parent::execute($jobList, $logger); + } + + /** + * @param array $argument + */ + protected function run($argument) { + $subscription = $this->getSubscription($argument['principaluri'], $argument['uri']); + $mutations = []; + if (!$subscription) { + return; + } + + $webcalData = $this->queryWebcalFeed($subscription, $mutations); + if (!$webcalData) { + return; + } + + $stripTodos = $subscription['striptodos'] ?? 1; + $stripAlarms = $subscription['stripalarms'] ?? 1; + $stripAttachments = $subscription['stripattachments'] ?? 1; + + try { + $splitter = new ICalendar($webcalData, Reader::OPTION_FORGIVING); + + // we wait with deleting all outdated events till we parsed the new ones + // in case the new calendar is broken and `new ICalendar` throws a ParseException + // the user will still see the old data + $this->calDavBackend->purgeAllCachedEventsForSubscription($subscription['id']); + + while ($vObject = $splitter->getNext()) { + /** @var Component $vObject */ + $uid = null; + $compName = null; + + foreach ($vObject->getComponents() as $component) { + if ($component->name === 'VTIMEZONE') { + continue; + } + + $uid = $component->{'UID'}->getValue(); + $compName = $component->name; + + if ($stripAlarms) { + unset($component->{'VALARM'}); + } + if ($stripAttachments) { + unset($component->{'ATTACH'}); + } + } + + if ($stripTodos && $compName === 'VTODO') { + continue; + } + + $uri = $uid . '.ics'; + $calendarData = $vObject->serialize(); + try { + $this->calDavBackend->createCalendarObject($subscription['id'], $uri, $calendarData, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); + } catch(BadRequest $ex) { + $this->logger->logException($ex); + } + } + + $newRefreshRate = $this->checkWebcalDataForRefreshRate($subscription, $webcalData); + if ($newRefreshRate) { + $mutations['{http://apple.com/ns/ical/}refreshrate'] = $newRefreshRate; + } + + $this->updateSubscription($subscription, $mutations); + } catch(ParseException $ex) { + $subscriptionId = $subscription['id']; + + $this->logger->logException($ex); + $this->logger->warning("Subscription $subscriptionId could not be refreshed due to a parsing error"); + } + } + + /** + * gets webcal feed from remote server + * + * @param array $subscription + * @param array &$mutations + * @return null|string + */ + private function queryWebcalFeed(array $subscription, array &$mutations) { + $client = $this->clientService->newClient(); + + $didBreak301Chain = false; + $latestLocation = null; + + $handlerStack = HandlerStack::create(); + $handlerStack->push(Middleware::mapRequest(function (RequestInterface $request) { + return $request + ->withHeader('Accept', 'text/calendar, application/calendar+json, application/calendar+xml') + ->withHeader('User-Agent', 'Nextcloud Webcal Crawler'); + })); + $handlerStack->push(Middleware::mapResponse(function(ResponseInterface $response) use (&$didBreak301Chain, &$latestLocation) { + if (!$didBreak301Chain) { + if ($response->getStatusCode() !== 301) { + $didBreak301Chain = true; + } else { + $latestLocation = $response->getHeader('Location'); + } + } + return $response; + })); + + $allowLocalAccess = $this->config->getAppValue('dav', 'webcalAllowLocalAccess', 'no'); + $subscriptionId = $subscription['id']; + $url = $this->cleanURL($subscription['source']); + if ($url === null) { + return null; + } + + if ($allowLocalAccess !== 'yes') { + $host = parse_url($url, PHP_URL_HOST); + // remove brackets from IPv6 addresses + if (strpos($host, '[') === 0 && substr($host, -1) === ']') { + $host = substr($host, 1, -1); + } + + if ($host === 'localhost' || substr($host, -6) === '.local' || substr($host, -10) === '.localhost' || + preg_match('/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/', $host)) { + $this->logger->warning("Subscription $subscriptionId was not refreshed because it violates local access rules"); + return null; + } + } + + try { + $params = [ + 'allow_redirects' => [ + 'redirects' => 10 + ], + 'handler' => $handlerStack, + ]; + + $user = parse_url($subscription['source'], PHP_URL_USER); + $pass = parse_url($subscription['source'], PHP_URL_PASS); + if ($user !== null && $pass !== null) { + $params['auth'] = [$user, $pass]; + } + + $response = $client->get($url, $params); + $body = $response->getBody(); + + if ($latestLocation) { + $mutations['{http://calendarserver.org/ns/}source'] = new Href($latestLocation); + } + + $contentType = $response->getHeader('Content-Type'); + $contentType = explode(';', $contentType, 2)[0]; + switch($contentType) { + case 'application/calendar+json': + try { + $jCalendar = Reader::readJson($body, Reader::OPTION_FORGIVING); + } catch(\Exception $ex) { + // In case of a parsing error return null + $this->logger->debug("Subscription $subscriptionId could not be parsed"); + return null; + } + return $jCalendar->serialize(); + + case 'application/calendar+xml': + try { + $xCalendar = Reader::readXML($body); + } catch(\Exception $ex) { + // In case of a parsing error return null + $this->logger->debug("Subscription $subscriptionId could not be parsed"); + return null; + } + return $xCalendar->serialize(); + + case 'text/calendar': + default: + try { + $vCalendar = Reader::read($body); + } catch(\Exception $ex) { + // In case of a parsing error return null + $this->logger->debug("Subscription $subscriptionId could not be parsed"); + return null; + } + return $vCalendar->serialize(); + } + } catch(\Exception $ex) { + $this->logger->logException($ex); + $this->logger->warning("Subscription $subscriptionId could not be refreshed due to a network error"); + + return null; + } + } + + /** + * loads subscription from backend + * + * @param string $principalUri + * @param string $uri + * @return array|null + */ + private function getSubscription(string $principalUri, string $uri) { + $subscriptions = array_values(array_filter( + $this->calDavBackend->getSubscriptionsForUser($principalUri), + function($sub) use ($uri) { + return $sub['uri'] === $uri; + } + )); + + if (\count($subscriptions) === 0) { + return null; + } + + $this->subscription = $subscriptions[0]; + return $this->subscription; + } + + /** + * get total number of seconds from DateInterval object + * + * @param \DateInterval $interval + * @return int + */ + private function getIntervalFromDateInterval(\DateInterval $interval):int { + return $interval->s + + ($interval->i * 60) + + ($interval->h * 60 * 60) + + ($interval->d * 60 * 60 * 24) + + ($interval->m * 60 * 60 * 24 * 30) + + ($interval->y * 60 * 60 * 24 * 365); + } + + /** + * check if: + * - current subscription stores a refreshrate + * - the webcal feed suggests a refreshrate + * - return suggested refreshrate if user didn't set a custom one + * + * @param array $subscription + * @param string $webcalData + * @return string|null + */ + 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) { + return null; + } + + /** @var Component\VCalendar $vCalendar */ + $vCalendar = Reader::read($webcalData); + + $newRefreshrate = null; + if (isset($vCalendar->{'X-PUBLISHED-TTL'})) { + $newRefreshrate = $vCalendar->{'X-PUBLISHED-TTL'}->getValue(); + } + if (isset($vCalendar->{'REFRESH-INTERVAL'})) { + $newRefreshrate = $vCalendar->{'REFRESH-INTERVAL'}->getValue(); + } + + if (!$newRefreshrate) { + return null; + } + + // check if new refresh rate is even valid + try { + DateTimeParser::parseDuration($newRefreshrate); + } catch(InvalidDataException $ex) { + return null; + } + + return $newRefreshrate; + } + + /** + * update subscription stored in database + * used to set: + * - refreshrate + * - source + * + * @param array $subscription + * @param array $mutations + */ + private function updateSubscription(array $subscription, array $mutations) { + if (empty($mutations)) { + return; + } + + $propPatch = new PropPatch($mutations); + $this->calDavBackend->updateSubscription($subscription['id'], $propPatch); + $propPatch->commit(); + } + + /** + * This method will strip authentication information and replace the + * 'webcal' or 'webcals' protocol scheme + * + * @param string $url + * @return string|null + */ + private function cleanURL(string $url) { + $parsed = parse_url($url); + if ($parsed === false) { + return null; + } + + if (isset($parsed['scheme']) && $parsed['scheme'] === 'http') { + $scheme = 'http'; + } else { + $scheme = 'https'; + } + + $host = $parsed['host'] ?? ''; + $port = isset($parsed['port']) ? ':' . $parsed['port'] : ''; + $path = $parsed['path'] ?? ''; + $query = isset($parsed['query']) ? '?' . $parsed['query'] : ''; + $fragment = isset($parsed['fragment']) ? '#' . $parsed['fragment'] : ''; + + $cleanURL = "$scheme://$host$port$path$query$fragment"; + // parse_url is giving some weird results if no url and no :// is given, + // so let's test the url again + $parsedClean = parse_url($cleanURL); + if ($parsedClean === false || !isset($parsedClean['host'])) { + return null; + } + + return $cleanURL; + } +} diff --git a/apps/dav/lib/CalDAV/CachedSubscription.php b/apps/dav/lib/CalDAV/CachedSubscription.php new file mode 100644 index 00000000000..a95ee15bbe5 --- /dev/null +++ b/apps/dav/lib/CalDAV/CachedSubscription.php @@ -0,0 +1,198 @@ +<?php +declare(strict_types=1); +/** + * @copyright 2018 Georg Ehrke <oc.list@georgehrke.com> + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +namespace OCA\DAV\CalDAV; + +use Sabre\CalDAV\Backend\BackendInterface; +use Sabre\DAV\Exception\MethodNotAllowed; +use Sabre\DAV\Exception\NotFound; +use Sabre\DAV\PropPatch; + +/** + * Class CachedSubscription + * + * @package OCA\DAV\CalDAV + * @property BackendInterface|CalDavBackend $caldavBackend + */ +class CachedSubscription extends \Sabre\CalDAV\Calendar { + + /** + * @return string + */ + public function getPrincipalURI():string { + return $this->calendarInfo['principaluri']; + } + + /** + * @return array + */ + public function getACL():array { + return [ + [ + 'privilege' => '{DAV:}read', + 'principal' => $this->getOwner(), + 'protected' => true, + ], + [ + 'privilege' => '{DAV:}read', + 'principal' => $this->getOwner() . '/calendar-proxy-write', + 'protected' => true, + ], + [ + 'privilege' => '{DAV:}read', + 'principal' => $this->getOwner() . '/calendar-proxy-read', + 'protected' => true, + ], + [ + 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy', + 'principal' => '{DAV:}authenticated', + 'protected' => true, + ], + ]; + } + + /** + * @return array + */ + public function getChildACL():array { + return [ + [ + 'privilege' => '{DAV:}read', + 'principal' => $this->getOwner(), + 'protected' => true, + ], + + [ + 'privilege' => '{DAV:}read', + 'principal' => $this->getOwner() . '/calendar-proxy-write', + 'protected' => true, + ], + [ + 'privilege' => '{DAV:}read', + 'principal' => $this->getOwner() . '/calendar-proxy-read', + 'protected' => true, + ], + + ]; + } + + /** + * @return null|string + */ + public function getOwner() { + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; + } + return parent::getOwner(); + } + + /** + * + */ + public function delete() { + $this->caldavBackend->deleteSubscription($this->calendarInfo['id']); + } + + /** + * @param PropPatch $propPatch + */ + public function propPatch(PropPatch $propPatch) { + $this->caldavBackend->updateSubscription($this->calendarInfo['id'], $propPatch); + } + + /** + * @param string $name + * @return CalendarObject|\Sabre\CalDAV\ICalendarObject + * @throws NotFound + */ + public function getChild($name) { + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); + if (!$obj) { + throw new NotFound('Calendar object not found'); + } + + $obj['acl'] = $this->getChildACL(); + return new CachedSubscriptionObject ($this->caldavBackend, $this->calendarInfo, $obj); + + } + + /** + * @return array + */ + public function getChildren():array { + $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); + + $children = []; + foreach($objs as $obj) { + $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj); + } + + return $children; + } + + /** + * @param array $paths + * @return array + */ + public function getMultipleChildren(array $paths):array { + $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); + + $children = []; + foreach($objs as $obj) { + $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj); + } + + return $children; + } + + /** + * @param string $name + * @param null $calendarData + * @return null|string|void + * @throws MethodNotAllowed + */ + public function createFile($name, $calendarData = null) { + throw new MethodNotAllowed('Creating objects in cached subscription is not allowed'); + } + + /** + * @param string $name + * @return bool + */ + public function childExists($name):bool { + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); + if (!$obj) { + return false; + } + + return true; + } + + /** + * @param array $filters + * @return array + */ + public function calendarQuery(array $filters):array { + return $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); + } +} diff --git a/apps/dav/lib/CalDAV/CachedSubscriptionObject.php b/apps/dav/lib/CalDAV/CachedSubscriptionObject.php new file mode 100644 index 00000000000..c2f7eeabf41 --- /dev/null +++ b/apps/dav/lib/CalDAV/CachedSubscriptionObject.php @@ -0,0 +1,64 @@ +<?php +declare(strict_types=1); +/** + * @copyright 2018 Georg Ehrke <oc.list@georgehrke.com> + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +namespace OCA\DAV\CalDAV; + +use Sabre\DAV\Exception\MethodNotAllowed; + +/** + * Class CachedSubscriptionObject + * + * @package OCA\DAV\CalDAV + * @property CalDavBackend $caldavBackend + */ +class CachedSubscriptionObject extends \Sabre\CalDAV\CalendarObject { + + /** + * @inheritdoc + */ + public function get() { + // Pre-populating the 'calendardata' is optional, if we don't have it + // already we fetch it from the backend. + if (!isset($this->objectData['calendardata'])) { + $this->objectData = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $this->objectData['uri'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); + } + + return $this->objectData['calendardata']; + } + + /** + * @param resource|string $calendarData + * @return string|void + * @throws MethodNotAllowed + */ + public function put($calendarData) { + throw new MethodNotAllowed('Creating objects in a cached subscription is not allowed'); + } + + /** + * @throws MethodNotAllowed + */ + public function delete() { + throw new MethodNotAllowed('Deleting objects in a cached subscription is not allowed'); + } +} diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index df10b62fc5b..60f163abcbf 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -1,7 +1,7 @@ <?php /** * @copyright Copyright (c) 2016, ownCloud, Inc. - * @copyright Copyright (c) 2017 Georg Ehrke + * @copyright Copyright (c) 2018 Georg Ehrke * * @author Georg Ehrke <oc.list@georgehrke.com> * @author Joas Schilling <coding@schilljs.com> @@ -73,6 +73,9 @@ use Symfony\Component\EventDispatcher\GenericEvent; */ class CalDavBackend extends AbstractBackend implements SyncSupport, SubscriptionSupport, SchedulingSupport { + const CALENDAR_TYPE_CALENDAR = 0; + const CALENDAR_TYPE_SUBSCRIPTION = 1; + const PERSONAL_CALENDAR_URI = 'personal'; const PERSONAL_CALENDAR_NAME = 'Personal'; @@ -145,7 +148,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription private $db; /** @var Backend */ - private $sharingBackend; + private $calendarSharingBackend; /** @var Principal */ private $principalBackend; @@ -191,7 +194,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription $this->db = $db; $this->principalBackend = $principalBackend; $this->userManager = $userManager; - $this->sharingBackend = new Backend($this->db, $this->userManager, $groupManager, $principalBackend, 'calendar'); + $this->calendarSharingBackend = new Backend($this->db, $this->userManager, $groupManager, $principalBackend, 'calendar'); $this->random = $random; $this->logger = $logger; $this->dispatcher = $dispatcher; @@ -372,6 +375,10 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription return array_values($calendars); } + /** + * @param $principalUri + * @return array + */ public function getUsersOwnCalendars($principalUri) { $principalUri = $this->convertPrincipal($principalUri, true); $fields = array_values($this->propertyMap); @@ -417,6 +424,10 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } + /** + * @param $uid + * @return string + */ private function getUserDisplayName($uid) { if (!isset($this->userDisplayNames[$uid])) { $user = $this->userManager->get($uid); @@ -601,6 +612,10 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription return $calendar; } + /** + * @param $calendarId + * @return array|null + */ public function getCalendarById($calendarId) { $fields = array_values($this->propertyMap); $fields[] = 'id'; @@ -648,6 +663,50 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } /** + * @param $subscriptionId + */ + public function getSubscriptionById($subscriptionId) { + $fields = array_values($this->subscriptionPropertyMap); + $fields[] = 'id'; + $fields[] = 'uri'; + $fields[] = 'source'; + $fields[] = 'synctoken'; + $fields[] = 'principaluri'; + $fields[] = 'lastmodified'; + + $query = $this->db->getQueryBuilder(); + $query->select($fields) + ->from('calendarsubscriptions') + ->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) + ->orderBy('calendarorder', 'asc'); + $stmt =$query->execute(); + + $row = $stmt->fetch(\PDO::FETCH_ASSOC); + $stmt->closeCursor(); + if ($row === false) { + return null; + } + + $subscription = [ + 'id' => $row['id'], + 'uri' => $row['uri'], + 'principaluri' => $row['principaluri'], + 'source' => $row['source'], + 'lastmodified' => $row['lastmodified'], + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', + ]; + + foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { + if (!is_null($row[$dbName])) { + $subscription[$xmlName] = $row[$dbName]; + } + } + + return $subscription; + } + + /** * Creates a new calendar for a principal. * * If the creation was a success, an id must be returned that can be used to reference @@ -783,20 +842,21 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription 'shares' => $this->getShares($calendarId), ])); - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?'); - $stmt->execute([$calendarId]); + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `calendartype` = ?'); + $stmt->execute([$calendarId, self::CALENDAR_TYPE_CALENDAR]); $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendars` WHERE `id` = ?'); $stmt->execute([$calendarId]); - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarchanges` WHERE `calendarid` = ?'); - $stmt->execute([$calendarId]); + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarchanges` WHERE `calendarid` = ? AND `calendartype` = ?'); + $stmt->execute([$calendarId, self::CALENDAR_TYPE_CALENDAR]); - $this->sharingBackend->deleteAllShares($calendarId); + $this->calendarSharingBackend->deleteAllShares($calendarId); $query = $this->db->getQueryBuilder(); $query->delete($this->dbObjectPropertiesTable) ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_CALENDAR))) ->execute(); } @@ -807,7 +867,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @return void */ function deleteAllSharesByUser($principaluri) { - $this->sharingBackend->deleteAllSharesByUser($principaluri); + $this->calendarSharingBackend->deleteAllSharesByUser($principaluri); } /** @@ -838,27 +898,29 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * used/fetched to determine these numbers. If both are specified the * amount of times this is needed is reduced by a great degree. * - * @param mixed $calendarId + * @param mixed $id + * @param int $calendarType * @return array */ - function getCalendarObjects($calendarId) { + public function getCalendarObjects($id, $calendarType=self::CALENDAR_TYPE_CALENDAR):array { $query = $this->db->getQueryBuilder(); $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'componenttype', 'classification']) ->from('calendarobjects') - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($id))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType))); $stmt = $query->execute(); $result = []; foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { $result[] = [ - 'id' => $row['id'], - 'uri' => $row['uri'], - 'lastmodified' => $row['lastmodified'], - 'etag' => '"' . $row['etag'] . '"', - 'calendarid' => $row['calendarid'], - 'size' => (int)$row['size'], - 'component' => strtolower($row['componenttype']), - 'classification'=> (int)$row['classification'] + 'id' => $row['id'], + 'uri' => $row['uri'], + 'lastmodified' => $row['lastmodified'], + 'etag' => '"' . $row['etag'] . '"', + 'calendarid' => $row['calendarid'], + 'size' => (int)$row['size'], + 'component' => strtolower($row['componenttype']), + 'classification'=> (int)$row['classification'] ]; } @@ -877,32 +939,35 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * * This method must return null if the object did not exist. * - * @param mixed $calendarId + * @param mixed $id * @param string $objectUri + * @param int $calendarType * @return array|null */ - function getCalendarObject($calendarId, $objectUri) { - + public function getCalendarObject($id, $objectUri, $calendarType=self::CALENDAR_TYPE_CALENDAR) { $query = $this->db->getQueryBuilder(); $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) - ->from('calendarobjects') - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))); + ->from('calendarobjects') + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($id))) + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType))); $stmt = $query->execute(); $row = $stmt->fetch(\PDO::FETCH_ASSOC); - if(!$row) return null; + if(!$row) { + return null; + } return [ - 'id' => $row['id'], - 'uri' => $row['uri'], - 'lastmodified' => $row['lastmodified'], - 'etag' => '"' . $row['etag'] . '"', - 'calendarid' => $row['calendarid'], - 'size' => (int)$row['size'], - 'calendardata' => $this->readBlob($row['calendardata']), - 'component' => strtolower($row['componenttype']), - 'classification'=> (int)$row['classification'] + 'id' => $row['id'], + 'uri' => $row['uri'], + 'lastmodified' => $row['lastmodified'], + 'etag' => '"' . $row['etag'] . '"', + 'calendarid' => $row['calendarid'], + 'size' => (int)$row['size'], + 'calendardata' => $this->readBlob($row['calendardata']), + 'component' => strtolower($row['componenttype']), + 'classification'=> (int)$row['classification'] ]; } @@ -916,9 +981,10 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * * @param mixed $calendarId * @param string[] $uris + * @param int $calendarType * @return array */ - function getMultipleCalendarObjects($calendarId, array $uris) { + public function getMultipleCalendarObjects($id, array $uris, $calendarType=self::CALENDAR_TYPE_CALENDAR):array { if (empty($uris)) { return []; } @@ -929,8 +995,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription $query = $this->db->getQueryBuilder(); $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) ->from('calendarobjects') - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) - ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($id))) + ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType))); foreach ($chunks as $uris) { $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); @@ -951,6 +1018,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } $result->closeCursor(); } + return $objects; } @@ -970,16 +1038,18 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @param mixed $calendarId * @param string $objectUri * @param string $calendarData + * @param int $calendarType * @return string */ - function createCalendarObject($calendarId, $objectUri, $calendarData) { + function createCalendarObject($calendarId, $objectUri, $calendarData, $calendarType=self::CALENDAR_TYPE_CALENDAR) { $extraData = $this->getDenormalizedData($calendarData); $q = $this->db->getQueryBuilder(); $q->select($q->createFunction('COUNT(*)')) ->from('calendarobjects') ->where($q->expr()->eq('calendarid', $q->createNamedParameter($calendarId))) - ->andWhere($q->expr()->eq('uid', $q->createNamedParameter($extraData['uid']))); + ->andWhere($q->expr()->eq('uid', $q->createNamedParameter($extraData['uid']))) + ->andWhere($q->expr()->eq('calendartype', $q->createNamedParameter($calendarType))); $result = $q->execute(); $count = (int) $result->fetchColumn(); @@ -1003,21 +1073,34 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription 'lastoccurence' => $query->createNamedParameter($extraData['lastOccurence']), 'classification' => $query->createNamedParameter($extraData['classification']), 'uid' => $query->createNamedParameter($extraData['uid']), + 'calendartype' => $query->createNamedParameter($calendarType), ]) ->execute(); - $this->updateProperties($calendarId, $objectUri, $calendarData); + $this->updateProperties($calendarId, $objectUri, $calendarData, $calendarType); - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( - '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', - [ - 'calendarId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), - 'shares' => $this->getShares($calendarId), - 'objectData' => $this->getCalendarObject($calendarId, $objectUri), - ] - )); - $this->addChange($calendarId, $objectUri, 1); + if ($calendarType === self::CALENDAR_TYPE_CALENDAR) { + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( + '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', + [ + 'calendarId' => $calendarId, + 'calendarData' => $this->getCalendarById($calendarId), + 'shares' => $this->getShares($calendarId), + 'objectData' => $this->getCalendarObject($calendarId, $objectUri), + ] + )); + } else { + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCachedCalendarObject', new GenericEvent( + '\OCA\DAV\CalDAV\CalDavBackend::createCachedCalendarObject', + [ + 'subscriptionId' => $calendarId, + 'calendarData' => $this->getCalendarById($calendarId), + 'shares' => $this->getShares($calendarId), + 'objectData' => $this->getCalendarObject($calendarId, $objectUri), + ] + )); + } + $this->addChange($calendarId, $objectUri, 1, $calendarType); return '"' . $extraData['etag'] . '"'; } @@ -1038,9 +1121,10 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @param mixed $calendarId * @param string $objectUri * @param string $calendarData + * @param int $calendarType * @return string */ - function updateCalendarObject($calendarId, $objectUri, $calendarData) { + function updateCalendarObject($calendarId, $objectUri, $calendarData, $calendarType=self::CALENDAR_TYPE_CALENDAR) { $extraData = $this->getDenormalizedData($calendarData); $query = $this->db->getQueryBuilder(); @@ -1056,23 +1140,36 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription ->set('uid', $query->createNamedParameter($extraData['uid'])) ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType))) ->execute(); - $this->updateProperties($calendarId, $objectUri, $calendarData); + $this->updateProperties($calendarId, $objectUri, $calendarData, $calendarType); $data = $this->getCalendarObject($calendarId, $objectUri); if (is_array($data)) { - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( - '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', - [ - 'calendarId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), - 'shares' => $this->getShares($calendarId), - 'objectData' => $data, - ] - )); + if ($calendarType === self::CALENDAR_TYPE_CALENDAR) { + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( + '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', + [ + 'calendarId' => $calendarId, + 'calendarData' => $this->getCalendarById($calendarId), + 'shares' => $this->getShares($calendarId), + 'objectData' => $data, + ] + )); + } else { + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCachedCalendarObject', new GenericEvent( + '\OCA\DAV\CalDAV\CalDavBackend::updateCachedCalendarObject', + [ + 'subscriptionId' => $calendarId, + 'calendarData' => $this->getCalendarById($calendarId), + 'shares' => $this->getShares($calendarId), + 'objectData' => $data, + ] + )); + } } - $this->addChange($calendarId, $objectUri, 2); + $this->addChange($calendarId, $objectUri, 2, $calendarType); return '"' . $extraData['etag'] . '"'; } @@ -1101,28 +1198,41 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * * @param mixed $calendarId * @param string $objectUri + * @param int $calendarType * @return void */ - function deleteCalendarObject($calendarId, $objectUri) { - $data = $this->getCalendarObject($calendarId, $objectUri); + function deleteCalendarObject($calendarId, $objectUri, $calendarType=self::CALENDAR_TYPE_CALENDAR) { + $data = $this->getCalendarObject($calendarId, $objectUri, $calendarType); if (is_array($data)) { - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( - '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', - [ - 'calendarId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), - 'shares' => $this->getShares($calendarId), - 'objectData' => $data, - ] - )); + if ($calendarType === self::CALENDAR_TYPE_CALENDAR) { + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( + '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', + [ + 'calendarId' => $calendarId, + 'calendarData' => $this->getCalendarById($calendarId), + 'shares' => $this->getShares($calendarId), + 'objectData' => $data, + ] + )); + } else { + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCachedCalendarObject', new GenericEvent( + '\OCA\DAV\CalDAV\CalDavBackend::deleteCachedCalendarObject', + [ + 'subscriptionId' => $calendarId, + 'calendarData' => $this->getCalendarById($calendarId), + 'shares' => $this->getShares($calendarId), + 'objectData' => $data, + ] + )); + } } - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ?'); - $stmt->execute([$calendarId, $objectUri]); + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ? AND `calendartype` = ?'); + $stmt->execute([$calendarId, $objectUri, $calendarType]); - $this->purgeProperties($calendarId, $data['id']); + $this->purgeProperties($calendarId, $data['id'], $calendarType); - $this->addChange($calendarId, $objectUri, 3); + $this->addChange($calendarId, $objectUri, 3, $calendarType); } /** @@ -1170,11 +1280,12 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * as possible, so it gives you a good idea on what type of stuff you need * to think of. * - * @param mixed $calendarId + * @param mixed $id * @param array $filters + * @param int $calendarType * @return array */ - function calendarQuery($calendarId, array $filters) { + public function calendarQuery($id, array $filters, $calendarType=self::CALENDAR_TYPE_CALENDAR):array { $componentType = null; $requirePostFilter = true; $timeRange = null; @@ -1211,7 +1322,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription $query = $this->db->getQueryBuilder(); $query->select($columns) ->from('calendarobjects') - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($id))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType))); if ($componentType) { $query->andWhere($query->expr()->eq('componenttype', $query->createNamedParameter($componentType))); @@ -1236,13 +1348,13 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } catch(ParseException $ex) { $this->logger->logException($ex, [ 'app' => 'dav', - 'message' => 'Caught parsing exception for calendar data. This usually indicates invalid calendar data. calendar-id:'.$calendarId.' uri:'.$row['uri'] + 'message' => 'Caught parsing exception for calendar data. This usually indicates invalid calendar data. calendar-id:'.$id.' uri:'.$row['uri'] ]); continue; } catch (InvalidDataException $ex) { $this->logger->logException($ex, [ 'app' => 'dav', - 'message' => 'Caught invalid data exception for calendar data. This usually indicates invalid calendar data. calendar-id:'.$calendarId.' uri:'.$row['uri'] + 'message' => 'Caught invalid data exception for calendar data. This usually indicates invalid calendar data. calendar-id:'.$id.' uri:'.$row['uri'] ]); continue; } @@ -1260,6 +1372,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription /** * custom Nextcloud search extension for CalDAV * + * TODO - this should optionally cover cached calendar objects as well + * * @param string $principalUri * @param array $filters * @param integer|null $limit @@ -1289,16 +1403,20 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription // Calendar id expressions $calendarExpressions = []; foreach($ownCalendars as $id) { - $calendarExpressions[] = $query->expr() - ->eq('c.calendarid', $query->createNamedParameter($id)); + $calendarExpressions[] = $query->expr()->andX( + $query->expr()->eq('c.calendarid', + $query->createNamedParameter($id)), + $query->expr()->eq('c.calendartype', + $query->createNamedParameter(self::CALENDAR_TYPE_CALENDAR))); } foreach($sharedCalendars as $id) { $calendarExpressions[] = $query->expr()->andX( $query->expr()->eq('c.calendarid', $query->createNamedParameter($id)), $query->expr()->eq('c.classification', - $query->createNamedParameter(self::CLASSIFICATION_PUBLIC)) - ); + $query->createNamedParameter(self::CLASSIFICATION_PUBLIC)), + $query->expr()->eq('c.calendartype', + $query->createNamedParameter(self::CALENDAR_TYPE_CALENDAR))); } if (count($calendarExpressions) === 1) { @@ -1396,7 +1514,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription $innerQuery->selectDistinct('op.objectid') ->from($this->dbObjectPropertiesTable, 'op') ->andWhere($innerQuery->expr()->eq('op.calendarid', - $outerQuery->createNamedParameter($calendarInfo['id']))); + $outerQuery->createNamedParameter($calendarInfo['id']))) + ->andWhere($innerQuery->expr()->eq('op.calendartype', + $outerQuery->createNamedParameter(self::CALENDAR_TYPE_CALENDAR))); // only return public items for shared calendars for now if ($calendarInfo['principaluri'] !== $calendarInfo['{http://owncloud.org/ns}owner-principal']) { @@ -1569,6 +1689,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription ->from('calendarobjects', 'co') ->leftJoin('co', 'calendars', 'c', $query->expr()->eq('co.calendarid', 'c.id')) ->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri))) + ->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid))) ->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid))); $stmt = $query->execute(); @@ -1634,9 +1755,10 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @param string $syncToken * @param int $syncLevel * @param int $limit + * @param int $calendarType * @return array */ - function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { + function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null, $calendarType=self::CALENDAR_TYPE_CALENDAR) { // Current synctoken $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); $stmt->execute([ $calendarId ]); @@ -1655,14 +1777,14 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription if ($syncToken) { - $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; + $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? AND `calendartype` = ? ORDER BY `synctoken`"; if ($limit>0) { $query.= " LIMIT " . (int)$limit; } // Fetching all changes $stmt = $this->db->prepare($query); - $stmt->execute([$syncToken, $currentToken, $calendarId]); + $stmt->execute([$syncToken, $currentToken, $calendarId, $calendarType]); $changes = []; @@ -1691,9 +1813,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } } else { // No synctoken supplied, this is the initial sync. - $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?"; + $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `calendartype` = ?"; $stmt = $this->db->prepare($query); - $stmt->execute([$calendarId]); + $stmt->execute([$calendarId, $calendarType]); $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); } @@ -1740,6 +1862,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription $fields[] = 'source'; $fields[] = 'principaluri'; $fields[] = 'lastmodified'; + $fields[] = 'synctoken'; $query = $this->db->getQueryBuilder(); $query->select($fields) @@ -1759,6 +1882,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription 'lastmodified' => $row['lastmodified'], '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', ]; foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { @@ -1821,7 +1945,16 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription ->values($valuesToInsert) ->execute(); - return $this->db->lastInsertId('*PREFIX*calendarsubscriptions'); + $subscriptionId = $this->db->lastInsertId('*PREFIX*calendarsubscriptions'); + + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createSubscription', new GenericEvent( + '\OCA\DAV\CalDAV\CalDavBackend::createSubscription', + [ + 'subscriptionId' => $subscriptionId, + 'subscriptionData' => $this->getSubscriptionById($subscriptionId), + ])); + + return $subscriptionId; } /** @@ -1869,6 +2002,14 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) ->execute(); + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateSubscription', new GenericEvent( + '\OCA\DAV\CalDAV\CalDavBackend::updateSubscription', + [ + 'subscriptionId' => $subscriptionId, + 'subscriptionData' => $this->getSubscriptionById($subscriptionId), + 'propertyMutations' => $mutations, + ])); + return true; }); @@ -1881,10 +2022,33 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @return void */ function deleteSubscription($subscriptionId) { + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription', new GenericEvent( + '\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription', + [ + 'subscriptionId' => $subscriptionId, + 'subscriptionData' => $this->getSubscriptionById($subscriptionId), + ])); + $query = $this->db->getQueryBuilder(); $query->delete('calendarsubscriptions') ->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) ->execute(); + + $query = $this->db->getQueryBuilder(); + $query->delete('calendarobjects') + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION))) + ->execute(); + + $query->delete('calendarchanges') + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION))) + ->execute(); + + $query->delete($this->dbObjectPropertiesTable) + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION))) + ->execute(); } /** @@ -2001,18 +2165,30 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @param mixed $calendarId * @param string $objectUri * @param int $operation 1 = add, 2 = modify, 3 = delete. + * @param int $calendarType * @return void */ - protected function addChange($calendarId, $objectUri, $operation) { + protected function addChange($calendarId, $objectUri, $operation, $calendarType=self::CALENDAR_TYPE_CALENDAR) { + $table = $calendarType === self::CALENDAR_TYPE_CALENDAR ? 'calendars': 'calendarsubscriptions'; - $stmt = $this->db->prepare('INSERT INTO `*PREFIX*calendarchanges` (`uri`, `synctoken`, `calendarid`, `operation`) SELECT ?, `synctoken`, ?, ? FROM `*PREFIX*calendars` WHERE `id` = ?'); - $stmt->execute([ - $objectUri, - $calendarId, - $operation, - $calendarId - ]); - $stmt = $this->db->prepare('UPDATE `*PREFIX*calendars` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?'); + $query = $this->db->getQueryBuilder(); + $query->select('synctoken') + ->from($table) + ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); + $syncToken = (int)$query->execute()->fetchColumn(); + + $query = $this->db->getQueryBuilder(); + $query->insert('calendarchanges') + ->values([ + 'uri' => $query->createNamedParameter($objectUri), + 'synctoken' => $query->createNamedParameter($syncToken), + 'calendarid' => $query->createNamedParameter($calendarId), + 'operation' => $query->createNamedParameter($operation), + 'calendartype' => $query->createNamedParameter($calendarType), + ]) + ->execute(); + + $stmt = $this->db->prepare("UPDATE `*PREFIX*$table` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?"); $stmt->execute([ $calendarId ]); @@ -2111,6 +2287,10 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } + /** + * @param $cardData + * @return bool|string + */ private function readBlob($cardData) { if (is_resource($cardData)) { return stream_get_contents($cardData); @@ -2135,15 +2315,16 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription 'add' => $add, 'remove' => $remove, ])); - $this->sharingBackend->updateShares($shareable, $add, $remove); + $this->calendarSharingBackend->updateShares($shareable, $add, $remove); } /** * @param int $resourceId + * @param int $calendarType * @return array */ - public function getShares($resourceId) { - return $this->sharingBackend->getShares($resourceId); + public function getShares($resourceId, $calendarType=self::CALENDAR_TYPE_CALENDAR) { + return $this->calendarSharingBackend->getShares($resourceId); } /** @@ -2206,7 +2387,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @return array */ public function applyShareAcl($resourceId, $acl) { - return $this->sharingBackend->applyShareAcl($resourceId, $acl); + return $this->calendarSharingBackend->applyShareAcl($resourceId, $acl); } @@ -2217,9 +2398,10 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @param int $calendarId * @param string $objectUri * @param string $calendarData + * @param int $calendarType */ - public function updateProperties($calendarId, $objectUri, $calendarData) { - $objectId = $this->getCalendarObjectId($calendarId, $objectUri); + public function updateProperties($calendarId, $objectUri, $calendarData, $calendarType=self::CALENDAR_TYPE_CALENDAR) { + $objectId = $this->getCalendarObjectId($calendarId, $objectUri, $calendarType); try { $vCalendar = $this->readCalendarData($calendarData); @@ -2234,6 +2416,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription ->values( [ 'calendarid' => $query->createNamedParameter($calendarId), + 'calendartype' => $query->createNamedParameter($calendarType), 'objectid' => $query->createNamedParameter($objectId), 'name' => $query->createParameter('name'), 'parameter' => $query->createParameter('parameter'), @@ -2291,8 +2474,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription public function deleteAllBirthdayCalendars() { $query = $this->db->getQueryBuilder(); $result = $query->select(['id'])->from('calendars') - ->where($query->expr()->eq('uri', - $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) + ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) ->execute(); $ids = $result->fetchAll(); @@ -2302,6 +2484,44 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } /** + * @param $subscriptionId + */ + public function purgeAllCachedEventsForSubscription($subscriptionId) { + $query = $this->db->getQueryBuilder(); + $query->select('uri') + ->from('calendarobjects') + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION))); + $stmt = $query->execute(); + + $uris = []; + foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { + $uris[] = $row['uri']; + } + $stmt->closeCursor(); + + $query = $this->db->getQueryBuilder(); + $query->delete('calendarobjects') + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION))) + ->execute(); + + $query->delete('calendarchanges') + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION))) + ->execute(); + + $query->delete($this->dbObjectPropertiesTable) + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION))) + ->execute(); + + foreach($uris as $uri) { + $this->addChange($subscriptionId, $uri, 3, self::CALENDAR_TYPE_SUBSCRIPTION); + } + } + + /** * read VCalendar data into a VCalendar object * * @param string $objectData @@ -2330,13 +2550,16 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * * @param int $calendarId * @param string $uri + * @param int $calendarType * @return int */ - protected function getCalendarObjectId($calendarId, $uri) { + protected function getCalendarObjectId($calendarId, $uri, $calendarType):int { $query = $this->db->getQueryBuilder(); - $query->select('id')->from('calendarobjects') + $query->select('id') + ->from('calendarobjects') ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) - ->andWhere($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); + ->andWhere($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) + ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType))); $result = $query->execute(); $objectIds = $result->fetch(); @@ -2349,6 +2572,13 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription return (int)$objectIds['id']; } + /** + * return legacy endpoint principal name to new principal name + * + * @param $principalUri + * @param $toV2 + * @return string + */ private function convertPrincipal($principalUri, $toV2) { if ($this->principalBackend->getPrincipalPrefix() === 'principals') { list(, $name) = Uri\split($principalUri); @@ -2360,6 +2590,11 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription return $principalUri; } + /** + * adds information about an owner to the calendar data + * + * @param $calendarInfo + */ private function addOwnerPrincipal(&$calendarInfo) { $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'; $displaynameKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'; diff --git a/apps/dav/lib/CalDAV/CalendarHome.php b/apps/dav/lib/CalDAV/CalendarHome.php index 6700b1b2496..9ff71410f87 100644 --- a/apps/dav/lib/CalDAV/CalendarHome.php +++ b/apps/dav/lib/CalDAV/CalendarHome.php @@ -42,6 +42,9 @@ class CalendarHome extends \Sabre\CalDAV\CalendarHome { /** @var \OCP\IConfig */ private $config; + /** @var bool */ + private $returnCachedSubscriptions=false; + public function __construct(BackendInterface $caldavBackend, $principalInfo) { parent::__construct($caldavBackend, $principalInfo); $this->l10n = \OC::$server->getL10N('dav'); @@ -91,7 +94,11 @@ class CalendarHome extends \Sabre\CalDAV\CalendarHome { // If the backend supports subscriptions, we'll add those as well, if ($this->caldavBackend instanceof SubscriptionSupport) { foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { - $objects[] = new Subscription($this->caldavBackend, $subscription); + if ($this->returnCachedSubscriptions) { + $objects[] = new CachedSubscription($this->caldavBackend, $subscription); + } else { + $objects[] = new Subscription($this->caldavBackend, $subscription); + } } } @@ -123,6 +130,10 @@ class CalendarHome extends \Sabre\CalDAV\CalendarHome { if ($this->caldavBackend instanceof SubscriptionSupport) { foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { if ($subscription['uri'] === $name) { + if ($this->returnCachedSubscriptions) { + return new CachedSubscription($this->caldavBackend, $subscription); + } + return new Subscription($this->caldavBackend, $subscription); } } @@ -141,4 +152,11 @@ class CalendarHome extends \Sabre\CalDAV\CalendarHome { $principalUri = $this->principalInfo['uri']; return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset); } + + /** + * + */ + public function enableCachedSubscriptionsForThisRequest() { + $this->returnCachedSubscriptions = true; + } } diff --git a/apps/dav/lib/CalDAV/WebcalCaching/Plugin.php b/apps/dav/lib/CalDAV/WebcalCaching/Plugin.php new file mode 100644 index 00000000000..de2ff5a8e8b --- /dev/null +++ b/apps/dav/lib/CalDAV/WebcalCaching/Plugin.php @@ -0,0 +1,145 @@ +<?php +declare(strict_types=1); +/** + * @copyright 2018 Georg Ehrke <oc.list@georgehrke.com> + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +namespace OCA\DAV\CalDAV\WebcalCaching; + +use OCA\DAV\CalDAV\CalendarHome; +use OCP\IRequest; +use Sabre\DAV\Exception\NotFound; +use Sabre\DAV\Server; +use Sabre\DAV\ServerPlugin; +use Sabre\HTTP\RequestInterface; +use Sabre\HTTP\ResponseInterface; + +class Plugin extends ServerPlugin { + + /** + * list of regular expressions for calendar user agents, + * that do not support subscriptions on their own + * + * @var string[] + */ + const ENABLE_FOR_CLIENTS = []; + + /** + * @var bool + */ + private $enabled=false; + + /** + * @var Server + */ + private $server; + + /** + * Plugin constructor. + * + * @param IRequest $request + */ + public function __construct(IRequest $request) { + if ($request->isUserAgent(self::ENABLE_FOR_CLIENTS)) { + $this->enabled = true; + } + + $magicHeader = $request->getHeader('X-NC-CalDAV-Webcal-Caching'); + if ($magicHeader === 'On') { + $this->enabled = true; + } + } + + /** + * This initializes the plugin. + * + * This function is called by Sabre\DAV\Server, after + * addPlugin is called. + * + * This method should set up the required event subscriptions. + * + * @param Server $server + */ + public function initialize(Server $server) { + $this->server = $server; + $server->on('beforeMethod', [$this, 'beforeMethod']); + } + + /** + * @param RequestInterface $request + * @param ResponseInterface $response + */ + public function beforeMethod(RequestInterface $request, ResponseInterface $response) { + if (!$this->enabled) { + return; + } + + $path = $request->getPath(); + $pathParts = explode('/', ltrim($path, '/')); + if (\count($pathParts) < 2) { + return; + } + + // $calendarHomePath will look like: calendars/username + $calendarHomePath = $pathParts[0] . '/' . $pathParts[1]; + try { + $calendarHome = $this->server->tree->getNodeForPath($calendarHomePath); + if (!($calendarHome instanceof CalendarHome)) { + //how did we end up here? + return; + } + + $calendarHome->enableCachedSubscriptionsForThisRequest(); + } catch(NotFound $ex) { + return; + } + } + + /** + * @return bool + */ + public function isCachingEnabledForThisRequest():bool { + return $this->enabled; + } + + /** + * This method should return a list of server-features. + * + * This is for example 'versioning' and is added to the DAV: header + * in an OPTIONS response. + * + * @return string[] + */ + public function getFeatures():array { + return ['nc-calendar-webcal-cache']; + } + + /** + * Returns a plugin name. + * + * Using this name other plugins will be able to access other plugins + * using Sabre\DAV\Server::getPlugin + * + * @return string + */ + public function getPluginName():string { + return 'nc-calendar-webcal-cache'; + } +} diff --git a/apps/dav/lib/Migration/RefreshWebcalJobRegistrar.php b/apps/dav/lib/Migration/RefreshWebcalJobRegistrar.php new file mode 100644 index 00000000000..912e0aec98e --- /dev/null +++ b/apps/dav/lib/Migration/RefreshWebcalJobRegistrar.php @@ -0,0 +1,83 @@ +<?php +declare(strict_types=1); +/** + * @copyright 2018 Georg Ehrke <oc.list@georgehrke.com> + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\DAV\Migration; + +use OCA\DAV\BackgroundJob\RefreshWebcalJob; +use OCP\BackgroundJob\IJobList; +use OCP\IDBConnection; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +class RefreshWebcalJobRegistrar implements IRepairStep { + + /** @var IDBConnection */ + private $connection; + + /** @var IJobList */ + private $jobList; + + /** + * FixBirthdayCalendarComponent constructor. + * + * @param IDBConnection $connection + * @param IJobList $jobList + */ + public function __construct(IDBConnection $connection, IJobList $jobList) { + $this->connection = $connection; + $this->jobList = $jobList; + } + + /** + * @inheritdoc + */ + public function getName() { + return 'Registering background jobs to update cache for webcal calendars'; + } + + /** + * @inheritdoc + */ + public function run(IOutput $output) { + $query = $this->connection->getQueryBuilder(); + $query->select(['principaluri', 'uri']) + ->from('calendarsubscriptions'); + $stmt = $query->execute(); + + $count = 0; + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { + $args = [ + 'principaluri' => $row['principaluri'], + 'uri' => $row['uri'], + ]; + + if (!$this->jobList->has(RefreshWebcalJob::class, $args)) { + $this->jobList->add(RefreshWebcalJob::class, $args); + $count++; + } + } + + $output->info("Added $count background jobs to update webcal calendars"); + } +} diff --git a/apps/dav/lib/Migration/Version1006Date20180628111625.php b/apps/dav/lib/Migration/Version1006Date20180628111625.php new file mode 100644 index 00000000000..8113b4c69bf --- /dev/null +++ b/apps/dav/lib/Migration/Version1006Date20180628111625.php @@ -0,0 +1,105 @@ +<?php +declare(strict_types=1); +/** + * @copyright 2018 Georg Ehrke <oc.list@georgehrke.com> + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\DAV\Migration; + +use Doctrine\DBAL\Types\Type; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; + +class Version1006Date20180628111625 extends SimpleMigrationStep { + + /** + * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + if ($schema->hasTable('calendarchanges')) { + $calendarChangesTable = $schema->getTable('calendarchanges'); + $calendarChangesTable->addColumn('calendartype', Type::INTEGER, [ + 'notnull' => true, + 'default' => 0, + ]); + + if ($calendarChangesTable->hasIndex('calendarid_synctoken')) { + $calendarChangesTable->dropIndex('calendarid_synctoken'); + } + $calendarChangesTable->addIndex(['calendarid', 'calendartype', 'synctoken'], 'calendarid_calendartype_synctoken'); + } + + if ($schema->hasTable('calendarobjects')) { + $calendarObjectsTable = $schema->getTable('calendarobjects'); + $calendarObjectsTable->addColumn('calendartype', Type::INTEGER, [ + 'notnull' => true, + 'default' => 0, + ]); + + if ($calendarObjectsTable->hasIndex('calobjects_index')) { + $calendarObjectsTable->dropIndex('calobjects_index'); + } + $calendarObjectsTable->addUniqueIndex(['calendarid', 'calendartype', 'uri'], 'calobjects_index'); + } + + if ($schema->hasTable('calendarobjects_props')) { + $calendarObjectsPropsTable = $schema->getTable('calendarobjects_props'); + $calendarObjectsPropsTable->addColumn('calendartype', Type::INTEGER, [ + 'notnull' => true, + 'default' => 0, + ]); + + + if ($calendarObjectsPropsTable->hasIndex('calendarobject_index')) { + $calendarObjectsPropsTable->dropIndex('calendarobject_index'); + } + if ($calendarObjectsPropsTable->hasIndex('calendarobject_name_index')) { + $calendarObjectsPropsTable->dropIndex('calendarobject_name_index'); + } + if ($calendarObjectsPropsTable->hasIndex('calendarobject_value_index')) { + $calendarObjectsPropsTable->dropIndex('calendarobject_value_index'); + } + + $calendarObjectsPropsTable->addIndex(['objectid', 'calendartype'], 'calendarobject_index'); + $calendarObjectsPropsTable->addIndex(['name', 'calendartype'], 'calendarobject_name_index'); + $calendarObjectsPropsTable->addIndex(['value', 'calendartype'], 'calendarobject_value_index'); + } + + if ($schema->hasTable('calendarsubscriptions')) { + $calendarSubscriptionsTable = $schema->getTable('calendarsubscriptions'); + $calendarSubscriptionsTable->addColumn('synctoken', 'integer', [ + 'notnull' => true, + 'default' => 1, + 'length' => 10, + 'unsigned' => true, + ]); + } + + return $schema; + } +} diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index c8d223b18b8..dac2fa102b3 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -149,7 +149,10 @@ class Server { if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); } + + $this->server->addPlugin(new CalDAV\WebcalCaching\Plugin($request)); $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |