@@ -67,7 +67,7 @@ |
||
| 67 | 67 | * @return array an array of events/journals/todos which are arrays of arrays of key-value-pairs |
| 68 | 68 | * @since 13.0.0 |
| 69 | 69 | */ |
| 70 | - public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null); |
|
| 70 | + public function search($pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null); |
|
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | 73 | * Check if calendars are available |
@@ -55,67 +55,67 @@ |
||
| 55 | 55 | */ |
| 56 | 56 | interface IManager { |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * This function is used to search and find objects within the user's calendars. |
|
| 60 | - * In case $pattern is empty all events/journals/todos will be returned. |
|
| 61 | - * |
|
| 62 | - * @param string $pattern which should match within the $searchProperties |
|
| 63 | - * @param array $searchProperties defines the properties within the query pattern should match |
|
| 64 | - * @param array $options - optional parameters: |
|
| 65 | - * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]] |
|
| 66 | - * @param integer|null $limit - limit number of search results |
|
| 67 | - * @param integer|null $offset - offset for paging of search results |
|
| 68 | - * @return array an array of events/journals/todos which are arrays of arrays of key-value-pairs |
|
| 69 | - * @since 13.0.0 |
|
| 70 | - */ |
|
| 71 | - public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null); |
|
| 58 | + /** |
|
| 59 | + * This function is used to search and find objects within the user's calendars. |
|
| 60 | + * In case $pattern is empty all events/journals/todos will be returned. |
|
| 61 | + * |
|
| 62 | + * @param string $pattern which should match within the $searchProperties |
|
| 63 | + * @param array $searchProperties defines the properties within the query pattern should match |
|
| 64 | + * @param array $options - optional parameters: |
|
| 65 | + * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]] |
|
| 66 | + * @param integer|null $limit - limit number of search results |
|
| 67 | + * @param integer|null $offset - offset for paging of search results |
|
| 68 | + * @return array an array of events/journals/todos which are arrays of arrays of key-value-pairs |
|
| 69 | + * @since 13.0.0 |
|
| 70 | + */ |
|
| 71 | + public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null); |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Check if calendars are available |
|
| 75 | - * |
|
| 76 | - * @return bool true if enabled, false if not |
|
| 77 | - * @since 13.0.0 |
|
| 78 | - */ |
|
| 79 | - public function isEnabled(); |
|
| 73 | + /** |
|
| 74 | + * Check if calendars are available |
|
| 75 | + * |
|
| 76 | + * @return bool true if enabled, false if not |
|
| 77 | + * @since 13.0.0 |
|
| 78 | + */ |
|
| 79 | + public function isEnabled(); |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Registers a calendar |
|
| 83 | - * |
|
| 84 | - * @param ICalendar $calendar |
|
| 85 | - * @return void |
|
| 86 | - * @since 13.0.0 |
|
| 87 | - */ |
|
| 88 | - public function registerCalendar(ICalendar $calendar); |
|
| 81 | + /** |
|
| 82 | + * Registers a calendar |
|
| 83 | + * |
|
| 84 | + * @param ICalendar $calendar |
|
| 85 | + * @return void |
|
| 86 | + * @since 13.0.0 |
|
| 87 | + */ |
|
| 88 | + public function registerCalendar(ICalendar $calendar); |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Unregisters a calendar |
|
| 92 | - * |
|
| 93 | - * @param ICalendar $calendar |
|
| 94 | - * @return void |
|
| 95 | - * @since 13.0.0 |
|
| 96 | - */ |
|
| 97 | - public function unregisterCalendar(ICalendar $calendar); |
|
| 90 | + /** |
|
| 91 | + * Unregisters a calendar |
|
| 92 | + * |
|
| 93 | + * @param ICalendar $calendar |
|
| 94 | + * @return void |
|
| 95 | + * @since 13.0.0 |
|
| 96 | + */ |
|
| 97 | + public function unregisterCalendar(ICalendar $calendar); |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 101 | - * calendars are actually requested |
|
| 102 | - * |
|
| 103 | - * @param \Closure $callable |
|
| 104 | - * @return void |
|
| 105 | - * @since 13.0.0 |
|
| 106 | - */ |
|
| 107 | - public function register(\Closure $callable); |
|
| 99 | + /** |
|
| 100 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 101 | + * calendars are actually requested |
|
| 102 | + * |
|
| 103 | + * @param \Closure $callable |
|
| 104 | + * @return void |
|
| 105 | + * @since 13.0.0 |
|
| 106 | + */ |
|
| 107 | + public function register(\Closure $callable); |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * @return ICalendar[] |
|
| 111 | - * @since 13.0.0 |
|
| 112 | - */ |
|
| 113 | - public function getCalendars(); |
|
| 109 | + /** |
|
| 110 | + * @return ICalendar[] |
|
| 111 | + * @since 13.0.0 |
|
| 112 | + */ |
|
| 113 | + public function getCalendars(); |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * removes all registered calendar instances |
|
| 117 | - * @return void |
|
| 118 | - * @since 13.0.0 |
|
| 119 | - */ |
|
| 120 | - public function clear(); |
|
| 115 | + /** |
|
| 116 | + * removes all registered calendar instances |
|
| 117 | + * @return void |
|
| 118 | + * @since 13.0.0 |
|
| 119 | + */ |
|
| 120 | + public function clear(); |
|
| 121 | 121 | } |
@@ -54,7 +54,7 @@ |
||
| 54 | 54 | * @return array an array of events/journals/todos which are arrays of key-value-pairs |
| 55 | 55 | * @since 13.0.0 |
| 56 | 56 | */ |
| 57 | - public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null); |
|
| 57 | + public function search($pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null); |
|
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * @return integer build up using \OCP\Constants |
@@ -31,41 +31,41 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | interface ICalendar { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @return string defining the technical unique key |
|
| 36 | - * @since 13.0.0 |
|
| 37 | - */ |
|
| 38 | - public function getKey(); |
|
| 34 | + /** |
|
| 35 | + * @return string defining the technical unique key |
|
| 36 | + * @since 13.0.0 |
|
| 37 | + */ |
|
| 38 | + public function getKey(); |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
| 42 | - * @return null|string |
|
| 43 | - * @since 13.0.0 |
|
| 44 | - */ |
|
| 45 | - public function getDisplayName(); |
|
| 40 | + /** |
|
| 41 | + * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
| 42 | + * @return null|string |
|
| 43 | + * @since 13.0.0 |
|
| 44 | + */ |
|
| 45 | + public function getDisplayName(); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Calendar color |
|
| 49 | - * @return null|string |
|
| 50 | - * @since 13.0.0 |
|
| 51 | - */ |
|
| 52 | - public function getDisplayColor(); |
|
| 47 | + /** |
|
| 48 | + * Calendar color |
|
| 49 | + * @return null|string |
|
| 50 | + * @since 13.0.0 |
|
| 51 | + */ |
|
| 52 | + public function getDisplayColor(); |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @param string $pattern which should match within the $searchProperties |
|
| 56 | - * @param array $searchProperties defines the properties within the query pattern should match |
|
| 57 | - * @param array $options - optional parameters: |
|
| 58 | - * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]] |
|
| 59 | - * @param integer|null $limit - limit number of search results |
|
| 60 | - * @param integer|null $offset - offset for paging of search results |
|
| 61 | - * @return array an array of events/journals/todos which are arrays of key-value-pairs |
|
| 62 | - * @since 13.0.0 |
|
| 63 | - */ |
|
| 64 | - public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null); |
|
| 54 | + /** |
|
| 55 | + * @param string $pattern which should match within the $searchProperties |
|
| 56 | + * @param array $searchProperties defines the properties within the query pattern should match |
|
| 57 | + * @param array $options - optional parameters: |
|
| 58 | + * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]] |
|
| 59 | + * @param integer|null $limit - limit number of search results |
|
| 60 | + * @param integer|null $offset - offset for paging of search results |
|
| 61 | + * @return array an array of events/journals/todos which are arrays of key-value-pairs |
|
| 62 | + * @since 13.0.0 |
|
| 63 | + */ |
|
| 64 | + public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null); |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @return integer build up using \OCP\Constants |
|
| 68 | - * @since 13.0.0 |
|
| 69 | - */ |
|
| 70 | - public function getPermissions(); |
|
| 66 | + /** |
|
| 67 | + * @return integer build up using \OCP\Constants |
|
| 68 | + * @since 13.0.0 |
|
| 69 | + */ |
|
| 70 | + public function getPermissions(); |
|
| 71 | 71 | } |
@@ -31,35 +31,35 @@ |
||
| 31 | 31 | $app->registerHooks(); |
| 32 | 32 | |
| 33 | 33 | \OC::$server->registerService('CardDAVSyncService', function() use ($app) { |
| 34 | - return $app->getSyncService(); |
|
| 34 | + return $app->getSyncService(); |
|
| 35 | 35 | }); |
| 36 | 36 | |
| 37 | 37 | $eventDispatcher = \OC::$server->getEventDispatcher(); |
| 38 | 38 | |
| 39 | 39 | $eventDispatcher->addListener('OCP\Federation\TrustedServerEvent::remove', |
| 40 | - function(GenericEvent $event) use ($app) { |
|
| 41 | - /** @var CardDavBackend $cardDavBackend */ |
|
| 42 | - $cardDavBackend = $app->getContainer()->query(CardDavBackend::class); |
|
| 43 | - $addressBookUri = $event->getSubject(); |
|
| 44 | - $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri); |
|
| 45 | - if (!is_null($addressBook)) { |
|
| 46 | - $cardDavBackend->deleteAddressBook($addressBook['id']); |
|
| 47 | - } |
|
| 48 | - } |
|
| 40 | + function(GenericEvent $event) use ($app) { |
|
| 41 | + /** @var CardDavBackend $cardDavBackend */ |
|
| 42 | + $cardDavBackend = $app->getContainer()->query(CardDavBackend::class); |
|
| 43 | + $addressBookUri = $event->getSubject(); |
|
| 44 | + $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri); |
|
| 45 | + if (!is_null($addressBook)) { |
|
| 46 | + $cardDavBackend->deleteAddressBook($addressBook['id']); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | ); |
| 50 | 50 | |
| 51 | 51 | $cm = \OC::$server->getContactsManager(); |
| 52 | 52 | $cm->register(function() use ($cm, $app) { |
| 53 | - $user = \OC::$server->getUserSession()->getUser(); |
|
| 54 | - if (!is_null($user)) { |
|
| 55 | - $app->setupContactsProvider($cm, $user->getUID()); |
|
| 56 | - } |
|
| 53 | + $user = \OC::$server->getUserSession()->getUser(); |
|
| 54 | + if (!is_null($user)) { |
|
| 55 | + $app->setupContactsProvider($cm, $user->getUID()); |
|
| 56 | + } |
|
| 57 | 57 | }); |
| 58 | 58 | |
| 59 | 59 | $calendarManager = \OC::$server->getCalendarManager(); |
| 60 | 60 | $calendarManager->register(function() use ($calendarManager, $app) { |
| 61 | - $user = \OC::$server->getUserSession()->getUser(); |
|
| 62 | - if ($user !== null) { |
|
| 63 | - $app->setupCalendarProvider($calendarManager, $user->getUID()); |
|
| 64 | - } |
|
| 61 | + $user = \OC::$server->getUserSession()->getUser(); |
|
| 62 | + if ($user !== null) { |
|
| 63 | + $app->setupCalendarProvider($calendarManager, $user->getUID()); |
|
| 64 | + } |
|
| 65 | 65 | }); |
@@ -43,165 +43,165 @@ |
||
| 43 | 43 | |
| 44 | 44 | class Application extends App { |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Application constructor. |
|
| 48 | - */ |
|
| 49 | - public function __construct() { |
|
| 50 | - parent::__construct('dav'); |
|
| 51 | - |
|
| 52 | - $container = $this->getContainer(); |
|
| 53 | - $server = $container->getServer(); |
|
| 54 | - |
|
| 55 | - $container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) { |
|
| 56 | - return new PhotoCache( |
|
| 57 | - $server->getAppDataDir('dav-photocache') |
|
| 58 | - ); |
|
| 59 | - }); |
|
| 60 | - |
|
| 61 | - /* |
|
| 46 | + /** |
|
| 47 | + * Application constructor. |
|
| 48 | + */ |
|
| 49 | + public function __construct() { |
|
| 50 | + parent::__construct('dav'); |
|
| 51 | + |
|
| 52 | + $container = $this->getContainer(); |
|
| 53 | + $server = $container->getServer(); |
|
| 54 | + |
|
| 55 | + $container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) { |
|
| 56 | + return new PhotoCache( |
|
| 57 | + $server->getAppDataDir('dav-photocache') |
|
| 58 | + ); |
|
| 59 | + }); |
|
| 60 | + |
|
| 61 | + /* |
|
| 62 | 62 | * Register capabilities |
| 63 | 63 | */ |
| 64 | - $container->registerCapability(Capabilities::class); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @param IContactsManager $contactsManager |
|
| 69 | - * @param string $userID |
|
| 70 | - */ |
|
| 71 | - public function setupContactsProvider(IContactsManager $contactsManager, $userID) { |
|
| 72 | - /** @var ContactsManager $cm */ |
|
| 73 | - $cm = $this->getContainer()->query(ContactsManager::class); |
|
| 74 | - $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
| 75 | - $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param ICalendarManager $calendarManager |
|
| 80 | - * @param string $userId |
|
| 81 | - */ |
|
| 82 | - public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) { |
|
| 83 | - $cm = $this->getContainer()->query(CalendarManager::class); |
|
| 84 | - $cm->setupCalendarProvider($calendarManager, $userId); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function registerHooks() { |
|
| 88 | - /** @var HookManager $hm */ |
|
| 89 | - $hm = $this->getContainer()->query(HookManager::class); |
|
| 90 | - $hm->setup(); |
|
| 91 | - |
|
| 92 | - $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
| 93 | - |
|
| 94 | - // first time login event setup |
|
| 95 | - $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
| 96 | - if ($event instanceof GenericEvent) { |
|
| 97 | - $hm->firstLogin($event->getSubject()); |
|
| 98 | - } |
|
| 99 | - }); |
|
| 100 | - |
|
| 101 | - // carddav/caldav sync event setup |
|
| 102 | - $listener = function($event) { |
|
| 103 | - if ($event instanceof GenericEvent) { |
|
| 104 | - /** @var BirthdayService $b */ |
|
| 105 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
| 106 | - $b->onCardChanged( |
|
| 107 | - $event->getArgument('addressBookId'), |
|
| 108 | - $event->getArgument('cardUri'), |
|
| 109 | - $event->getArgument('cardData') |
|
| 110 | - ); |
|
| 111 | - } |
|
| 112 | - }; |
|
| 113 | - |
|
| 114 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
| 115 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
| 116 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
| 117 | - if ($event instanceof GenericEvent) { |
|
| 118 | - /** @var BirthdayService $b */ |
|
| 119 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
| 120 | - $b->onCardDeleted( |
|
| 121 | - $event->getArgument('addressBookId'), |
|
| 122 | - $event->getArgument('cardUri') |
|
| 123 | - ); |
|
| 124 | - } |
|
| 125 | - }); |
|
| 126 | - |
|
| 127 | - $clearPhotoCache = function($event) { |
|
| 128 | - if ($event instanceof GenericEvent) { |
|
| 129 | - /** @var PhotoCache $p */ |
|
| 130 | - $p = $this->getContainer()->query(PhotoCache::class); |
|
| 131 | - $p->delete( |
|
| 132 | - $event->getArgument('addressBookId'), |
|
| 133 | - $event->getArgument('cardUri') |
|
| 134 | - ); |
|
| 135 | - } |
|
| 136 | - }; |
|
| 137 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); |
|
| 138 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); |
|
| 139 | - |
|
| 140 | - $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
| 141 | - $user = $event->getSubject(); |
|
| 142 | - $syncService = $this->getContainer()->query(SyncService::class); |
|
| 143 | - $syncService->updateUser($user); |
|
| 144 | - }); |
|
| 145 | - |
|
| 146 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
| 147 | - /** @var Backend $backend */ |
|
| 148 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 149 | - $backend->onCalendarAdd( |
|
| 150 | - $event->getArgument('calendarData') |
|
| 151 | - ); |
|
| 152 | - }); |
|
| 153 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
| 154 | - /** @var Backend $backend */ |
|
| 155 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 156 | - $backend->onCalendarUpdate( |
|
| 157 | - $event->getArgument('calendarData'), |
|
| 158 | - $event->getArgument('shares'), |
|
| 159 | - $event->getArgument('propertyMutations') |
|
| 160 | - ); |
|
| 161 | - }); |
|
| 162 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
| 163 | - /** @var Backend $backend */ |
|
| 164 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 165 | - $backend->onCalendarDelete( |
|
| 166 | - $event->getArgument('calendarData'), |
|
| 167 | - $event->getArgument('shares') |
|
| 168 | - ); |
|
| 169 | - }); |
|
| 170 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
| 171 | - /** @var Backend $backend */ |
|
| 172 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 173 | - $backend->onCalendarUpdateShares( |
|
| 174 | - $event->getArgument('calendarData'), |
|
| 175 | - $event->getArgument('shares'), |
|
| 176 | - $event->getArgument('add'), |
|
| 177 | - $event->getArgument('remove') |
|
| 178 | - ); |
|
| 179 | - }); |
|
| 180 | - |
|
| 181 | - $listener = function(GenericEvent $event, $eventName) { |
|
| 182 | - /** @var Backend $backend */ |
|
| 183 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 184 | - |
|
| 185 | - $subject = Event::SUBJECT_OBJECT_ADD; |
|
| 186 | - if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
| 187 | - $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
| 188 | - } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
| 189 | - $subject = Event::SUBJECT_OBJECT_DELETE; |
|
| 190 | - } |
|
| 191 | - $backend->onTouchCalendarObject( |
|
| 192 | - $subject, |
|
| 193 | - $event->getArgument('calendarData'), |
|
| 194 | - $event->getArgument('shares'), |
|
| 195 | - $event->getArgument('objectData') |
|
| 196 | - ); |
|
| 197 | - }; |
|
| 198 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
| 199 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
| 200 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - public function getSyncService() { |
|
| 204 | - return $this->getContainer()->query(SyncService::class); |
|
| 205 | - } |
|
| 64 | + $container->registerCapability(Capabilities::class); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @param IContactsManager $contactsManager |
|
| 69 | + * @param string $userID |
|
| 70 | + */ |
|
| 71 | + public function setupContactsProvider(IContactsManager $contactsManager, $userID) { |
|
| 72 | + /** @var ContactsManager $cm */ |
|
| 73 | + $cm = $this->getContainer()->query(ContactsManager::class); |
|
| 74 | + $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
| 75 | + $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param ICalendarManager $calendarManager |
|
| 80 | + * @param string $userId |
|
| 81 | + */ |
|
| 82 | + public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) { |
|
| 83 | + $cm = $this->getContainer()->query(CalendarManager::class); |
|
| 84 | + $cm->setupCalendarProvider($calendarManager, $userId); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function registerHooks() { |
|
| 88 | + /** @var HookManager $hm */ |
|
| 89 | + $hm = $this->getContainer()->query(HookManager::class); |
|
| 90 | + $hm->setup(); |
|
| 91 | + |
|
| 92 | + $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
| 93 | + |
|
| 94 | + // first time login event setup |
|
| 95 | + $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
| 96 | + if ($event instanceof GenericEvent) { |
|
| 97 | + $hm->firstLogin($event->getSubject()); |
|
| 98 | + } |
|
| 99 | + }); |
|
| 100 | + |
|
| 101 | + // carddav/caldav sync event setup |
|
| 102 | + $listener = function($event) { |
|
| 103 | + if ($event instanceof GenericEvent) { |
|
| 104 | + /** @var BirthdayService $b */ |
|
| 105 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
| 106 | + $b->onCardChanged( |
|
| 107 | + $event->getArgument('addressBookId'), |
|
| 108 | + $event->getArgument('cardUri'), |
|
| 109 | + $event->getArgument('cardData') |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | + }; |
|
| 113 | + |
|
| 114 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
| 115 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
| 116 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
| 117 | + if ($event instanceof GenericEvent) { |
|
| 118 | + /** @var BirthdayService $b */ |
|
| 119 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
| 120 | + $b->onCardDeleted( |
|
| 121 | + $event->getArgument('addressBookId'), |
|
| 122 | + $event->getArgument('cardUri') |
|
| 123 | + ); |
|
| 124 | + } |
|
| 125 | + }); |
|
| 126 | + |
|
| 127 | + $clearPhotoCache = function($event) { |
|
| 128 | + if ($event instanceof GenericEvent) { |
|
| 129 | + /** @var PhotoCache $p */ |
|
| 130 | + $p = $this->getContainer()->query(PhotoCache::class); |
|
| 131 | + $p->delete( |
|
| 132 | + $event->getArgument('addressBookId'), |
|
| 133 | + $event->getArgument('cardUri') |
|
| 134 | + ); |
|
| 135 | + } |
|
| 136 | + }; |
|
| 137 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); |
|
| 138 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); |
|
| 139 | + |
|
| 140 | + $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
| 141 | + $user = $event->getSubject(); |
|
| 142 | + $syncService = $this->getContainer()->query(SyncService::class); |
|
| 143 | + $syncService->updateUser($user); |
|
| 144 | + }); |
|
| 145 | + |
|
| 146 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
| 147 | + /** @var Backend $backend */ |
|
| 148 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 149 | + $backend->onCalendarAdd( |
|
| 150 | + $event->getArgument('calendarData') |
|
| 151 | + ); |
|
| 152 | + }); |
|
| 153 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
| 154 | + /** @var Backend $backend */ |
|
| 155 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 156 | + $backend->onCalendarUpdate( |
|
| 157 | + $event->getArgument('calendarData'), |
|
| 158 | + $event->getArgument('shares'), |
|
| 159 | + $event->getArgument('propertyMutations') |
|
| 160 | + ); |
|
| 161 | + }); |
|
| 162 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
| 163 | + /** @var Backend $backend */ |
|
| 164 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 165 | + $backend->onCalendarDelete( |
|
| 166 | + $event->getArgument('calendarData'), |
|
| 167 | + $event->getArgument('shares') |
|
| 168 | + ); |
|
| 169 | + }); |
|
| 170 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
| 171 | + /** @var Backend $backend */ |
|
| 172 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 173 | + $backend->onCalendarUpdateShares( |
|
| 174 | + $event->getArgument('calendarData'), |
|
| 175 | + $event->getArgument('shares'), |
|
| 176 | + $event->getArgument('add'), |
|
| 177 | + $event->getArgument('remove') |
|
| 178 | + ); |
|
| 179 | + }); |
|
| 180 | + |
|
| 181 | + $listener = function(GenericEvent $event, $eventName) { |
|
| 182 | + /** @var Backend $backend */ |
|
| 183 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 184 | + |
|
| 185 | + $subject = Event::SUBJECT_OBJECT_ADD; |
|
| 186 | + if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
| 187 | + $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
| 188 | + } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
| 189 | + $subject = Event::SUBJECT_OBJECT_DELETE; |
|
| 190 | + } |
|
| 191 | + $backend->onTouchCalendarObject( |
|
| 192 | + $subject, |
|
| 193 | + $event->getArgument('calendarData'), |
|
| 194 | + $event->getArgument('shares'), |
|
| 195 | + $event->getArgument('objectData') |
|
| 196 | + ); |
|
| 197 | + }; |
|
| 198 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
| 199 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
| 200 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + public function getSyncService() { |
|
| 204 | + return $this->getContainer()->query(SyncService::class); |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | 207 | } |
@@ -28,44 +28,44 @@ |
||
| 28 | 28 | |
| 29 | 29 | class CalendarManager { |
| 30 | 30 | |
| 31 | - /** @var CalDavBackend */ |
|
| 32 | - private $backend; |
|
| 31 | + /** @var CalDavBackend */ |
|
| 32 | + private $backend; |
|
| 33 | 33 | |
| 34 | - /** @var IL10N */ |
|
| 35 | - private $l10n; |
|
| 34 | + /** @var IL10N */ |
|
| 35 | + private $l10n; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * CalendarManager constructor. |
|
| 39 | - * |
|
| 40 | - * @param CalDavBackend $backend |
|
| 41 | - * @param IL10N $l10n |
|
| 42 | - */ |
|
| 43 | - public function __construct(CalDavBackend $backend, IL10N $l10n) { |
|
| 44 | - $this->backend = $backend; |
|
| 45 | - $this->l10n = $l10n; |
|
| 46 | - } |
|
| 37 | + /** |
|
| 38 | + * CalendarManager constructor. |
|
| 39 | + * |
|
| 40 | + * @param CalDavBackend $backend |
|
| 41 | + * @param IL10N $l10n |
|
| 42 | + */ |
|
| 43 | + public function __construct(CalDavBackend $backend, IL10N $l10n) { |
|
| 44 | + $this->backend = $backend; |
|
| 45 | + $this->l10n = $l10n; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param IManager $cm |
|
| 50 | - * @param string $userId |
|
| 51 | - */ |
|
| 52 | - public function setupCalendarProvider(IManager $cm, $userId) { |
|
| 53 | - $calendars = $this->backend->getCalendarsForUser("principals/users/$userId"); |
|
| 54 | - $this->register($cm, $calendars); |
|
| 55 | - } |
|
| 48 | + /** |
|
| 49 | + * @param IManager $cm |
|
| 50 | + * @param string $userId |
|
| 51 | + */ |
|
| 52 | + public function setupCalendarProvider(IManager $cm, $userId) { |
|
| 53 | + $calendars = $this->backend->getCalendarsForUser("principals/users/$userId"); |
|
| 54 | + $this->register($cm, $calendars); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @param IManager $cm |
|
| 59 | - * @param array $calendars |
|
| 60 | - */ |
|
| 61 | - private function register(IManager $cm, array $calendars) { |
|
| 62 | - foreach($calendars as $calendarInfo) { |
|
| 63 | - $calendar = new Calendar($this->backend, $calendarInfo, $this->l10n); |
|
| 64 | - $cm->registerCalendar(new CalendarImpl( |
|
| 65 | - $calendar, |
|
| 66 | - $calendarInfo, |
|
| 67 | - $this->backend |
|
| 68 | - )); |
|
| 69 | - } |
|
| 70 | - } |
|
| 57 | + /** |
|
| 58 | + * @param IManager $cm |
|
| 59 | + * @param array $calendars |
|
| 60 | + */ |
|
| 61 | + private function register(IManager $cm, array $calendars) { |
|
| 62 | + foreach($calendars as $calendarInfo) { |
|
| 63 | + $calendar = new Calendar($this->backend, $calendarInfo, $this->l10n); |
|
| 64 | + $cm->registerCalendar(new CalendarImpl( |
|
| 65 | + $calendar, |
|
| 66 | + $calendarInfo, |
|
| 67 | + $this->backend |
|
| 68 | + )); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -59,7 +59,7 @@ |
||
| 59 | 59 | * @param array $calendars |
| 60 | 60 | */ |
| 61 | 61 | private function register(IManager $cm, array $calendars) { |
| 62 | - foreach($calendars as $calendarInfo) { |
|
| 62 | + foreach ($calendars as $calendarInfo) { |
|
| 63 | 63 | $calendar = new Calendar($this->backend, $calendarInfo, $this->l10n); |
| 64 | 64 | $cm->registerCalendar(new CalendarImpl( |
| 65 | 65 | $calendar, |
@@ -27,114 +27,114 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Manager implements \OCP\Calendar\IManager { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var ICalendar[] holds all registered calendars |
|
| 32 | - */ |
|
| 33 | - private $calendars=[]; |
|
| 30 | + /** |
|
| 31 | + * @var ICalendar[] holds all registered calendars |
|
| 32 | + */ |
|
| 33 | + private $calendars=[]; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var \Closure[] to call to load/register calendar providers |
|
| 37 | - */ |
|
| 38 | - private $calendarLoaders=[]; |
|
| 35 | + /** |
|
| 36 | + * @var \Closure[] to call to load/register calendar providers |
|
| 37 | + */ |
|
| 38 | + private $calendarLoaders=[]; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * This function is used to search and find objects within the user's calendars. |
|
| 42 | - * In case $pattern is empty all events/journals/todos will be returned. |
|
| 43 | - * |
|
| 44 | - * @param string $pattern which should match within the $searchProperties |
|
| 45 | - * @param array $searchProperties defines the properties within the query pattern should match |
|
| 46 | - * @param array $options - optional parameters: |
|
| 47 | - * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]] |
|
| 48 | - * @param integer|null $limit - limit number of search results |
|
| 49 | - * @param integer|null $offset - offset for paging of search results |
|
| 50 | - * @return array an array of events/journals/todos which are arrays of arrays of key-value-pairs |
|
| 51 | - * @since 13.0.0 |
|
| 52 | - */ |
|
| 53 | - public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null) { |
|
| 54 | - $this->loadCalendars(); |
|
| 55 | - $result = []; |
|
| 56 | - foreach($this->calendars as $calendar) { |
|
| 57 | - $r = $calendar->search($pattern, $searchProperties, $options, $limit, $offset); |
|
| 58 | - foreach($r as $o) { |
|
| 59 | - $o['calendar-key'] = $calendar->getKey(); |
|
| 60 | - $result[] = $o; |
|
| 61 | - } |
|
| 62 | - } |
|
| 40 | + /** |
|
| 41 | + * This function is used to search and find objects within the user's calendars. |
|
| 42 | + * In case $pattern is empty all events/journals/todos will be returned. |
|
| 43 | + * |
|
| 44 | + * @param string $pattern which should match within the $searchProperties |
|
| 45 | + * @param array $searchProperties defines the properties within the query pattern should match |
|
| 46 | + * @param array $options - optional parameters: |
|
| 47 | + * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]] |
|
| 48 | + * @param integer|null $limit - limit number of search results |
|
| 49 | + * @param integer|null $offset - offset for paging of search results |
|
| 50 | + * @return array an array of events/journals/todos which are arrays of arrays of key-value-pairs |
|
| 51 | + * @since 13.0.0 |
|
| 52 | + */ |
|
| 53 | + public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null) { |
|
| 54 | + $this->loadCalendars(); |
|
| 55 | + $result = []; |
|
| 56 | + foreach($this->calendars as $calendar) { |
|
| 57 | + $r = $calendar->search($pattern, $searchProperties, $options, $limit, $offset); |
|
| 58 | + foreach($r as $o) { |
|
| 59 | + $o['calendar-key'] = $calendar->getKey(); |
|
| 60 | + $result[] = $o; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return $result; |
|
| 65 | - } |
|
| 64 | + return $result; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Check if calendars are available |
|
| 69 | - * |
|
| 70 | - * @return bool true if enabled, false if not |
|
| 71 | - * @since 13.0.0 |
|
| 72 | - */ |
|
| 73 | - public function isEnabled() { |
|
| 74 | - return !empty($this->calendars) || !empty($this->calendarLoaders); |
|
| 75 | - } |
|
| 67 | + /** |
|
| 68 | + * Check if calendars are available |
|
| 69 | + * |
|
| 70 | + * @return bool true if enabled, false if not |
|
| 71 | + * @since 13.0.0 |
|
| 72 | + */ |
|
| 73 | + public function isEnabled() { |
|
| 74 | + return !empty($this->calendars) || !empty($this->calendarLoaders); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Registers a calendar |
|
| 79 | - * |
|
| 80 | - * @param ICalendar $calendar |
|
| 81 | - * @return void |
|
| 82 | - * @since 13.0.0 |
|
| 83 | - */ |
|
| 84 | - public function registerCalendar(ICalendar $calendar) { |
|
| 85 | - $this->calendars[$calendar->getKey()] = $calendar; |
|
| 86 | - } |
|
| 77 | + /** |
|
| 78 | + * Registers a calendar |
|
| 79 | + * |
|
| 80 | + * @param ICalendar $calendar |
|
| 81 | + * @return void |
|
| 82 | + * @since 13.0.0 |
|
| 83 | + */ |
|
| 84 | + public function registerCalendar(ICalendar $calendar) { |
|
| 85 | + $this->calendars[$calendar->getKey()] = $calendar; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Unregisters a calendar |
|
| 90 | - * |
|
| 91 | - * @param ICalendar $calendar |
|
| 92 | - * @return void |
|
| 93 | - * @since 13.0.0 |
|
| 94 | - */ |
|
| 95 | - public function unregisterCalendar(ICalendar $calendar) { |
|
| 96 | - unset($this->calendars[$calendar->getKey()]); |
|
| 97 | - } |
|
| 88 | + /** |
|
| 89 | + * Unregisters a calendar |
|
| 90 | + * |
|
| 91 | + * @param ICalendar $calendar |
|
| 92 | + * @return void |
|
| 93 | + * @since 13.0.0 |
|
| 94 | + */ |
|
| 95 | + public function unregisterCalendar(ICalendar $calendar) { |
|
| 96 | + unset($this->calendars[$calendar->getKey()]); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 101 | - * calendars are actually requested |
|
| 102 | - * |
|
| 103 | - * @param \Closure $callable |
|
| 104 | - * @return void |
|
| 105 | - * @since 13.0.0 |
|
| 106 | - */ |
|
| 107 | - public function register(\Closure $callable) { |
|
| 108 | - $this->calendarLoaders[] = $callable; |
|
| 109 | - } |
|
| 99 | + /** |
|
| 100 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 101 | + * calendars are actually requested |
|
| 102 | + * |
|
| 103 | + * @param \Closure $callable |
|
| 104 | + * @return void |
|
| 105 | + * @since 13.0.0 |
|
| 106 | + */ |
|
| 107 | + public function register(\Closure $callable) { |
|
| 108 | + $this->calendarLoaders[] = $callable; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * @return ICalendar[] |
|
| 113 | - * @since 13.0.0 |
|
| 114 | - */ |
|
| 115 | - public function getCalendars() { |
|
| 116 | - $this->loadCalendars(); |
|
| 111 | + /** |
|
| 112 | + * @return ICalendar[] |
|
| 113 | + * @since 13.0.0 |
|
| 114 | + */ |
|
| 115 | + public function getCalendars() { |
|
| 116 | + $this->loadCalendars(); |
|
| 117 | 117 | |
| 118 | - return array_values($this->calendars); |
|
| 119 | - } |
|
| 118 | + return array_values($this->calendars); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * removes all registered calendar instances |
|
| 123 | - * @return void |
|
| 124 | - * @since 13.0.0 |
|
| 125 | - */ |
|
| 126 | - public function clear() { |
|
| 127 | - $this->calendars = []; |
|
| 128 | - $this->calendarLoaders = []; |
|
| 129 | - } |
|
| 121 | + /** |
|
| 122 | + * removes all registered calendar instances |
|
| 123 | + * @return void |
|
| 124 | + * @since 13.0.0 |
|
| 125 | + */ |
|
| 126 | + public function clear() { |
|
| 127 | + $this->calendars = []; |
|
| 128 | + $this->calendarLoaders = []; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * loads all calendars |
|
| 133 | - */ |
|
| 134 | - private function loadCalendars() { |
|
| 135 | - foreach($this->calendarLoaders as $callable) { |
|
| 136 | - $callable($this); |
|
| 137 | - } |
|
| 138 | - $this->calendarLoaders = []; |
|
| 139 | - } |
|
| 131 | + /** |
|
| 132 | + * loads all calendars |
|
| 133 | + */ |
|
| 134 | + private function loadCalendars() { |
|
| 135 | + foreach($this->calendarLoaders as $callable) { |
|
| 136 | + $callable($this); |
|
| 137 | + } |
|
| 138 | + $this->calendarLoaders = []; |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | /** |
| 31 | 31 | * @var ICalendar[] holds all registered calendars |
| 32 | 32 | */ |
| 33 | - private $calendars=[]; |
|
| 33 | + private $calendars = []; |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * @var \Closure[] to call to load/register calendar providers |
| 37 | 37 | */ |
| 38 | - private $calendarLoaders=[]; |
|
| 38 | + private $calendarLoaders = []; |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * This function is used to search and find objects within the user's calendars. |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | * @return array an array of events/journals/todos which are arrays of arrays of key-value-pairs |
| 51 | 51 | * @since 13.0.0 |
| 52 | 52 | */ |
| 53 | - public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null) { |
|
| 53 | + public function search($pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null) { |
|
| 54 | 54 | $this->loadCalendars(); |
| 55 | 55 | $result = []; |
| 56 | - foreach($this->calendars as $calendar) { |
|
| 56 | + foreach ($this->calendars as $calendar) { |
|
| 57 | 57 | $r = $calendar->search($pattern, $searchProperties, $options, $limit, $offset); |
| 58 | - foreach($r as $o) { |
|
| 58 | + foreach ($r as $o) { |
|
| 59 | 59 | $o['calendar-key'] = $calendar->getKey(); |
| 60 | 60 | $result[] = $o; |
| 61 | 61 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * loads all calendars |
| 133 | 133 | */ |
| 134 | 134 | private function loadCalendars() { |
| 135 | - foreach($this->calendarLoaders as $callable) { |
|
| 135 | + foreach ($this->calendarLoaders as $callable) { |
|
| 136 | 136 | $callable($this); |
| 137 | 137 | } |
| 138 | 138 | $this->calendarLoaders = []; |
@@ -57,488 +57,488 @@ |
||
| 57 | 57 | */ |
| 58 | 58 | interface IServerContainer extends IContainer { |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * The calendar manager will act as a broker between consumers for calendar information and |
|
| 62 | - * providers which actual deliver the calendar information. |
|
| 63 | - * |
|
| 64 | - * @return \OCP\Calendar\IManager |
|
| 65 | - * @since 13.0.0 |
|
| 66 | - */ |
|
| 67 | - public function getCalendarManager(); |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The contacts manager will act as a broker between consumers for contacts information and |
|
| 71 | - * providers which actual deliver the contact information. |
|
| 72 | - * |
|
| 73 | - * @return \OCP\Contacts\IManager |
|
| 74 | - * @since 6.0.0 |
|
| 75 | - */ |
|
| 76 | - public function getContactsManager(); |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * The current request object holding all information about the request currently being processed |
|
| 80 | - * is returned from this method. |
|
| 81 | - * In case the current execution was not initiated by a web request null is returned |
|
| 82 | - * |
|
| 83 | - * @return \OCP\IRequest |
|
| 84 | - * @since 6.0.0 |
|
| 85 | - */ |
|
| 86 | - public function getRequest(); |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Returns the preview manager which can create preview images for a given file |
|
| 90 | - * |
|
| 91 | - * @return \OCP\IPreview |
|
| 92 | - * @since 6.0.0 |
|
| 93 | - */ |
|
| 94 | - public function getPreviewManager(); |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Returns the tag manager which can get and set tags for different object types |
|
| 98 | - * |
|
| 99 | - * @see \OCP\ITagManager::load() |
|
| 100 | - * @return \OCP\ITagManager |
|
| 101 | - * @since 6.0.0 |
|
| 102 | - */ |
|
| 103 | - public function getTagManager(); |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Returns the root folder of ownCloud's data directory |
|
| 107 | - * |
|
| 108 | - * @return \OCP\Files\IRootFolder |
|
| 109 | - * @since 6.0.0 - between 6.0.0 and 8.0.0 this returned \OCP\Files\Folder |
|
| 110 | - */ |
|
| 111 | - public function getRootFolder(); |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Returns a view to ownCloud's files folder |
|
| 115 | - * |
|
| 116 | - * @param string $userId user ID |
|
| 117 | - * @return \OCP\Files\Folder |
|
| 118 | - * @since 6.0.0 - parameter $userId was added in 8.0.0 |
|
| 119 | - * @see getUserFolder in \OCP\Files\IRootFolder |
|
| 120 | - */ |
|
| 121 | - public function getUserFolder($userId = null); |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Returns an app-specific view in ownClouds data directory |
|
| 125 | - * |
|
| 126 | - * @return \OCP\Files\Folder |
|
| 127 | - * @since 6.0.0 |
|
| 128 | - * @deprecated since 9.2.0 use IAppData |
|
| 129 | - */ |
|
| 130 | - public function getAppFolder(); |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Returns a user manager |
|
| 134 | - * |
|
| 135 | - * @return \OCP\IUserManager |
|
| 136 | - * @since 8.0.0 |
|
| 137 | - */ |
|
| 138 | - public function getUserManager(); |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns a group manager |
|
| 142 | - * |
|
| 143 | - * @return \OCP\IGroupManager |
|
| 144 | - * @since 8.0.0 |
|
| 145 | - */ |
|
| 146 | - public function getGroupManager(); |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Returns the user session |
|
| 150 | - * |
|
| 151 | - * @return \OCP\IUserSession |
|
| 152 | - * @since 6.0.0 |
|
| 153 | - */ |
|
| 154 | - public function getUserSession(); |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Returns the navigation manager |
|
| 158 | - * |
|
| 159 | - * @return \OCP\INavigationManager |
|
| 160 | - * @since 6.0.0 |
|
| 161 | - */ |
|
| 162 | - public function getNavigationManager(); |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Returns the config manager |
|
| 166 | - * |
|
| 167 | - * @return \OCP\IConfig |
|
| 168 | - * @since 6.0.0 |
|
| 169 | - */ |
|
| 170 | - public function getConfig(); |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Returns a Crypto instance |
|
| 174 | - * |
|
| 175 | - * @return \OCP\Security\ICrypto |
|
| 176 | - * @since 8.0.0 |
|
| 177 | - */ |
|
| 178 | - public function getCrypto(); |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Returns a Hasher instance |
|
| 182 | - * |
|
| 183 | - * @return \OCP\Security\IHasher |
|
| 184 | - * @since 8.0.0 |
|
| 185 | - */ |
|
| 186 | - public function getHasher(); |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Returns a SecureRandom instance |
|
| 190 | - * |
|
| 191 | - * @return \OCP\Security\ISecureRandom |
|
| 192 | - * @since 8.1.0 |
|
| 193 | - */ |
|
| 194 | - public function getSecureRandom(); |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Returns a CredentialsManager instance |
|
| 198 | - * |
|
| 199 | - * @return \OCP\Security\ICredentialsManager |
|
| 200 | - * @since 9.0.0 |
|
| 201 | - */ |
|
| 202 | - public function getCredentialsManager(); |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Returns the app config manager |
|
| 206 | - * |
|
| 207 | - * @return \OCP\IAppConfig |
|
| 208 | - * @since 7.0.0 |
|
| 209 | - */ |
|
| 210 | - public function getAppConfig(); |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * @return \OCP\L10N\IFactory |
|
| 214 | - * @since 8.2.0 |
|
| 215 | - */ |
|
| 216 | - public function getL10NFactory(); |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * get an L10N instance |
|
| 220 | - * @param string $app appid |
|
| 221 | - * @param string $lang |
|
| 222 | - * @return \OCP\IL10N |
|
| 223 | - * @since 6.0.0 - parameter $lang was added in 8.0.0 |
|
| 224 | - */ |
|
| 225 | - public function getL10N($app, $lang = null); |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * @return \OC\Encryption\Manager |
|
| 229 | - * @since 8.1.0 |
|
| 230 | - */ |
|
| 231 | - public function getEncryptionManager(); |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @return \OC\Encryption\File |
|
| 235 | - * @since 8.1.0 |
|
| 236 | - */ |
|
| 237 | - public function getEncryptionFilesHelper(); |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * @return \OCP\Encryption\Keys\IStorage |
|
| 241 | - * @since 8.1.0 |
|
| 242 | - */ |
|
| 243 | - public function getEncryptionKeyStorage(); |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Returns the URL generator |
|
| 247 | - * |
|
| 248 | - * @return \OCP\IURLGenerator |
|
| 249 | - * @since 6.0.0 |
|
| 250 | - */ |
|
| 251 | - public function getURLGenerator(); |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Returns the Helper |
|
| 255 | - * |
|
| 256 | - * @return \OCP\IHelper |
|
| 257 | - * @since 6.0.0 |
|
| 258 | - */ |
|
| 259 | - public function getHelper(); |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Returns an ICache instance |
|
| 263 | - * |
|
| 264 | - * @return \OCP\ICache |
|
| 265 | - * @since 6.0.0 |
|
| 266 | - */ |
|
| 267 | - public function getCache(); |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Returns an \OCP\CacheFactory instance |
|
| 271 | - * |
|
| 272 | - * @return \OCP\ICacheFactory |
|
| 273 | - * @since 7.0.0 |
|
| 274 | - */ |
|
| 275 | - public function getMemCacheFactory(); |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Returns the current session |
|
| 279 | - * |
|
| 280 | - * @return \OCP\ISession |
|
| 281 | - * @since 6.0.0 |
|
| 282 | - */ |
|
| 283 | - public function getSession(); |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Returns the activity manager |
|
| 287 | - * |
|
| 288 | - * @return \OCP\Activity\IManager |
|
| 289 | - * @since 6.0.0 |
|
| 290 | - */ |
|
| 291 | - public function getActivityManager(); |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Returns the current session |
|
| 295 | - * |
|
| 296 | - * @return \OCP\IDBConnection |
|
| 297 | - * @since 6.0.0 |
|
| 298 | - */ |
|
| 299 | - public function getDatabaseConnection(); |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Returns an avatar manager, used for avatar functionality |
|
| 303 | - * |
|
| 304 | - * @return \OCP\IAvatarManager |
|
| 305 | - * @since 6.0.0 |
|
| 306 | - */ |
|
| 307 | - public function getAvatarManager(); |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Returns an job list for controlling background jobs |
|
| 311 | - * |
|
| 312 | - * @return \OCP\BackgroundJob\IJobList |
|
| 313 | - * @since 7.0.0 |
|
| 314 | - */ |
|
| 315 | - public function getJobList(); |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Returns a logger instance |
|
| 319 | - * |
|
| 320 | - * @return \OCP\ILogger |
|
| 321 | - * @since 8.0.0 |
|
| 322 | - */ |
|
| 323 | - public function getLogger(); |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Returns a router for generating and matching urls |
|
| 327 | - * |
|
| 328 | - * @return \OCP\Route\IRouter |
|
| 329 | - * @since 7.0.0 |
|
| 330 | - */ |
|
| 331 | - public function getRouter(); |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * Returns a search instance |
|
| 335 | - * |
|
| 336 | - * @return \OCP\ISearch |
|
| 337 | - * @since 7.0.0 |
|
| 338 | - */ |
|
| 339 | - public function getSearch(); |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Get the certificate manager for the user |
|
| 343 | - * |
|
| 344 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 345 | - * @return \OCP\ICertificateManager | null if $userId is null and no user is logged in |
|
| 346 | - * @since 8.0.0 |
|
| 347 | - */ |
|
| 348 | - public function getCertificateManager($userId = null); |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * Create a new event source |
|
| 352 | - * |
|
| 353 | - * @return \OCP\IEventSource |
|
| 354 | - * @since 8.0.0 |
|
| 355 | - */ |
|
| 356 | - public function createEventSource(); |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * Returns an instance of the HTTP helper class |
|
| 360 | - * @return \OC\HTTPHelper |
|
| 361 | - * @deprecated 8.1.0 Use \OCP\Http\Client\IClientService |
|
| 362 | - * @since 8.0.0 |
|
| 363 | - */ |
|
| 364 | - public function getHTTPHelper(); |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Returns an instance of the HTTP client service |
|
| 368 | - * |
|
| 369 | - * @return \OCP\Http\Client\IClientService |
|
| 370 | - * @since 8.1.0 |
|
| 371 | - */ |
|
| 372 | - public function getHTTPClientService(); |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Get the active event logger |
|
| 376 | - * |
|
| 377 | - * @return \OCP\Diagnostics\IEventLogger |
|
| 378 | - * @since 8.0.0 |
|
| 379 | - */ |
|
| 380 | - public function getEventLogger(); |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Get the active query logger |
|
| 384 | - * |
|
| 385 | - * The returned logger only logs data when debug mode is enabled |
|
| 386 | - * |
|
| 387 | - * @return \OCP\Diagnostics\IQueryLogger |
|
| 388 | - * @since 8.0.0 |
|
| 389 | - */ |
|
| 390 | - public function getQueryLogger(); |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Get the manager for temporary files and folders |
|
| 394 | - * |
|
| 395 | - * @return \OCP\ITempManager |
|
| 396 | - * @since 8.0.0 |
|
| 397 | - */ |
|
| 398 | - public function getTempManager(); |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * Get the app manager |
|
| 402 | - * |
|
| 403 | - * @return \OCP\App\IAppManager |
|
| 404 | - * @since 8.0.0 |
|
| 405 | - */ |
|
| 406 | - public function getAppManager(); |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * Get the webroot |
|
| 410 | - * |
|
| 411 | - * @return string |
|
| 412 | - * @since 8.0.0 |
|
| 413 | - */ |
|
| 414 | - public function getWebRoot(); |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
| 418 | - * @since 8.0.0 |
|
| 419 | - */ |
|
| 420 | - public function getMountProviderCollection(); |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Get the IniWrapper |
|
| 424 | - * |
|
| 425 | - * @return \bantu\IniGetWrapper\IniGetWrapper |
|
| 426 | - * @since 8.0.0 |
|
| 427 | - */ |
|
| 428 | - public function getIniWrapper(); |
|
| 429 | - /** |
|
| 430 | - * @return \OCP\Command\IBus |
|
| 431 | - * @since 8.1.0 |
|
| 432 | - */ |
|
| 433 | - public function getCommandBus(); |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Creates a new mailer |
|
| 437 | - * |
|
| 438 | - * @return \OCP\Mail\IMailer |
|
| 439 | - * @since 8.1.0 |
|
| 440 | - */ |
|
| 441 | - public function getMailer(); |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Get the locking provider |
|
| 445 | - * |
|
| 446 | - * @return \OCP\Lock\ILockingProvider |
|
| 447 | - * @since 8.1.0 |
|
| 448 | - */ |
|
| 449 | - public function getLockingProvider(); |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @return \OCP\Files\Mount\IMountManager |
|
| 453 | - * @since 8.2.0 |
|
| 454 | - */ |
|
| 455 | - public function getMountManager(); |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Get the MimeTypeDetector |
|
| 459 | - * |
|
| 460 | - * @return \OCP\Files\IMimeTypeDetector |
|
| 461 | - * @since 8.2.0 |
|
| 462 | - */ |
|
| 463 | - public function getMimeTypeDetector(); |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Get the MimeTypeLoader |
|
| 467 | - * |
|
| 468 | - * @return \OCP\Files\IMimeTypeLoader |
|
| 469 | - * @since 8.2.0 |
|
| 470 | - */ |
|
| 471 | - public function getMimeTypeLoader(); |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * Get the EventDispatcher |
|
| 475 | - * |
|
| 476 | - * @return EventDispatcherInterface |
|
| 477 | - * @since 8.2.0 |
|
| 478 | - */ |
|
| 479 | - public function getEventDispatcher(); |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * Get the Notification Manager |
|
| 483 | - * |
|
| 484 | - * @return \OCP\Notification\IManager |
|
| 485 | - * @since 9.0.0 |
|
| 486 | - */ |
|
| 487 | - public function getNotificationManager(); |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * @return \OCP\Comments\ICommentsManager |
|
| 491 | - * @since 9.0.0 |
|
| 492 | - */ |
|
| 493 | - public function getCommentsManager(); |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Returns the system-tag manager |
|
| 497 | - * |
|
| 498 | - * @return \OCP\SystemTag\ISystemTagManager |
|
| 499 | - * |
|
| 500 | - * @since 9.0.0 |
|
| 501 | - */ |
|
| 502 | - public function getSystemTagManager(); |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * Returns the system-tag object mapper |
|
| 506 | - * |
|
| 507 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
| 508 | - * |
|
| 509 | - * @since 9.0.0 |
|
| 510 | - */ |
|
| 511 | - public function getSystemTagObjectMapper(); |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Returns the share manager |
|
| 515 | - * |
|
| 516 | - * @return \OCP\Share\IManager |
|
| 517 | - * @since 9.0.0 |
|
| 518 | - */ |
|
| 519 | - public function getShareManager(); |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * @return IContentSecurityPolicyManager |
|
| 523 | - * @since 9.0.0 |
|
| 524 | - */ |
|
| 525 | - public function getContentSecurityPolicyManager(); |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * @return \OCP\IDateTimeZone |
|
| 529 | - * @since 8.0.0 |
|
| 530 | - */ |
|
| 531 | - public function getDateTimeZone(); |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * @return \OCP\IDateTimeFormatter |
|
| 535 | - * @since 8.0.0 |
|
| 536 | - */ |
|
| 537 | - public function getDateTimeFormatter(); |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * @return \OCP\Federation\ICloudIdManager |
|
| 541 | - * @since 12.0.0 |
|
| 542 | - */ |
|
| 543 | - public function getCloudIdManager(); |
|
| 60 | + /** |
|
| 61 | + * The calendar manager will act as a broker between consumers for calendar information and |
|
| 62 | + * providers which actual deliver the calendar information. |
|
| 63 | + * |
|
| 64 | + * @return \OCP\Calendar\IManager |
|
| 65 | + * @since 13.0.0 |
|
| 66 | + */ |
|
| 67 | + public function getCalendarManager(); |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The contacts manager will act as a broker between consumers for contacts information and |
|
| 71 | + * providers which actual deliver the contact information. |
|
| 72 | + * |
|
| 73 | + * @return \OCP\Contacts\IManager |
|
| 74 | + * @since 6.0.0 |
|
| 75 | + */ |
|
| 76 | + public function getContactsManager(); |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * The current request object holding all information about the request currently being processed |
|
| 80 | + * is returned from this method. |
|
| 81 | + * In case the current execution was not initiated by a web request null is returned |
|
| 82 | + * |
|
| 83 | + * @return \OCP\IRequest |
|
| 84 | + * @since 6.0.0 |
|
| 85 | + */ |
|
| 86 | + public function getRequest(); |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Returns the preview manager which can create preview images for a given file |
|
| 90 | + * |
|
| 91 | + * @return \OCP\IPreview |
|
| 92 | + * @since 6.0.0 |
|
| 93 | + */ |
|
| 94 | + public function getPreviewManager(); |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Returns the tag manager which can get and set tags for different object types |
|
| 98 | + * |
|
| 99 | + * @see \OCP\ITagManager::load() |
|
| 100 | + * @return \OCP\ITagManager |
|
| 101 | + * @since 6.0.0 |
|
| 102 | + */ |
|
| 103 | + public function getTagManager(); |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Returns the root folder of ownCloud's data directory |
|
| 107 | + * |
|
| 108 | + * @return \OCP\Files\IRootFolder |
|
| 109 | + * @since 6.0.0 - between 6.0.0 and 8.0.0 this returned \OCP\Files\Folder |
|
| 110 | + */ |
|
| 111 | + public function getRootFolder(); |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Returns a view to ownCloud's files folder |
|
| 115 | + * |
|
| 116 | + * @param string $userId user ID |
|
| 117 | + * @return \OCP\Files\Folder |
|
| 118 | + * @since 6.0.0 - parameter $userId was added in 8.0.0 |
|
| 119 | + * @see getUserFolder in \OCP\Files\IRootFolder |
|
| 120 | + */ |
|
| 121 | + public function getUserFolder($userId = null); |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Returns an app-specific view in ownClouds data directory |
|
| 125 | + * |
|
| 126 | + * @return \OCP\Files\Folder |
|
| 127 | + * @since 6.0.0 |
|
| 128 | + * @deprecated since 9.2.0 use IAppData |
|
| 129 | + */ |
|
| 130 | + public function getAppFolder(); |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Returns a user manager |
|
| 134 | + * |
|
| 135 | + * @return \OCP\IUserManager |
|
| 136 | + * @since 8.0.0 |
|
| 137 | + */ |
|
| 138 | + public function getUserManager(); |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns a group manager |
|
| 142 | + * |
|
| 143 | + * @return \OCP\IGroupManager |
|
| 144 | + * @since 8.0.0 |
|
| 145 | + */ |
|
| 146 | + public function getGroupManager(); |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Returns the user session |
|
| 150 | + * |
|
| 151 | + * @return \OCP\IUserSession |
|
| 152 | + * @since 6.0.0 |
|
| 153 | + */ |
|
| 154 | + public function getUserSession(); |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Returns the navigation manager |
|
| 158 | + * |
|
| 159 | + * @return \OCP\INavigationManager |
|
| 160 | + * @since 6.0.0 |
|
| 161 | + */ |
|
| 162 | + public function getNavigationManager(); |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Returns the config manager |
|
| 166 | + * |
|
| 167 | + * @return \OCP\IConfig |
|
| 168 | + * @since 6.0.0 |
|
| 169 | + */ |
|
| 170 | + public function getConfig(); |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Returns a Crypto instance |
|
| 174 | + * |
|
| 175 | + * @return \OCP\Security\ICrypto |
|
| 176 | + * @since 8.0.0 |
|
| 177 | + */ |
|
| 178 | + public function getCrypto(); |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Returns a Hasher instance |
|
| 182 | + * |
|
| 183 | + * @return \OCP\Security\IHasher |
|
| 184 | + * @since 8.0.0 |
|
| 185 | + */ |
|
| 186 | + public function getHasher(); |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Returns a SecureRandom instance |
|
| 190 | + * |
|
| 191 | + * @return \OCP\Security\ISecureRandom |
|
| 192 | + * @since 8.1.0 |
|
| 193 | + */ |
|
| 194 | + public function getSecureRandom(); |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Returns a CredentialsManager instance |
|
| 198 | + * |
|
| 199 | + * @return \OCP\Security\ICredentialsManager |
|
| 200 | + * @since 9.0.0 |
|
| 201 | + */ |
|
| 202 | + public function getCredentialsManager(); |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Returns the app config manager |
|
| 206 | + * |
|
| 207 | + * @return \OCP\IAppConfig |
|
| 208 | + * @since 7.0.0 |
|
| 209 | + */ |
|
| 210 | + public function getAppConfig(); |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * @return \OCP\L10N\IFactory |
|
| 214 | + * @since 8.2.0 |
|
| 215 | + */ |
|
| 216 | + public function getL10NFactory(); |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * get an L10N instance |
|
| 220 | + * @param string $app appid |
|
| 221 | + * @param string $lang |
|
| 222 | + * @return \OCP\IL10N |
|
| 223 | + * @since 6.0.0 - parameter $lang was added in 8.0.0 |
|
| 224 | + */ |
|
| 225 | + public function getL10N($app, $lang = null); |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * @return \OC\Encryption\Manager |
|
| 229 | + * @since 8.1.0 |
|
| 230 | + */ |
|
| 231 | + public function getEncryptionManager(); |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @return \OC\Encryption\File |
|
| 235 | + * @since 8.1.0 |
|
| 236 | + */ |
|
| 237 | + public function getEncryptionFilesHelper(); |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * @return \OCP\Encryption\Keys\IStorage |
|
| 241 | + * @since 8.1.0 |
|
| 242 | + */ |
|
| 243 | + public function getEncryptionKeyStorage(); |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Returns the URL generator |
|
| 247 | + * |
|
| 248 | + * @return \OCP\IURLGenerator |
|
| 249 | + * @since 6.0.0 |
|
| 250 | + */ |
|
| 251 | + public function getURLGenerator(); |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Returns the Helper |
|
| 255 | + * |
|
| 256 | + * @return \OCP\IHelper |
|
| 257 | + * @since 6.0.0 |
|
| 258 | + */ |
|
| 259 | + public function getHelper(); |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Returns an ICache instance |
|
| 263 | + * |
|
| 264 | + * @return \OCP\ICache |
|
| 265 | + * @since 6.0.0 |
|
| 266 | + */ |
|
| 267 | + public function getCache(); |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Returns an \OCP\CacheFactory instance |
|
| 271 | + * |
|
| 272 | + * @return \OCP\ICacheFactory |
|
| 273 | + * @since 7.0.0 |
|
| 274 | + */ |
|
| 275 | + public function getMemCacheFactory(); |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Returns the current session |
|
| 279 | + * |
|
| 280 | + * @return \OCP\ISession |
|
| 281 | + * @since 6.0.0 |
|
| 282 | + */ |
|
| 283 | + public function getSession(); |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Returns the activity manager |
|
| 287 | + * |
|
| 288 | + * @return \OCP\Activity\IManager |
|
| 289 | + * @since 6.0.0 |
|
| 290 | + */ |
|
| 291 | + public function getActivityManager(); |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Returns the current session |
|
| 295 | + * |
|
| 296 | + * @return \OCP\IDBConnection |
|
| 297 | + * @since 6.0.0 |
|
| 298 | + */ |
|
| 299 | + public function getDatabaseConnection(); |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Returns an avatar manager, used for avatar functionality |
|
| 303 | + * |
|
| 304 | + * @return \OCP\IAvatarManager |
|
| 305 | + * @since 6.0.0 |
|
| 306 | + */ |
|
| 307 | + public function getAvatarManager(); |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Returns an job list for controlling background jobs |
|
| 311 | + * |
|
| 312 | + * @return \OCP\BackgroundJob\IJobList |
|
| 313 | + * @since 7.0.0 |
|
| 314 | + */ |
|
| 315 | + public function getJobList(); |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Returns a logger instance |
|
| 319 | + * |
|
| 320 | + * @return \OCP\ILogger |
|
| 321 | + * @since 8.0.0 |
|
| 322 | + */ |
|
| 323 | + public function getLogger(); |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Returns a router for generating and matching urls |
|
| 327 | + * |
|
| 328 | + * @return \OCP\Route\IRouter |
|
| 329 | + * @since 7.0.0 |
|
| 330 | + */ |
|
| 331 | + public function getRouter(); |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * Returns a search instance |
|
| 335 | + * |
|
| 336 | + * @return \OCP\ISearch |
|
| 337 | + * @since 7.0.0 |
|
| 338 | + */ |
|
| 339 | + public function getSearch(); |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Get the certificate manager for the user |
|
| 343 | + * |
|
| 344 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 345 | + * @return \OCP\ICertificateManager | null if $userId is null and no user is logged in |
|
| 346 | + * @since 8.0.0 |
|
| 347 | + */ |
|
| 348 | + public function getCertificateManager($userId = null); |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * Create a new event source |
|
| 352 | + * |
|
| 353 | + * @return \OCP\IEventSource |
|
| 354 | + * @since 8.0.0 |
|
| 355 | + */ |
|
| 356 | + public function createEventSource(); |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * Returns an instance of the HTTP helper class |
|
| 360 | + * @return \OC\HTTPHelper |
|
| 361 | + * @deprecated 8.1.0 Use \OCP\Http\Client\IClientService |
|
| 362 | + * @since 8.0.0 |
|
| 363 | + */ |
|
| 364 | + public function getHTTPHelper(); |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Returns an instance of the HTTP client service |
|
| 368 | + * |
|
| 369 | + * @return \OCP\Http\Client\IClientService |
|
| 370 | + * @since 8.1.0 |
|
| 371 | + */ |
|
| 372 | + public function getHTTPClientService(); |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Get the active event logger |
|
| 376 | + * |
|
| 377 | + * @return \OCP\Diagnostics\IEventLogger |
|
| 378 | + * @since 8.0.0 |
|
| 379 | + */ |
|
| 380 | + public function getEventLogger(); |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Get the active query logger |
|
| 384 | + * |
|
| 385 | + * The returned logger only logs data when debug mode is enabled |
|
| 386 | + * |
|
| 387 | + * @return \OCP\Diagnostics\IQueryLogger |
|
| 388 | + * @since 8.0.0 |
|
| 389 | + */ |
|
| 390 | + public function getQueryLogger(); |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Get the manager for temporary files and folders |
|
| 394 | + * |
|
| 395 | + * @return \OCP\ITempManager |
|
| 396 | + * @since 8.0.0 |
|
| 397 | + */ |
|
| 398 | + public function getTempManager(); |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Get the app manager |
|
| 402 | + * |
|
| 403 | + * @return \OCP\App\IAppManager |
|
| 404 | + * @since 8.0.0 |
|
| 405 | + */ |
|
| 406 | + public function getAppManager(); |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Get the webroot |
|
| 410 | + * |
|
| 411 | + * @return string |
|
| 412 | + * @since 8.0.0 |
|
| 413 | + */ |
|
| 414 | + public function getWebRoot(); |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
| 418 | + * @since 8.0.0 |
|
| 419 | + */ |
|
| 420 | + public function getMountProviderCollection(); |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Get the IniWrapper |
|
| 424 | + * |
|
| 425 | + * @return \bantu\IniGetWrapper\IniGetWrapper |
|
| 426 | + * @since 8.0.0 |
|
| 427 | + */ |
|
| 428 | + public function getIniWrapper(); |
|
| 429 | + /** |
|
| 430 | + * @return \OCP\Command\IBus |
|
| 431 | + * @since 8.1.0 |
|
| 432 | + */ |
|
| 433 | + public function getCommandBus(); |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Creates a new mailer |
|
| 437 | + * |
|
| 438 | + * @return \OCP\Mail\IMailer |
|
| 439 | + * @since 8.1.0 |
|
| 440 | + */ |
|
| 441 | + public function getMailer(); |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Get the locking provider |
|
| 445 | + * |
|
| 446 | + * @return \OCP\Lock\ILockingProvider |
|
| 447 | + * @since 8.1.0 |
|
| 448 | + */ |
|
| 449 | + public function getLockingProvider(); |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @return \OCP\Files\Mount\IMountManager |
|
| 453 | + * @since 8.2.0 |
|
| 454 | + */ |
|
| 455 | + public function getMountManager(); |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Get the MimeTypeDetector |
|
| 459 | + * |
|
| 460 | + * @return \OCP\Files\IMimeTypeDetector |
|
| 461 | + * @since 8.2.0 |
|
| 462 | + */ |
|
| 463 | + public function getMimeTypeDetector(); |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Get the MimeTypeLoader |
|
| 467 | + * |
|
| 468 | + * @return \OCP\Files\IMimeTypeLoader |
|
| 469 | + * @since 8.2.0 |
|
| 470 | + */ |
|
| 471 | + public function getMimeTypeLoader(); |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * Get the EventDispatcher |
|
| 475 | + * |
|
| 476 | + * @return EventDispatcherInterface |
|
| 477 | + * @since 8.2.0 |
|
| 478 | + */ |
|
| 479 | + public function getEventDispatcher(); |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * Get the Notification Manager |
|
| 483 | + * |
|
| 484 | + * @return \OCP\Notification\IManager |
|
| 485 | + * @since 9.0.0 |
|
| 486 | + */ |
|
| 487 | + public function getNotificationManager(); |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * @return \OCP\Comments\ICommentsManager |
|
| 491 | + * @since 9.0.0 |
|
| 492 | + */ |
|
| 493 | + public function getCommentsManager(); |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Returns the system-tag manager |
|
| 497 | + * |
|
| 498 | + * @return \OCP\SystemTag\ISystemTagManager |
|
| 499 | + * |
|
| 500 | + * @since 9.0.0 |
|
| 501 | + */ |
|
| 502 | + public function getSystemTagManager(); |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * Returns the system-tag object mapper |
|
| 506 | + * |
|
| 507 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
| 508 | + * |
|
| 509 | + * @since 9.0.0 |
|
| 510 | + */ |
|
| 511 | + public function getSystemTagObjectMapper(); |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Returns the share manager |
|
| 515 | + * |
|
| 516 | + * @return \OCP\Share\IManager |
|
| 517 | + * @since 9.0.0 |
|
| 518 | + */ |
|
| 519 | + public function getShareManager(); |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * @return IContentSecurityPolicyManager |
|
| 523 | + * @since 9.0.0 |
|
| 524 | + */ |
|
| 525 | + public function getContentSecurityPolicyManager(); |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * @return \OCP\IDateTimeZone |
|
| 529 | + * @since 8.0.0 |
|
| 530 | + */ |
|
| 531 | + public function getDateTimeZone(); |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * @return \OCP\IDateTimeFormatter |
|
| 535 | + * @since 8.0.0 |
|
| 536 | + */ |
|
| 537 | + public function getDateTimeFormatter(); |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * @return \OCP\Federation\ICloudIdManager |
|
| 541 | + * @since 12.0.0 |
|
| 542 | + */ |
|
| 543 | + public function getCloudIdManager(); |
|
| 544 | 544 | } |
@@ -50,10 +50,8 @@ |
||
| 50 | 50 | use Sabre\DAV\Exception\Forbidden; |
| 51 | 51 | use Sabre\DAV\Exception\NotFound; |
| 52 | 52 | use Sabre\DAV\PropPatch; |
| 53 | -use Sabre\HTTP\URLUtil; |
|
| 54 | 53 | use Sabre\VObject\Component; |
| 55 | 54 | use Sabre\VObject\Component\VCalendar; |
| 56 | -use Sabre\VObject\Component\VEvent; |
|
| 57 | 55 | use Sabre\VObject\Component\VTimeZone; |
| 58 | 56 | use Sabre\VObject\DateTimeParser; |
| 59 | 57 | use Sabre\VObject\Property; |
@@ -72,2252 +72,2252 @@ |
||
| 72 | 72 | */ |
| 73 | 73 | class CalDavBackend extends AbstractBackend implements SyncSupport, SubscriptionSupport, SchedulingSupport { |
| 74 | 74 | |
| 75 | - const PERSONAL_CALENDAR_URI = 'personal'; |
|
| 76 | - const PERSONAL_CALENDAR_NAME = 'Personal'; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * We need to specify a max date, because we need to stop *somewhere* |
|
| 80 | - * |
|
| 81 | - * On 32 bit system the maximum for a signed integer is 2147483647, so |
|
| 82 | - * MAX_DATE cannot be higher than date('Y-m-d', 2147483647) which results |
|
| 83 | - * in 2038-01-19 to avoid problems when the date is converted |
|
| 84 | - * to a unix timestamp. |
|
| 85 | - */ |
|
| 86 | - const MAX_DATE = '2038-01-01'; |
|
| 87 | - |
|
| 88 | - const ACCESS_PUBLIC = 4; |
|
| 89 | - const CLASSIFICATION_PUBLIC = 0; |
|
| 90 | - const CLASSIFICATION_PRIVATE = 1; |
|
| 91 | - const CLASSIFICATION_CONFIDENTIAL = 2; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * List of CalDAV properties, and how they map to database field names |
|
| 95 | - * Add your own properties by simply adding on to this array. |
|
| 96 | - * |
|
| 97 | - * Note that only string-based properties are supported here. |
|
| 98 | - * |
|
| 99 | - * @var array |
|
| 100 | - */ |
|
| 101 | - public $propertyMap = [ |
|
| 102 | - '{DAV:}displayname' => 'displayname', |
|
| 103 | - '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'description', |
|
| 104 | - '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'timezone', |
|
| 105 | - '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
| 106 | - '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
| 107 | - ]; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * List of subscription properties, and how they map to database field names. |
|
| 111 | - * |
|
| 112 | - * @var array |
|
| 113 | - */ |
|
| 114 | - public $subscriptionPropertyMap = [ |
|
| 115 | - '{DAV:}displayname' => 'displayname', |
|
| 116 | - '{http://apple.com/ns/ical/}refreshrate' => 'refreshrate', |
|
| 117 | - '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
| 118 | - '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
| 119 | - '{http://calendarserver.org/ns/}subscribed-strip-todos' => 'striptodos', |
|
| 120 | - '{http://calendarserver.org/ns/}subscribed-strip-alarms' => 'stripalarms', |
|
| 121 | - '{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments', |
|
| 122 | - ]; |
|
| 123 | - |
|
| 124 | - /** @var array properties to index */ |
|
| 125 | - public static $indexProperties = ['CATEGORIES', 'COMMENT', 'DESCRIPTION', |
|
| 126 | - 'LOCATION', 'RESOURCES', 'STATUS', 'SUMMARY', 'ATTENDEE', 'CONTACT', |
|
| 127 | - 'ORGANIZER']; |
|
| 128 | - |
|
| 129 | - /** @var array parameters to index */ |
|
| 130 | - public static $indexParameters = [ |
|
| 131 | - 'ATTENDEE' => ['CN'], |
|
| 132 | - 'ORGANIZER' => ['CN'], |
|
| 133 | - ]; |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @var string[] Map of uid => display name |
|
| 137 | - */ |
|
| 138 | - protected $userDisplayNames; |
|
| 139 | - |
|
| 140 | - /** @var IDBConnection */ |
|
| 141 | - private $db; |
|
| 142 | - |
|
| 143 | - /** @var Backend */ |
|
| 144 | - private $sharingBackend; |
|
| 145 | - |
|
| 146 | - /** @var Principal */ |
|
| 147 | - private $principalBackend; |
|
| 148 | - |
|
| 149 | - /** @var IUserManager */ |
|
| 150 | - private $userManager; |
|
| 151 | - |
|
| 152 | - /** @var ISecureRandom */ |
|
| 153 | - private $random; |
|
| 154 | - |
|
| 155 | - /** @var EventDispatcherInterface */ |
|
| 156 | - private $dispatcher; |
|
| 157 | - |
|
| 158 | - /** @var bool */ |
|
| 159 | - private $legacyEndpoint; |
|
| 160 | - |
|
| 161 | - /** @var string */ |
|
| 162 | - private $dbObjectPropertiesTable = 'calendarobjects_props'; |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * CalDavBackend constructor. |
|
| 166 | - * |
|
| 167 | - * @param IDBConnection $db |
|
| 168 | - * @param Principal $principalBackend |
|
| 169 | - * @param IUserManager $userManager |
|
| 170 | - * @param IGroupManager $groupManager |
|
| 171 | - * @param ISecureRandom $random |
|
| 172 | - * @param EventDispatcherInterface $dispatcher |
|
| 173 | - * @param bool $legacyEndpoint |
|
| 174 | - */ |
|
| 175 | - public function __construct(IDBConnection $db, |
|
| 176 | - Principal $principalBackend, |
|
| 177 | - IUserManager $userManager, |
|
| 178 | - IGroupManager $groupManager, |
|
| 179 | - ISecureRandom $random, |
|
| 180 | - EventDispatcherInterface $dispatcher, |
|
| 181 | - $legacyEndpoint = false) { |
|
| 182 | - $this->db = $db; |
|
| 183 | - $this->principalBackend = $principalBackend; |
|
| 184 | - $this->userManager = $userManager; |
|
| 185 | - $this->sharingBackend = new Backend($this->db, $this->userManager, $groupManager, $principalBackend, 'calendar'); |
|
| 186 | - $this->random = $random; |
|
| 187 | - $this->dispatcher = $dispatcher; |
|
| 188 | - $this->legacyEndpoint = $legacyEndpoint; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Return the number of calendars for a principal |
|
| 193 | - * |
|
| 194 | - * By default this excludes the automatically generated birthday calendar |
|
| 195 | - * |
|
| 196 | - * @param $principalUri |
|
| 197 | - * @param bool $excludeBirthday |
|
| 198 | - * @return int |
|
| 199 | - */ |
|
| 200 | - public function getCalendarsForUserCount($principalUri, $excludeBirthday = true) { |
|
| 201 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
| 202 | - $query = $this->db->getQueryBuilder(); |
|
| 203 | - $query->select($query->createFunction('COUNT(*)')) |
|
| 204 | - ->from('calendars') |
|
| 205 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
| 206 | - |
|
| 207 | - if ($excludeBirthday) { |
|
| 208 | - $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return (int)$query->execute()->fetchColumn(); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Returns a list of calendars for a principal. |
|
| 216 | - * |
|
| 217 | - * Every project is an array with the following keys: |
|
| 218 | - * * id, a unique id that will be used by other functions to modify the |
|
| 219 | - * calendar. This can be the same as the uri or a database key. |
|
| 220 | - * * uri, which the basename of the uri with which the calendar is |
|
| 221 | - * accessed. |
|
| 222 | - * * principaluri. The owner of the calendar. Almost always the same as |
|
| 223 | - * principalUri passed to this method. |
|
| 224 | - * |
|
| 225 | - * Furthermore it can contain webdav properties in clark notation. A very |
|
| 226 | - * common one is '{DAV:}displayname'. |
|
| 227 | - * |
|
| 228 | - * Many clients also require: |
|
| 229 | - * {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
| 230 | - * For this property, you can just return an instance of |
|
| 231 | - * Sabre\CalDAV\Property\SupportedCalendarComponentSet. |
|
| 232 | - * |
|
| 233 | - * If you return {http://sabredav.org/ns}read-only and set the value to 1, |
|
| 234 | - * ACL will automatically be put in read-only mode. |
|
| 235 | - * |
|
| 236 | - * @param string $principalUri |
|
| 237 | - * @return array |
|
| 238 | - */ |
|
| 239 | - function getCalendarsForUser($principalUri) { |
|
| 240 | - $principalUriOriginal = $principalUri; |
|
| 241 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
| 242 | - $fields = array_values($this->propertyMap); |
|
| 243 | - $fields[] = 'id'; |
|
| 244 | - $fields[] = 'uri'; |
|
| 245 | - $fields[] = 'synctoken'; |
|
| 246 | - $fields[] = 'components'; |
|
| 247 | - $fields[] = 'principaluri'; |
|
| 248 | - $fields[] = 'transparent'; |
|
| 249 | - |
|
| 250 | - // Making fields a comma-delimited list |
|
| 251 | - $query = $this->db->getQueryBuilder(); |
|
| 252 | - $query->select($fields)->from('calendars') |
|
| 253 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
| 254 | - ->orderBy('calendarorder', 'ASC'); |
|
| 255 | - $stmt = $query->execute(); |
|
| 256 | - |
|
| 257 | - $calendars = []; |
|
| 258 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 259 | - |
|
| 260 | - $components = []; |
|
| 261 | - if ($row['components']) { |
|
| 262 | - $components = explode(',',$row['components']); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - $calendar = [ |
|
| 266 | - 'id' => $row['id'], |
|
| 267 | - 'uri' => $row['uri'], |
|
| 268 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 269 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 270 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 271 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 272 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 273 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
| 274 | - ]; |
|
| 275 | - |
|
| 276 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 277 | - $calendar[$xmlName] = $row[$dbName]; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - $this->addOwnerPrincipal($calendar); |
|
| 281 | - |
|
| 282 | - if (!isset($calendars[$calendar['id']])) { |
|
| 283 | - $calendars[$calendar['id']] = $calendar; |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - $stmt->closeCursor(); |
|
| 288 | - |
|
| 289 | - // query for shared calendars |
|
| 290 | - $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
|
| 291 | - $principals = array_map(function($principal) { |
|
| 292 | - return urldecode($principal); |
|
| 293 | - }, $principals); |
|
| 294 | - $principals[]= $principalUri; |
|
| 295 | - |
|
| 296 | - $fields = array_values($this->propertyMap); |
|
| 297 | - $fields[] = 'a.id'; |
|
| 298 | - $fields[] = 'a.uri'; |
|
| 299 | - $fields[] = 'a.synctoken'; |
|
| 300 | - $fields[] = 'a.components'; |
|
| 301 | - $fields[] = 'a.principaluri'; |
|
| 302 | - $fields[] = 'a.transparent'; |
|
| 303 | - $fields[] = 's.access'; |
|
| 304 | - $query = $this->db->getQueryBuilder(); |
|
| 305 | - $result = $query->select($fields) |
|
| 306 | - ->from('dav_shares', 's') |
|
| 307 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
| 308 | - ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) |
|
| 309 | - ->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) |
|
| 310 | - ->setParameter('type', 'calendar') |
|
| 311 | - ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
| 312 | - ->execute(); |
|
| 313 | - |
|
| 314 | - $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
| 315 | - while($row = $result->fetch()) { |
|
| 316 | - if ($row['principaluri'] === $principalUri) { |
|
| 317 | - continue; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - $readOnly = (int) $row['access'] === Backend::ACCESS_READ; |
|
| 321 | - if (isset($calendars[$row['id']])) { |
|
| 322 | - if ($readOnly) { |
|
| 323 | - // New share can not have more permissions then the old one. |
|
| 324 | - continue; |
|
| 325 | - } |
|
| 326 | - if (isset($calendars[$row['id']][$readOnlyPropertyName]) && |
|
| 327 | - $calendars[$row['id']][$readOnlyPropertyName] === 0) { |
|
| 328 | - // Old share is already read-write, no more permissions can be gained |
|
| 329 | - continue; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - list(, $name) = Uri\split($row['principaluri']); |
|
| 334 | - $uri = $row['uri'] . '_shared_by_' . $name; |
|
| 335 | - $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
| 336 | - $components = []; |
|
| 337 | - if ($row['components']) { |
|
| 338 | - $components = explode(',',$row['components']); |
|
| 339 | - } |
|
| 340 | - $calendar = [ |
|
| 341 | - 'id' => $row['id'], |
|
| 342 | - 'uri' => $uri, |
|
| 343 | - 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
| 344 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 345 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 346 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 347 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 348 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 349 | - $readOnlyPropertyName => $readOnly, |
|
| 350 | - ]; |
|
| 351 | - |
|
| 352 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 353 | - $calendar[$xmlName] = $row[$dbName]; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - $this->addOwnerPrincipal($calendar); |
|
| 357 | - |
|
| 358 | - $calendars[$calendar['id']] = $calendar; |
|
| 359 | - } |
|
| 360 | - $result->closeCursor(); |
|
| 361 | - |
|
| 362 | - return array_values($calendars); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - public function getUsersOwnCalendars($principalUri) { |
|
| 366 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
| 367 | - $fields = array_values($this->propertyMap); |
|
| 368 | - $fields[] = 'id'; |
|
| 369 | - $fields[] = 'uri'; |
|
| 370 | - $fields[] = 'synctoken'; |
|
| 371 | - $fields[] = 'components'; |
|
| 372 | - $fields[] = 'principaluri'; |
|
| 373 | - $fields[] = 'transparent'; |
|
| 374 | - // Making fields a comma-delimited list |
|
| 375 | - $query = $this->db->getQueryBuilder(); |
|
| 376 | - $query->select($fields)->from('calendars') |
|
| 377 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
| 378 | - ->orderBy('calendarorder', 'ASC'); |
|
| 379 | - $stmt = $query->execute(); |
|
| 380 | - $calendars = []; |
|
| 381 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 382 | - $components = []; |
|
| 383 | - if ($row['components']) { |
|
| 384 | - $components = explode(',',$row['components']); |
|
| 385 | - } |
|
| 386 | - $calendar = [ |
|
| 387 | - 'id' => $row['id'], |
|
| 388 | - 'uri' => $row['uri'], |
|
| 389 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 390 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 391 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 392 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 393 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 394 | - ]; |
|
| 395 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 396 | - $calendar[$xmlName] = $row[$dbName]; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - $this->addOwnerPrincipal($calendar); |
|
| 400 | - |
|
| 401 | - if (!isset($calendars[$calendar['id']])) { |
|
| 402 | - $calendars[$calendar['id']] = $calendar; |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - $stmt->closeCursor(); |
|
| 406 | - return array_values($calendars); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - private function getUserDisplayName($uid) { |
|
| 411 | - if (!isset($this->userDisplayNames[$uid])) { |
|
| 412 | - $user = $this->userManager->get($uid); |
|
| 413 | - |
|
| 414 | - if ($user instanceof IUser) { |
|
| 415 | - $this->userDisplayNames[$uid] = $user->getDisplayName(); |
|
| 416 | - } else { |
|
| 417 | - $this->userDisplayNames[$uid] = $uid; |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - return $this->userDisplayNames[$uid]; |
|
| 422 | - } |
|
| 75 | + const PERSONAL_CALENDAR_URI = 'personal'; |
|
| 76 | + const PERSONAL_CALENDAR_NAME = 'Personal'; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * We need to specify a max date, because we need to stop *somewhere* |
|
| 80 | + * |
|
| 81 | + * On 32 bit system the maximum for a signed integer is 2147483647, so |
|
| 82 | + * MAX_DATE cannot be higher than date('Y-m-d', 2147483647) which results |
|
| 83 | + * in 2038-01-19 to avoid problems when the date is converted |
|
| 84 | + * to a unix timestamp. |
|
| 85 | + */ |
|
| 86 | + const MAX_DATE = '2038-01-01'; |
|
| 87 | + |
|
| 88 | + const ACCESS_PUBLIC = 4; |
|
| 89 | + const CLASSIFICATION_PUBLIC = 0; |
|
| 90 | + const CLASSIFICATION_PRIVATE = 1; |
|
| 91 | + const CLASSIFICATION_CONFIDENTIAL = 2; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * List of CalDAV properties, and how they map to database field names |
|
| 95 | + * Add your own properties by simply adding on to this array. |
|
| 96 | + * |
|
| 97 | + * Note that only string-based properties are supported here. |
|
| 98 | + * |
|
| 99 | + * @var array |
|
| 100 | + */ |
|
| 101 | + public $propertyMap = [ |
|
| 102 | + '{DAV:}displayname' => 'displayname', |
|
| 103 | + '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'description', |
|
| 104 | + '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'timezone', |
|
| 105 | + '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
| 106 | + '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
| 107 | + ]; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * List of subscription properties, and how they map to database field names. |
|
| 111 | + * |
|
| 112 | + * @var array |
|
| 113 | + */ |
|
| 114 | + public $subscriptionPropertyMap = [ |
|
| 115 | + '{DAV:}displayname' => 'displayname', |
|
| 116 | + '{http://apple.com/ns/ical/}refreshrate' => 'refreshrate', |
|
| 117 | + '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
| 118 | + '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
| 119 | + '{http://calendarserver.org/ns/}subscribed-strip-todos' => 'striptodos', |
|
| 120 | + '{http://calendarserver.org/ns/}subscribed-strip-alarms' => 'stripalarms', |
|
| 121 | + '{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments', |
|
| 122 | + ]; |
|
| 123 | + |
|
| 124 | + /** @var array properties to index */ |
|
| 125 | + public static $indexProperties = ['CATEGORIES', 'COMMENT', 'DESCRIPTION', |
|
| 126 | + 'LOCATION', 'RESOURCES', 'STATUS', 'SUMMARY', 'ATTENDEE', 'CONTACT', |
|
| 127 | + 'ORGANIZER']; |
|
| 128 | + |
|
| 129 | + /** @var array parameters to index */ |
|
| 130 | + public static $indexParameters = [ |
|
| 131 | + 'ATTENDEE' => ['CN'], |
|
| 132 | + 'ORGANIZER' => ['CN'], |
|
| 133 | + ]; |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @var string[] Map of uid => display name |
|
| 137 | + */ |
|
| 138 | + protected $userDisplayNames; |
|
| 139 | + |
|
| 140 | + /** @var IDBConnection */ |
|
| 141 | + private $db; |
|
| 142 | + |
|
| 143 | + /** @var Backend */ |
|
| 144 | + private $sharingBackend; |
|
| 145 | + |
|
| 146 | + /** @var Principal */ |
|
| 147 | + private $principalBackend; |
|
| 148 | + |
|
| 149 | + /** @var IUserManager */ |
|
| 150 | + private $userManager; |
|
| 151 | + |
|
| 152 | + /** @var ISecureRandom */ |
|
| 153 | + private $random; |
|
| 154 | + |
|
| 155 | + /** @var EventDispatcherInterface */ |
|
| 156 | + private $dispatcher; |
|
| 157 | + |
|
| 158 | + /** @var bool */ |
|
| 159 | + private $legacyEndpoint; |
|
| 160 | + |
|
| 161 | + /** @var string */ |
|
| 162 | + private $dbObjectPropertiesTable = 'calendarobjects_props'; |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * CalDavBackend constructor. |
|
| 166 | + * |
|
| 167 | + * @param IDBConnection $db |
|
| 168 | + * @param Principal $principalBackend |
|
| 169 | + * @param IUserManager $userManager |
|
| 170 | + * @param IGroupManager $groupManager |
|
| 171 | + * @param ISecureRandom $random |
|
| 172 | + * @param EventDispatcherInterface $dispatcher |
|
| 173 | + * @param bool $legacyEndpoint |
|
| 174 | + */ |
|
| 175 | + public function __construct(IDBConnection $db, |
|
| 176 | + Principal $principalBackend, |
|
| 177 | + IUserManager $userManager, |
|
| 178 | + IGroupManager $groupManager, |
|
| 179 | + ISecureRandom $random, |
|
| 180 | + EventDispatcherInterface $dispatcher, |
|
| 181 | + $legacyEndpoint = false) { |
|
| 182 | + $this->db = $db; |
|
| 183 | + $this->principalBackend = $principalBackend; |
|
| 184 | + $this->userManager = $userManager; |
|
| 185 | + $this->sharingBackend = new Backend($this->db, $this->userManager, $groupManager, $principalBackend, 'calendar'); |
|
| 186 | + $this->random = $random; |
|
| 187 | + $this->dispatcher = $dispatcher; |
|
| 188 | + $this->legacyEndpoint = $legacyEndpoint; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Return the number of calendars for a principal |
|
| 193 | + * |
|
| 194 | + * By default this excludes the automatically generated birthday calendar |
|
| 195 | + * |
|
| 196 | + * @param $principalUri |
|
| 197 | + * @param bool $excludeBirthday |
|
| 198 | + * @return int |
|
| 199 | + */ |
|
| 200 | + public function getCalendarsForUserCount($principalUri, $excludeBirthday = true) { |
|
| 201 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
| 202 | + $query = $this->db->getQueryBuilder(); |
|
| 203 | + $query->select($query->createFunction('COUNT(*)')) |
|
| 204 | + ->from('calendars') |
|
| 205 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
| 206 | + |
|
| 207 | + if ($excludeBirthday) { |
|
| 208 | + $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return (int)$query->execute()->fetchColumn(); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Returns a list of calendars for a principal. |
|
| 216 | + * |
|
| 217 | + * Every project is an array with the following keys: |
|
| 218 | + * * id, a unique id that will be used by other functions to modify the |
|
| 219 | + * calendar. This can be the same as the uri or a database key. |
|
| 220 | + * * uri, which the basename of the uri with which the calendar is |
|
| 221 | + * accessed. |
|
| 222 | + * * principaluri. The owner of the calendar. Almost always the same as |
|
| 223 | + * principalUri passed to this method. |
|
| 224 | + * |
|
| 225 | + * Furthermore it can contain webdav properties in clark notation. A very |
|
| 226 | + * common one is '{DAV:}displayname'. |
|
| 227 | + * |
|
| 228 | + * Many clients also require: |
|
| 229 | + * {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
| 230 | + * For this property, you can just return an instance of |
|
| 231 | + * Sabre\CalDAV\Property\SupportedCalendarComponentSet. |
|
| 232 | + * |
|
| 233 | + * If you return {http://sabredav.org/ns}read-only and set the value to 1, |
|
| 234 | + * ACL will automatically be put in read-only mode. |
|
| 235 | + * |
|
| 236 | + * @param string $principalUri |
|
| 237 | + * @return array |
|
| 238 | + */ |
|
| 239 | + function getCalendarsForUser($principalUri) { |
|
| 240 | + $principalUriOriginal = $principalUri; |
|
| 241 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
| 242 | + $fields = array_values($this->propertyMap); |
|
| 243 | + $fields[] = 'id'; |
|
| 244 | + $fields[] = 'uri'; |
|
| 245 | + $fields[] = 'synctoken'; |
|
| 246 | + $fields[] = 'components'; |
|
| 247 | + $fields[] = 'principaluri'; |
|
| 248 | + $fields[] = 'transparent'; |
|
| 249 | + |
|
| 250 | + // Making fields a comma-delimited list |
|
| 251 | + $query = $this->db->getQueryBuilder(); |
|
| 252 | + $query->select($fields)->from('calendars') |
|
| 253 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
| 254 | + ->orderBy('calendarorder', 'ASC'); |
|
| 255 | + $stmt = $query->execute(); |
|
| 256 | + |
|
| 257 | + $calendars = []; |
|
| 258 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 259 | + |
|
| 260 | + $components = []; |
|
| 261 | + if ($row['components']) { |
|
| 262 | + $components = explode(',',$row['components']); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + $calendar = [ |
|
| 266 | + 'id' => $row['id'], |
|
| 267 | + 'uri' => $row['uri'], |
|
| 268 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 269 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 270 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 271 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 272 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 273 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
| 274 | + ]; |
|
| 275 | + |
|
| 276 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 277 | + $calendar[$xmlName] = $row[$dbName]; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + $this->addOwnerPrincipal($calendar); |
|
| 281 | + |
|
| 282 | + if (!isset($calendars[$calendar['id']])) { |
|
| 283 | + $calendars[$calendar['id']] = $calendar; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + $stmt->closeCursor(); |
|
| 288 | + |
|
| 289 | + // query for shared calendars |
|
| 290 | + $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
|
| 291 | + $principals = array_map(function($principal) { |
|
| 292 | + return urldecode($principal); |
|
| 293 | + }, $principals); |
|
| 294 | + $principals[]= $principalUri; |
|
| 295 | + |
|
| 296 | + $fields = array_values($this->propertyMap); |
|
| 297 | + $fields[] = 'a.id'; |
|
| 298 | + $fields[] = 'a.uri'; |
|
| 299 | + $fields[] = 'a.synctoken'; |
|
| 300 | + $fields[] = 'a.components'; |
|
| 301 | + $fields[] = 'a.principaluri'; |
|
| 302 | + $fields[] = 'a.transparent'; |
|
| 303 | + $fields[] = 's.access'; |
|
| 304 | + $query = $this->db->getQueryBuilder(); |
|
| 305 | + $result = $query->select($fields) |
|
| 306 | + ->from('dav_shares', 's') |
|
| 307 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
| 308 | + ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) |
|
| 309 | + ->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) |
|
| 310 | + ->setParameter('type', 'calendar') |
|
| 311 | + ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
| 312 | + ->execute(); |
|
| 313 | + |
|
| 314 | + $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
| 315 | + while($row = $result->fetch()) { |
|
| 316 | + if ($row['principaluri'] === $principalUri) { |
|
| 317 | + continue; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + $readOnly = (int) $row['access'] === Backend::ACCESS_READ; |
|
| 321 | + if (isset($calendars[$row['id']])) { |
|
| 322 | + if ($readOnly) { |
|
| 323 | + // New share can not have more permissions then the old one. |
|
| 324 | + continue; |
|
| 325 | + } |
|
| 326 | + if (isset($calendars[$row['id']][$readOnlyPropertyName]) && |
|
| 327 | + $calendars[$row['id']][$readOnlyPropertyName] === 0) { |
|
| 328 | + // Old share is already read-write, no more permissions can be gained |
|
| 329 | + continue; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + list(, $name) = Uri\split($row['principaluri']); |
|
| 334 | + $uri = $row['uri'] . '_shared_by_' . $name; |
|
| 335 | + $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
| 336 | + $components = []; |
|
| 337 | + if ($row['components']) { |
|
| 338 | + $components = explode(',',$row['components']); |
|
| 339 | + } |
|
| 340 | + $calendar = [ |
|
| 341 | + 'id' => $row['id'], |
|
| 342 | + 'uri' => $uri, |
|
| 343 | + 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
| 344 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 345 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 346 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 347 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 348 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 349 | + $readOnlyPropertyName => $readOnly, |
|
| 350 | + ]; |
|
| 351 | + |
|
| 352 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 353 | + $calendar[$xmlName] = $row[$dbName]; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + $this->addOwnerPrincipal($calendar); |
|
| 357 | + |
|
| 358 | + $calendars[$calendar['id']] = $calendar; |
|
| 359 | + } |
|
| 360 | + $result->closeCursor(); |
|
| 361 | + |
|
| 362 | + return array_values($calendars); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + public function getUsersOwnCalendars($principalUri) { |
|
| 366 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
| 367 | + $fields = array_values($this->propertyMap); |
|
| 368 | + $fields[] = 'id'; |
|
| 369 | + $fields[] = 'uri'; |
|
| 370 | + $fields[] = 'synctoken'; |
|
| 371 | + $fields[] = 'components'; |
|
| 372 | + $fields[] = 'principaluri'; |
|
| 373 | + $fields[] = 'transparent'; |
|
| 374 | + // Making fields a comma-delimited list |
|
| 375 | + $query = $this->db->getQueryBuilder(); |
|
| 376 | + $query->select($fields)->from('calendars') |
|
| 377 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
| 378 | + ->orderBy('calendarorder', 'ASC'); |
|
| 379 | + $stmt = $query->execute(); |
|
| 380 | + $calendars = []; |
|
| 381 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 382 | + $components = []; |
|
| 383 | + if ($row['components']) { |
|
| 384 | + $components = explode(',',$row['components']); |
|
| 385 | + } |
|
| 386 | + $calendar = [ |
|
| 387 | + 'id' => $row['id'], |
|
| 388 | + 'uri' => $row['uri'], |
|
| 389 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 390 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 391 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 392 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 393 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 394 | + ]; |
|
| 395 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 396 | + $calendar[$xmlName] = $row[$dbName]; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + $this->addOwnerPrincipal($calendar); |
|
| 400 | + |
|
| 401 | + if (!isset($calendars[$calendar['id']])) { |
|
| 402 | + $calendars[$calendar['id']] = $calendar; |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + $stmt->closeCursor(); |
|
| 406 | + return array_values($calendars); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + private function getUserDisplayName($uid) { |
|
| 411 | + if (!isset($this->userDisplayNames[$uid])) { |
|
| 412 | + $user = $this->userManager->get($uid); |
|
| 413 | + |
|
| 414 | + if ($user instanceof IUser) { |
|
| 415 | + $this->userDisplayNames[$uid] = $user->getDisplayName(); |
|
| 416 | + } else { |
|
| 417 | + $this->userDisplayNames[$uid] = $uid; |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + return $this->userDisplayNames[$uid]; |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | - /** |
|
| 425 | - * @return array |
|
| 426 | - */ |
|
| 427 | - public function getPublicCalendars() { |
|
| 428 | - $fields = array_values($this->propertyMap); |
|
| 429 | - $fields[] = 'a.id'; |
|
| 430 | - $fields[] = 'a.uri'; |
|
| 431 | - $fields[] = 'a.synctoken'; |
|
| 432 | - $fields[] = 'a.components'; |
|
| 433 | - $fields[] = 'a.principaluri'; |
|
| 434 | - $fields[] = 'a.transparent'; |
|
| 435 | - $fields[] = 's.access'; |
|
| 436 | - $fields[] = 's.publicuri'; |
|
| 437 | - $calendars = []; |
|
| 438 | - $query = $this->db->getQueryBuilder(); |
|
| 439 | - $result = $query->select($fields) |
|
| 440 | - ->from('dav_shares', 's') |
|
| 441 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
| 442 | - ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
| 443 | - ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
| 444 | - ->execute(); |
|
| 445 | - |
|
| 446 | - while($row = $result->fetch()) { |
|
| 447 | - list(, $name) = Uri\split($row['principaluri']); |
|
| 448 | - $row['displayname'] = $row['displayname'] . "($name)"; |
|
| 449 | - $components = []; |
|
| 450 | - if ($row['components']) { |
|
| 451 | - $components = explode(',',$row['components']); |
|
| 452 | - } |
|
| 453 | - $calendar = [ |
|
| 454 | - 'id' => $row['id'], |
|
| 455 | - 'uri' => $row['publicuri'], |
|
| 456 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 457 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 458 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 459 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 460 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 461 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
| 462 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
| 463 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
| 464 | - ]; |
|
| 465 | - |
|
| 466 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 467 | - $calendar[$xmlName] = $row[$dbName]; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $this->addOwnerPrincipal($calendar); |
|
| 471 | - |
|
| 472 | - if (!isset($calendars[$calendar['id']])) { |
|
| 473 | - $calendars[$calendar['id']] = $calendar; |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - $result->closeCursor(); |
|
| 477 | - |
|
| 478 | - return array_values($calendars); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * @param string $uri |
|
| 483 | - * @return array |
|
| 484 | - * @throws NotFound |
|
| 485 | - */ |
|
| 486 | - public function getPublicCalendar($uri) { |
|
| 487 | - $fields = array_values($this->propertyMap); |
|
| 488 | - $fields[] = 'a.id'; |
|
| 489 | - $fields[] = 'a.uri'; |
|
| 490 | - $fields[] = 'a.synctoken'; |
|
| 491 | - $fields[] = 'a.components'; |
|
| 492 | - $fields[] = 'a.principaluri'; |
|
| 493 | - $fields[] = 'a.transparent'; |
|
| 494 | - $fields[] = 's.access'; |
|
| 495 | - $fields[] = 's.publicuri'; |
|
| 496 | - $query = $this->db->getQueryBuilder(); |
|
| 497 | - $result = $query->select($fields) |
|
| 498 | - ->from('dav_shares', 's') |
|
| 499 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
| 500 | - ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
| 501 | - ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
| 502 | - ->andWhere($query->expr()->eq('s.publicuri', $query->createNamedParameter($uri))) |
|
| 503 | - ->execute(); |
|
| 504 | - |
|
| 505 | - $row = $result->fetch(\PDO::FETCH_ASSOC); |
|
| 506 | - |
|
| 507 | - $result->closeCursor(); |
|
| 508 | - |
|
| 509 | - if ($row === false) { |
|
| 510 | - throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - list(, $name) = Uri\split($row['principaluri']); |
|
| 514 | - $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
| 515 | - $components = []; |
|
| 516 | - if ($row['components']) { |
|
| 517 | - $components = explode(',',$row['components']); |
|
| 518 | - } |
|
| 519 | - $calendar = [ |
|
| 520 | - 'id' => $row['id'], |
|
| 521 | - 'uri' => $row['publicuri'], |
|
| 522 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 523 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 524 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 525 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 526 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 527 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 528 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
| 529 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
| 530 | - ]; |
|
| 531 | - |
|
| 532 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 533 | - $calendar[$xmlName] = $row[$dbName]; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - $this->addOwnerPrincipal($calendar); |
|
| 537 | - |
|
| 538 | - return $calendar; |
|
| 539 | - |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * @param string $principal |
|
| 544 | - * @param string $uri |
|
| 545 | - * @return array|null |
|
| 546 | - */ |
|
| 547 | - public function getCalendarByUri($principal, $uri) { |
|
| 548 | - $fields = array_values($this->propertyMap); |
|
| 549 | - $fields[] = 'id'; |
|
| 550 | - $fields[] = 'uri'; |
|
| 551 | - $fields[] = 'synctoken'; |
|
| 552 | - $fields[] = 'components'; |
|
| 553 | - $fields[] = 'principaluri'; |
|
| 554 | - $fields[] = 'transparent'; |
|
| 555 | - |
|
| 556 | - // Making fields a comma-delimited list |
|
| 557 | - $query = $this->db->getQueryBuilder(); |
|
| 558 | - $query->select($fields)->from('calendars') |
|
| 559 | - ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
| 560 | - ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) |
|
| 561 | - ->setMaxResults(1); |
|
| 562 | - $stmt = $query->execute(); |
|
| 563 | - |
|
| 564 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 565 | - $stmt->closeCursor(); |
|
| 566 | - if ($row === false) { |
|
| 567 | - return null; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - $components = []; |
|
| 571 | - if ($row['components']) { |
|
| 572 | - $components = explode(',',$row['components']); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - $calendar = [ |
|
| 576 | - 'id' => $row['id'], |
|
| 577 | - 'uri' => $row['uri'], |
|
| 578 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 579 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 580 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 581 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 582 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 583 | - ]; |
|
| 584 | - |
|
| 585 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 586 | - $calendar[$xmlName] = $row[$dbName]; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - $this->addOwnerPrincipal($calendar); |
|
| 590 | - |
|
| 591 | - return $calendar; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - public function getCalendarById($calendarId) { |
|
| 595 | - $fields = array_values($this->propertyMap); |
|
| 596 | - $fields[] = 'id'; |
|
| 597 | - $fields[] = 'uri'; |
|
| 598 | - $fields[] = 'synctoken'; |
|
| 599 | - $fields[] = 'components'; |
|
| 600 | - $fields[] = 'principaluri'; |
|
| 601 | - $fields[] = 'transparent'; |
|
| 602 | - |
|
| 603 | - // Making fields a comma-delimited list |
|
| 604 | - $query = $this->db->getQueryBuilder(); |
|
| 605 | - $query->select($fields)->from('calendars') |
|
| 606 | - ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))) |
|
| 607 | - ->setMaxResults(1); |
|
| 608 | - $stmt = $query->execute(); |
|
| 609 | - |
|
| 610 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 611 | - $stmt->closeCursor(); |
|
| 612 | - if ($row === false) { |
|
| 613 | - return null; |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - $components = []; |
|
| 617 | - if ($row['components']) { |
|
| 618 | - $components = explode(',',$row['components']); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - $calendar = [ |
|
| 622 | - 'id' => $row['id'], |
|
| 623 | - 'uri' => $row['uri'], |
|
| 624 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 625 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 626 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 627 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 628 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 629 | - ]; |
|
| 630 | - |
|
| 631 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 632 | - $calendar[$xmlName] = $row[$dbName]; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - $this->addOwnerPrincipal($calendar); |
|
| 636 | - |
|
| 637 | - return $calendar; |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * Creates a new calendar for a principal. |
|
| 642 | - * |
|
| 643 | - * If the creation was a success, an id must be returned that can be used to reference |
|
| 644 | - * this calendar in other methods, such as updateCalendar. |
|
| 645 | - * |
|
| 646 | - * @param string $principalUri |
|
| 647 | - * @param string $calendarUri |
|
| 648 | - * @param array $properties |
|
| 649 | - * @return int |
|
| 650 | - * @suppress SqlInjectionChecker |
|
| 651 | - */ |
|
| 652 | - function createCalendar($principalUri, $calendarUri, array $properties) { |
|
| 653 | - $values = [ |
|
| 654 | - 'principaluri' => $this->convertPrincipal($principalUri, true), |
|
| 655 | - 'uri' => $calendarUri, |
|
| 656 | - 'synctoken' => 1, |
|
| 657 | - 'transparent' => 0, |
|
| 658 | - 'components' => 'VEVENT,VTODO', |
|
| 659 | - 'displayname' => $calendarUri |
|
| 660 | - ]; |
|
| 661 | - |
|
| 662 | - // Default value |
|
| 663 | - $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
|
| 664 | - if (isset($properties[$sccs])) { |
|
| 665 | - if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
|
| 666 | - throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
| 667 | - } |
|
| 668 | - $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
| 669 | - } |
|
| 670 | - $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
| 671 | - if (isset($properties[$transp])) { |
|
| 672 | - $values['transparent'] = (int) ($properties[$transp]->getValue() === 'transparent'); |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 676 | - if (isset($properties[$xmlName])) { |
|
| 677 | - $values[$dbName] = $properties[$xmlName]; |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - $query = $this->db->getQueryBuilder(); |
|
| 682 | - $query->insert('calendars'); |
|
| 683 | - foreach($values as $column => $value) { |
|
| 684 | - $query->setValue($column, $query->createNamedParameter($value)); |
|
| 685 | - } |
|
| 686 | - $query->execute(); |
|
| 687 | - $calendarId = $query->getLastInsertId(); |
|
| 688 | - |
|
| 689 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent( |
|
| 690 | - '\OCA\DAV\CalDAV\CalDavBackend::createCalendar', |
|
| 691 | - [ |
|
| 692 | - 'calendarId' => $calendarId, |
|
| 693 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
| 694 | - ])); |
|
| 695 | - |
|
| 696 | - return $calendarId; |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * Updates properties for a calendar. |
|
| 701 | - * |
|
| 702 | - * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
| 703 | - * To do the actual updates, you must tell this object which properties |
|
| 704 | - * you're going to process with the handle() method. |
|
| 705 | - * |
|
| 706 | - * Calling the handle method is like telling the PropPatch object "I |
|
| 707 | - * promise I can handle updating this property". |
|
| 708 | - * |
|
| 709 | - * Read the PropPatch documentation for more info and examples. |
|
| 710 | - * |
|
| 711 | - * @param mixed $calendarId |
|
| 712 | - * @param PropPatch $propPatch |
|
| 713 | - * @return void |
|
| 714 | - */ |
|
| 715 | - function updateCalendar($calendarId, PropPatch $propPatch) { |
|
| 716 | - $supportedProperties = array_keys($this->propertyMap); |
|
| 717 | - $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * @suppress SqlInjectionChecker |
|
| 721 | - */ |
|
| 722 | - $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
|
| 723 | - $newValues = []; |
|
| 724 | - foreach ($mutations as $propertyName => $propertyValue) { |
|
| 725 | - |
|
| 726 | - switch ($propertyName) { |
|
| 727 | - case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
| 728 | - $fieldName = 'transparent'; |
|
| 729 | - $newValues[$fieldName] = (int) ($propertyValue->getValue() === 'transparent'); |
|
| 730 | - break; |
|
| 731 | - default : |
|
| 732 | - $fieldName = $this->propertyMap[$propertyName]; |
|
| 733 | - $newValues[$fieldName] = $propertyValue; |
|
| 734 | - break; |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - } |
|
| 738 | - $query = $this->db->getQueryBuilder(); |
|
| 739 | - $query->update('calendars'); |
|
| 740 | - foreach ($newValues as $fieldName => $value) { |
|
| 741 | - $query->set($fieldName, $query->createNamedParameter($value)); |
|
| 742 | - } |
|
| 743 | - $query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); |
|
| 744 | - $query->execute(); |
|
| 745 | - |
|
| 746 | - $this->addChange($calendarId, "", 2); |
|
| 747 | - |
|
| 748 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent( |
|
| 749 | - '\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', |
|
| 750 | - [ |
|
| 751 | - 'calendarId' => $calendarId, |
|
| 752 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
| 753 | - 'shares' => $this->getShares($calendarId), |
|
| 754 | - 'propertyMutations' => $mutations, |
|
| 755 | - ])); |
|
| 756 | - |
|
| 757 | - return true; |
|
| 758 | - }); |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - /** |
|
| 762 | - * Delete a calendar and all it's objects |
|
| 763 | - * |
|
| 764 | - * @param mixed $calendarId |
|
| 765 | - * @return void |
|
| 766 | - */ |
|
| 767 | - function deleteCalendar($calendarId) { |
|
| 768 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', new GenericEvent( |
|
| 769 | - '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', |
|
| 770 | - [ |
|
| 771 | - 'calendarId' => $calendarId, |
|
| 772 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
| 773 | - 'shares' => $this->getShares($calendarId), |
|
| 774 | - ])); |
|
| 775 | - |
|
| 776 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?'); |
|
| 777 | - $stmt->execute([$calendarId]); |
|
| 778 | - |
|
| 779 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
| 780 | - $stmt->execute([$calendarId]); |
|
| 781 | - |
|
| 782 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarchanges` WHERE `calendarid` = ?'); |
|
| 783 | - $stmt->execute([$calendarId]); |
|
| 784 | - |
|
| 785 | - $this->sharingBackend->deleteAllShares($calendarId); |
|
| 786 | - |
|
| 787 | - $query = $this->db->getQueryBuilder(); |
|
| 788 | - $query->delete($this->dbObjectPropertiesTable) |
|
| 789 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
| 790 | - ->execute(); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * Delete all of an user's shares |
|
| 795 | - * |
|
| 796 | - * @param string $principaluri |
|
| 797 | - * @return void |
|
| 798 | - */ |
|
| 799 | - function deleteAllSharesByUser($principaluri) { |
|
| 800 | - $this->sharingBackend->deleteAllSharesByUser($principaluri); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * Returns all calendar objects within a calendar. |
|
| 805 | - * |
|
| 806 | - * Every item contains an array with the following keys: |
|
| 807 | - * * calendardata - The iCalendar-compatible calendar data |
|
| 808 | - * * uri - a unique key which will be used to construct the uri. This can |
|
| 809 | - * be any arbitrary string, but making sure it ends with '.ics' is a |
|
| 810 | - * good idea. This is only the basename, or filename, not the full |
|
| 811 | - * path. |
|
| 812 | - * * lastmodified - a timestamp of the last modification time |
|
| 813 | - * * etag - An arbitrary string, surrounded by double-quotes. (e.g.: |
|
| 814 | - * '"abcdef"') |
|
| 815 | - * * size - The size of the calendar objects, in bytes. |
|
| 816 | - * * component - optional, a string containing the type of object, such |
|
| 817 | - * as 'vevent' or 'vtodo'. If specified, this will be used to populate |
|
| 818 | - * the Content-Type header. |
|
| 819 | - * |
|
| 820 | - * Note that the etag is optional, but it's highly encouraged to return for |
|
| 821 | - * speed reasons. |
|
| 822 | - * |
|
| 823 | - * The calendardata is also optional. If it's not returned |
|
| 824 | - * 'getCalendarObject' will be called later, which *is* expected to return |
|
| 825 | - * calendardata. |
|
| 826 | - * |
|
| 827 | - * If neither etag or size are specified, the calendardata will be |
|
| 828 | - * used/fetched to determine these numbers. If both are specified the |
|
| 829 | - * amount of times this is needed is reduced by a great degree. |
|
| 830 | - * |
|
| 831 | - * @param mixed $calendarId |
|
| 832 | - * @return array |
|
| 833 | - */ |
|
| 834 | - function getCalendarObjects($calendarId) { |
|
| 835 | - $query = $this->db->getQueryBuilder(); |
|
| 836 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'componenttype', 'classification']) |
|
| 837 | - ->from('calendarobjects') |
|
| 838 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
| 839 | - $stmt = $query->execute(); |
|
| 840 | - |
|
| 841 | - $result = []; |
|
| 842 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
| 843 | - $result[] = [ |
|
| 844 | - 'id' => $row['id'], |
|
| 845 | - 'uri' => $row['uri'], |
|
| 846 | - 'lastmodified' => $row['lastmodified'], |
|
| 847 | - 'etag' => '"' . $row['etag'] . '"', |
|
| 848 | - 'calendarid' => $row['calendarid'], |
|
| 849 | - 'size' => (int)$row['size'], |
|
| 850 | - 'component' => strtolower($row['componenttype']), |
|
| 851 | - 'classification'=> (int)$row['classification'] |
|
| 852 | - ]; |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - return $result; |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - /** |
|
| 859 | - * Returns information from a single calendar object, based on it's object |
|
| 860 | - * uri. |
|
| 861 | - * |
|
| 862 | - * The object uri is only the basename, or filename and not a full path. |
|
| 863 | - * |
|
| 864 | - * The returned array must have the same keys as getCalendarObjects. The |
|
| 865 | - * 'calendardata' object is required here though, while it's not required |
|
| 866 | - * for getCalendarObjects. |
|
| 867 | - * |
|
| 868 | - * This method must return null if the object did not exist. |
|
| 869 | - * |
|
| 870 | - * @param mixed $calendarId |
|
| 871 | - * @param string $objectUri |
|
| 872 | - * @return array|null |
|
| 873 | - */ |
|
| 874 | - function getCalendarObject($calendarId, $objectUri) { |
|
| 875 | - |
|
| 876 | - $query = $this->db->getQueryBuilder(); |
|
| 877 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
| 878 | - ->from('calendarobjects') |
|
| 879 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
| 880 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))); |
|
| 881 | - $stmt = $query->execute(); |
|
| 882 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 883 | - |
|
| 884 | - if(!$row) return null; |
|
| 885 | - |
|
| 886 | - return [ |
|
| 887 | - 'id' => $row['id'], |
|
| 888 | - 'uri' => $row['uri'], |
|
| 889 | - 'lastmodified' => $row['lastmodified'], |
|
| 890 | - 'etag' => '"' . $row['etag'] . '"', |
|
| 891 | - 'calendarid' => $row['calendarid'], |
|
| 892 | - 'size' => (int)$row['size'], |
|
| 893 | - 'calendardata' => $this->readBlob($row['calendardata']), |
|
| 894 | - 'component' => strtolower($row['componenttype']), |
|
| 895 | - 'classification'=> (int)$row['classification'] |
|
| 896 | - ]; |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * Returns a list of calendar objects. |
|
| 901 | - * |
|
| 902 | - * This method should work identical to getCalendarObject, but instead |
|
| 903 | - * return all the calendar objects in the list as an array. |
|
| 904 | - * |
|
| 905 | - * If the backend supports this, it may allow for some speed-ups. |
|
| 906 | - * |
|
| 907 | - * @param mixed $calendarId |
|
| 908 | - * @param string[] $uris |
|
| 909 | - * @return array |
|
| 910 | - */ |
|
| 911 | - function getMultipleCalendarObjects($calendarId, array $uris) { |
|
| 912 | - if (empty($uris)) { |
|
| 913 | - return []; |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - $chunks = array_chunk($uris, 100); |
|
| 917 | - $objects = []; |
|
| 918 | - |
|
| 919 | - $query = $this->db->getQueryBuilder(); |
|
| 920 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
| 921 | - ->from('calendarobjects') |
|
| 922 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
| 923 | - ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); |
|
| 924 | - |
|
| 925 | - foreach ($chunks as $uris) { |
|
| 926 | - $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); |
|
| 927 | - $result = $query->execute(); |
|
| 928 | - |
|
| 929 | - while ($row = $result->fetch()) { |
|
| 930 | - $objects[] = [ |
|
| 931 | - 'id' => $row['id'], |
|
| 932 | - 'uri' => $row['uri'], |
|
| 933 | - 'lastmodified' => $row['lastmodified'], |
|
| 934 | - 'etag' => '"' . $row['etag'] . '"', |
|
| 935 | - 'calendarid' => $row['calendarid'], |
|
| 936 | - 'size' => (int)$row['size'], |
|
| 937 | - 'calendardata' => $this->readBlob($row['calendardata']), |
|
| 938 | - 'component' => strtolower($row['componenttype']), |
|
| 939 | - 'classification' => (int)$row['classification'] |
|
| 940 | - ]; |
|
| 941 | - } |
|
| 942 | - $result->closeCursor(); |
|
| 943 | - } |
|
| 944 | - return $objects; |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - /** |
|
| 948 | - * Creates a new calendar object. |
|
| 949 | - * |
|
| 950 | - * The object uri is only the basename, or filename and not a full path. |
|
| 951 | - * |
|
| 952 | - * It is possible return an etag from this function, which will be used in |
|
| 953 | - * the response to this PUT request. Note that the ETag must be surrounded |
|
| 954 | - * by double-quotes. |
|
| 955 | - * |
|
| 956 | - * However, you should only really return this ETag if you don't mangle the |
|
| 957 | - * calendar-data. If the result of a subsequent GET to this object is not |
|
| 958 | - * the exact same as this request body, you should omit the ETag. |
|
| 959 | - * |
|
| 960 | - * @param mixed $calendarId |
|
| 961 | - * @param string $objectUri |
|
| 962 | - * @param string $calendarData |
|
| 963 | - * @return string |
|
| 964 | - */ |
|
| 965 | - function createCalendarObject($calendarId, $objectUri, $calendarData) { |
|
| 966 | - $extraData = $this->getDenormalizedData($calendarData); |
|
| 967 | - |
|
| 968 | - $q = $this->db->getQueryBuilder(); |
|
| 969 | - $q->select($q->createFunction('COUNT(*)')) |
|
| 970 | - ->from('calendarobjects') |
|
| 971 | - ->where($q->expr()->eq('calendarid', $q->createNamedParameter($calendarId))) |
|
| 972 | - ->andWhere($q->expr()->eq('uid', $q->createNamedParameter($extraData['uid']))); |
|
| 973 | - |
|
| 974 | - $result = $q->execute(); |
|
| 975 | - $count = (int) $result->fetchColumn(); |
|
| 976 | - $result->closeCursor(); |
|
| 977 | - |
|
| 978 | - if ($count !== 0) { |
|
| 979 | - throw new \Sabre\DAV\Exception\BadRequest('Calendar object with uid already exists in this calendar collection.'); |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - $query = $this->db->getQueryBuilder(); |
|
| 983 | - $query->insert('calendarobjects') |
|
| 984 | - ->values([ |
|
| 985 | - 'calendarid' => $query->createNamedParameter($calendarId), |
|
| 986 | - 'uri' => $query->createNamedParameter($objectUri), |
|
| 987 | - 'calendardata' => $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB), |
|
| 988 | - 'lastmodified' => $query->createNamedParameter(time()), |
|
| 989 | - 'etag' => $query->createNamedParameter($extraData['etag']), |
|
| 990 | - 'size' => $query->createNamedParameter($extraData['size']), |
|
| 991 | - 'componenttype' => $query->createNamedParameter($extraData['componentType']), |
|
| 992 | - 'firstoccurence' => $query->createNamedParameter($extraData['firstOccurence']), |
|
| 993 | - 'lastoccurence' => $query->createNamedParameter($extraData['lastOccurence']), |
|
| 994 | - 'classification' => $query->createNamedParameter($extraData['classification']), |
|
| 995 | - 'uid' => $query->createNamedParameter($extraData['uid']), |
|
| 996 | - ]) |
|
| 997 | - ->execute(); |
|
| 998 | - |
|
| 999 | - $this->updateProperties($calendarId, $objectUri, $calendarData); |
|
| 1000 | - |
|
| 1001 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( |
|
| 1002 | - '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', |
|
| 1003 | - [ |
|
| 1004 | - 'calendarId' => $calendarId, |
|
| 1005 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
| 1006 | - 'shares' => $this->getShares($calendarId), |
|
| 1007 | - 'objectData' => $this->getCalendarObject($calendarId, $objectUri), |
|
| 1008 | - ] |
|
| 1009 | - )); |
|
| 1010 | - $this->addChange($calendarId, $objectUri, 1); |
|
| 1011 | - |
|
| 1012 | - return '"' . $extraData['etag'] . '"'; |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - /** |
|
| 1016 | - * Updates an existing calendarobject, based on it's uri. |
|
| 1017 | - * |
|
| 1018 | - * The object uri is only the basename, or filename and not a full path. |
|
| 1019 | - * |
|
| 1020 | - * It is possible return an etag from this function, which will be used in |
|
| 1021 | - * the response to this PUT request. Note that the ETag must be surrounded |
|
| 1022 | - * by double-quotes. |
|
| 1023 | - * |
|
| 1024 | - * However, you should only really return this ETag if you don't mangle the |
|
| 1025 | - * calendar-data. If the result of a subsequent GET to this object is not |
|
| 1026 | - * the exact same as this request body, you should omit the ETag. |
|
| 1027 | - * |
|
| 1028 | - * @param mixed $calendarId |
|
| 1029 | - * @param string $objectUri |
|
| 1030 | - * @param string $calendarData |
|
| 1031 | - * @return string |
|
| 1032 | - */ |
|
| 1033 | - function updateCalendarObject($calendarId, $objectUri, $calendarData) { |
|
| 1034 | - $extraData = $this->getDenormalizedData($calendarData); |
|
| 1035 | - |
|
| 1036 | - $query = $this->db->getQueryBuilder(); |
|
| 1037 | - $query->update('calendarobjects') |
|
| 1038 | - ->set('calendardata', $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB)) |
|
| 1039 | - ->set('lastmodified', $query->createNamedParameter(time())) |
|
| 1040 | - ->set('etag', $query->createNamedParameter($extraData['etag'])) |
|
| 1041 | - ->set('size', $query->createNamedParameter($extraData['size'])) |
|
| 1042 | - ->set('componenttype', $query->createNamedParameter($extraData['componentType'])) |
|
| 1043 | - ->set('firstoccurence', $query->createNamedParameter($extraData['firstOccurence'])) |
|
| 1044 | - ->set('lastoccurence', $query->createNamedParameter($extraData['lastOccurence'])) |
|
| 1045 | - ->set('classification', $query->createNamedParameter($extraData['classification'])) |
|
| 1046 | - ->set('uid', $query->createNamedParameter($extraData['uid'])) |
|
| 1047 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
| 1048 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
| 1049 | - ->execute(); |
|
| 1050 | - |
|
| 1051 | - $this->updateProperties($calendarId, $objectUri, $calendarData); |
|
| 1052 | - |
|
| 1053 | - $data = $this->getCalendarObject($calendarId, $objectUri); |
|
| 1054 | - if (is_array($data)) { |
|
| 1055 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( |
|
| 1056 | - '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', |
|
| 1057 | - [ |
|
| 1058 | - 'calendarId' => $calendarId, |
|
| 1059 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
| 1060 | - 'shares' => $this->getShares($calendarId), |
|
| 1061 | - 'objectData' => $data, |
|
| 1062 | - ] |
|
| 1063 | - )); |
|
| 1064 | - } |
|
| 1065 | - $this->addChange($calendarId, $objectUri, 2); |
|
| 1066 | - |
|
| 1067 | - return '"' . $extraData['etag'] . '"'; |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - /** |
|
| 1071 | - * @param int $calendarObjectId |
|
| 1072 | - * @param int $classification |
|
| 1073 | - */ |
|
| 1074 | - public function setClassification($calendarObjectId, $classification) { |
|
| 1075 | - if (!in_array($classification, [ |
|
| 1076 | - self::CLASSIFICATION_PUBLIC, self::CLASSIFICATION_PRIVATE, self::CLASSIFICATION_CONFIDENTIAL |
|
| 1077 | - ])) { |
|
| 1078 | - throw new \InvalidArgumentException(); |
|
| 1079 | - } |
|
| 1080 | - $query = $this->db->getQueryBuilder(); |
|
| 1081 | - $query->update('calendarobjects') |
|
| 1082 | - ->set('classification', $query->createNamedParameter($classification)) |
|
| 1083 | - ->where($query->expr()->eq('id', $query->createNamedParameter($calendarObjectId))) |
|
| 1084 | - ->execute(); |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - /** |
|
| 1088 | - * Deletes an existing calendar object. |
|
| 1089 | - * |
|
| 1090 | - * The object uri is only the basename, or filename and not a full path. |
|
| 1091 | - * |
|
| 1092 | - * @param mixed $calendarId |
|
| 1093 | - * @param string $objectUri |
|
| 1094 | - * @return void |
|
| 1095 | - */ |
|
| 1096 | - function deleteCalendarObject($calendarId, $objectUri) { |
|
| 1097 | - $data = $this->getCalendarObject($calendarId, $objectUri); |
|
| 1098 | - if (is_array($data)) { |
|
| 1099 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( |
|
| 1100 | - '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', |
|
| 1101 | - [ |
|
| 1102 | - 'calendarId' => $calendarId, |
|
| 1103 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
| 1104 | - 'shares' => $this->getShares($calendarId), |
|
| 1105 | - 'objectData' => $data, |
|
| 1106 | - ] |
|
| 1107 | - )); |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ?'); |
|
| 1111 | - $stmt->execute([$calendarId, $objectUri]); |
|
| 1112 | - |
|
| 1113 | - $this->purgeProperties($calendarId, $data['id']); |
|
| 1114 | - |
|
| 1115 | - $this->addChange($calendarId, $objectUri, 3); |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - /** |
|
| 1119 | - * Performs a calendar-query on the contents of this calendar. |
|
| 1120 | - * |
|
| 1121 | - * The calendar-query is defined in RFC4791 : CalDAV. Using the |
|
| 1122 | - * calendar-query it is possible for a client to request a specific set of |
|
| 1123 | - * object, based on contents of iCalendar properties, date-ranges and |
|
| 1124 | - * iCalendar component types (VTODO, VEVENT). |
|
| 1125 | - * |
|
| 1126 | - * This method should just return a list of (relative) urls that match this |
|
| 1127 | - * query. |
|
| 1128 | - * |
|
| 1129 | - * The list of filters are specified as an array. The exact array is |
|
| 1130 | - * documented by Sabre\CalDAV\CalendarQueryParser. |
|
| 1131 | - * |
|
| 1132 | - * Note that it is extremely likely that getCalendarObject for every path |
|
| 1133 | - * returned from this method will be called almost immediately after. You |
|
| 1134 | - * may want to anticipate this to speed up these requests. |
|
| 1135 | - * |
|
| 1136 | - * This method provides a default implementation, which parses *all* the |
|
| 1137 | - * iCalendar objects in the specified calendar. |
|
| 1138 | - * |
|
| 1139 | - * This default may well be good enough for personal use, and calendars |
|
| 1140 | - * that aren't very large. But if you anticipate high usage, big calendars |
|
| 1141 | - * or high loads, you are strongly advised to optimize certain paths. |
|
| 1142 | - * |
|
| 1143 | - * The best way to do so is override this method and to optimize |
|
| 1144 | - * specifically for 'common filters'. |
|
| 1145 | - * |
|
| 1146 | - * Requests that are extremely common are: |
|
| 1147 | - * * requests for just VEVENTS |
|
| 1148 | - * * requests for just VTODO |
|
| 1149 | - * * requests with a time-range-filter on either VEVENT or VTODO. |
|
| 1150 | - * |
|
| 1151 | - * ..and combinations of these requests. It may not be worth it to try to |
|
| 1152 | - * handle every possible situation and just rely on the (relatively |
|
| 1153 | - * easy to use) CalendarQueryValidator to handle the rest. |
|
| 1154 | - * |
|
| 1155 | - * Note that especially time-range-filters may be difficult to parse. A |
|
| 1156 | - * time-range filter specified on a VEVENT must for instance also handle |
|
| 1157 | - * recurrence rules correctly. |
|
| 1158 | - * A good example of how to interprete all these filters can also simply |
|
| 1159 | - * be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct |
|
| 1160 | - * as possible, so it gives you a good idea on what type of stuff you need |
|
| 1161 | - * to think of. |
|
| 1162 | - * |
|
| 1163 | - * @param mixed $calendarId |
|
| 1164 | - * @param array $filters |
|
| 1165 | - * @return array |
|
| 1166 | - */ |
|
| 1167 | - function calendarQuery($calendarId, array $filters) { |
|
| 1168 | - $componentType = null; |
|
| 1169 | - $requirePostFilter = true; |
|
| 1170 | - $timeRange = null; |
|
| 1171 | - |
|
| 1172 | - // if no filters were specified, we don't need to filter after a query |
|
| 1173 | - if (!$filters['prop-filters'] && !$filters['comp-filters']) { |
|
| 1174 | - $requirePostFilter = false; |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - // Figuring out if there's a component filter |
|
| 1178 | - if (count($filters['comp-filters']) > 0 && !$filters['comp-filters'][0]['is-not-defined']) { |
|
| 1179 | - $componentType = $filters['comp-filters'][0]['name']; |
|
| 1180 | - |
|
| 1181 | - // Checking if we need post-filters |
|
| 1182 | - if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['time-range'] && !$filters['comp-filters'][0]['prop-filters']) { |
|
| 1183 | - $requirePostFilter = false; |
|
| 1184 | - } |
|
| 1185 | - // There was a time-range filter |
|
| 1186 | - if ($componentType === 'VEVENT' && isset($filters['comp-filters'][0]['time-range'])) { |
|
| 1187 | - $timeRange = $filters['comp-filters'][0]['time-range']; |
|
| 1188 | - |
|
| 1189 | - // If start time OR the end time is not specified, we can do a |
|
| 1190 | - // 100% accurate mysql query. |
|
| 1191 | - if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && (!$timeRange['start'] || !$timeRange['end'])) { |
|
| 1192 | - $requirePostFilter = false; |
|
| 1193 | - } |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - } |
|
| 1197 | - $columns = ['uri']; |
|
| 1198 | - if ($requirePostFilter) { |
|
| 1199 | - $columns = ['uri', 'calendardata']; |
|
| 1200 | - } |
|
| 1201 | - $query = $this->db->getQueryBuilder(); |
|
| 1202 | - $query->select($columns) |
|
| 1203 | - ->from('calendarobjects') |
|
| 1204 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
| 1205 | - |
|
| 1206 | - if ($componentType) { |
|
| 1207 | - $query->andWhere($query->expr()->eq('componenttype', $query->createNamedParameter($componentType))); |
|
| 1208 | - } |
|
| 1209 | - |
|
| 1210 | - if ($timeRange && $timeRange['start']) { |
|
| 1211 | - $query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($timeRange['start']->getTimeStamp()))); |
|
| 1212 | - } |
|
| 1213 | - if ($timeRange && $timeRange['end']) { |
|
| 1214 | - $query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($timeRange['end']->getTimeStamp()))); |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - $stmt = $query->execute(); |
|
| 1218 | - |
|
| 1219 | - $result = []; |
|
| 1220 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1221 | - if ($requirePostFilter) { |
|
| 1222 | - if (!$this->validateFilterForObject($row, $filters)) { |
|
| 1223 | - continue; |
|
| 1224 | - } |
|
| 1225 | - } |
|
| 1226 | - $result[] = $row['uri']; |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - return $result; |
|
| 1230 | - } |
|
| 1231 | - |
|
| 1232 | - /** |
|
| 1233 | - * custom Nextcloud search extension for CalDAV |
|
| 1234 | - * |
|
| 1235 | - * @param string $principalUri |
|
| 1236 | - * @param array $filters |
|
| 1237 | - * @param integer|null $limit |
|
| 1238 | - * @param integer|null $offset |
|
| 1239 | - * @return array |
|
| 1240 | - */ |
|
| 1241 | - public function calendarSearch($principalUri, array $filters, $limit=null, $offset=null) { |
|
| 1242 | - $calendars = $this->getCalendarsForUser($principalUri); |
|
| 1243 | - $ownCalendars = []; |
|
| 1244 | - $sharedCalendars = []; |
|
| 1245 | - |
|
| 1246 | - $uriMapper = []; |
|
| 1247 | - |
|
| 1248 | - foreach($calendars as $calendar) { |
|
| 1249 | - if ($calendar['{http://owncloud.org/ns}owner-principal'] === $principalUri) { |
|
| 1250 | - $ownCalendars[] = $calendar['id']; |
|
| 1251 | - } else { |
|
| 1252 | - $sharedCalendars[] = $calendar['id']; |
|
| 1253 | - } |
|
| 1254 | - $uriMapper[$calendar['id']] = $calendar['uri']; |
|
| 1255 | - } |
|
| 1256 | - if (count($ownCalendars) === 0 && count($sharedCalendars) === 0) { |
|
| 1257 | - return []; |
|
| 1258 | - } |
|
| 1259 | - |
|
| 1260 | - $query = $this->db->getQueryBuilder(); |
|
| 1261 | - // Calendar id expressions |
|
| 1262 | - $calendarExpressions = []; |
|
| 1263 | - foreach($ownCalendars as $id) { |
|
| 1264 | - $calendarExpressions[] = $query->expr() |
|
| 1265 | - ->eq('c.calendarid', $query->createNamedParameter($id)); |
|
| 1266 | - } |
|
| 1267 | - foreach($sharedCalendars as $id) { |
|
| 1268 | - $calendarExpressions[] = $query->expr()->andX( |
|
| 1269 | - $query->expr()->eq('c.calendarid', |
|
| 1270 | - $query->createNamedParameter($id)), |
|
| 1271 | - $query->expr()->eq('c.classification', |
|
| 1272 | - $query->createNamedParameter(self::CLASSIFICATION_PUBLIC)) |
|
| 1273 | - ); |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - if (count($calendarExpressions) === 1) { |
|
| 1277 | - $calExpr = $calendarExpressions[0]; |
|
| 1278 | - } else { |
|
| 1279 | - $calExpr = call_user_func_array([$query->expr(), 'orX'], $calendarExpressions); |
|
| 1280 | - } |
|
| 1281 | - |
|
| 1282 | - // Component expressions |
|
| 1283 | - $compExpressions = []; |
|
| 1284 | - foreach($filters['comps'] as $comp) { |
|
| 1285 | - $compExpressions[] = $query->expr() |
|
| 1286 | - ->eq('c.componenttype', $query->createNamedParameter($comp)); |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - if (count($compExpressions) === 1) { |
|
| 1290 | - $compExpr = $compExpressions[0]; |
|
| 1291 | - } else { |
|
| 1292 | - $compExpr = call_user_func_array([$query->expr(), 'orX'], $compExpressions); |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - if (!isset($filters['props'])) { |
|
| 1296 | - $filters['props'] = []; |
|
| 1297 | - } |
|
| 1298 | - if (!isset($filters['params'])) { |
|
| 1299 | - $filters['params'] = []; |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - $propParamExpressions = []; |
|
| 1303 | - foreach($filters['props'] as $prop) { |
|
| 1304 | - $propParamExpressions[] = $query->expr()->andX( |
|
| 1305 | - $query->expr()->eq('i.name', $query->createNamedParameter($prop)), |
|
| 1306 | - $query->expr()->isNull('i.parameter') |
|
| 1307 | - ); |
|
| 1308 | - } |
|
| 1309 | - foreach($filters['params'] as $param) { |
|
| 1310 | - $propParamExpressions[] = $query->expr()->andX( |
|
| 1311 | - $query->expr()->eq('i.name', $query->createNamedParameter($param['property'])), |
|
| 1312 | - $query->expr()->eq('i.parameter', $query->createNamedParameter($param['parameter'])) |
|
| 1313 | - ); |
|
| 1314 | - } |
|
| 1315 | - |
|
| 1316 | - if (count($propParamExpressions) === 1) { |
|
| 1317 | - $propParamExpr = $propParamExpressions[0]; |
|
| 1318 | - } else { |
|
| 1319 | - $propParamExpr = call_user_func_array([$query->expr(), 'orX'], $propParamExpressions); |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - $query->select(['c.calendarid', 'c.uri']) |
|
| 1323 | - ->from($this->dbObjectPropertiesTable, 'i') |
|
| 1324 | - ->join('i', 'calendarobjects', 'c', $query->expr()->eq('i.objectid', 'c.id')) |
|
| 1325 | - ->where($calExpr) |
|
| 1326 | - ->andWhere($compExpr) |
|
| 1327 | - ->andWhere($propParamExpr) |
|
| 1328 | - ->andWhere($query->expr()->iLike('i.value', |
|
| 1329 | - $query->createNamedParameter('%'.$this->db->escapeLikeParameter($filters['search-term']).'%'))); |
|
| 1330 | - |
|
| 1331 | - if ($offset) { |
|
| 1332 | - $query->setFirstResult($offset); |
|
| 1333 | - } |
|
| 1334 | - if ($limit) { |
|
| 1335 | - $query->setMaxResults($limit); |
|
| 1336 | - } |
|
| 1337 | - |
|
| 1338 | - $stmt = $query->execute(); |
|
| 1339 | - |
|
| 1340 | - $result = []; |
|
| 1341 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1342 | - $path = $uriMapper[$row['calendarid']] . '/' . $row['uri']; |
|
| 1343 | - if (!in_array($path, $result)) { |
|
| 1344 | - $result[] = $path; |
|
| 1345 | - } |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - return $result; |
|
| 1349 | - } |
|
| 1350 | - |
|
| 1351 | - /** |
|
| 1352 | - * used for Nextcloud's calendar API |
|
| 1353 | - * |
|
| 1354 | - * @param array $calendarInfo |
|
| 1355 | - * @param string $pattern |
|
| 1356 | - * @param array $searchProperties |
|
| 1357 | - * @param array $options |
|
| 1358 | - * @param integer|null $limit |
|
| 1359 | - * @param integer|null $offset |
|
| 1360 | - * |
|
| 1361 | - * @return array |
|
| 1362 | - */ |
|
| 1363 | - public function search(array $calendarInfo, $pattern, array $searchProperties, |
|
| 1364 | - array $options, $limit, $offset) { |
|
| 1365 | - $outerQuery = $this->db->getQueryBuilder(); |
|
| 1366 | - $innerQuery = $this->db->getQueryBuilder(); |
|
| 1367 | - |
|
| 1368 | - $innerQuery->selectDistinct('op.objectid') |
|
| 1369 | - ->from($this->dbObjectPropertiesTable, 'op') |
|
| 1370 | - ->andWhere($innerQuery->expr()->eq('op.calendarid', |
|
| 1371 | - $outerQuery->createNamedParameter($calendarInfo['id']))); |
|
| 1372 | - |
|
| 1373 | - // only return public items for shared calendars for now |
|
| 1374 | - if ($calendarInfo['principaluri'] !== $calendarInfo['{http://owncloud.org/ns}owner-principal']) { |
|
| 1375 | - $innerQuery->andWhere($innerQuery->expr()->eq('c.classification', |
|
| 1376 | - $outerQuery->createNamedParameter(self::CLASSIFICATION_PUBLIC))); |
|
| 1377 | - } |
|
| 1378 | - |
|
| 1379 | - $or = $innerQuery->expr()->orX(); |
|
| 1380 | - foreach($searchProperties as $searchProperty) { |
|
| 1381 | - $or->add($innerQuery->expr()->eq('op.name', |
|
| 1382 | - $outerQuery->createNamedParameter($searchProperty))); |
|
| 1383 | - } |
|
| 1384 | - $innerQuery->andWhere($or); |
|
| 1385 | - |
|
| 1386 | - if ($pattern !== '') { |
|
| 1387 | - $innerQuery->andWhere($innerQuery->expr()->iLike('op.value', |
|
| 1388 | - $outerQuery->createNamedParameter('%' . |
|
| 1389 | - $this->db->escapeLikeParameter($pattern) . '%'))); |
|
| 1390 | - } |
|
| 1391 | - |
|
| 1392 | - $outerQuery->select('c.id', 'c.calendardata', 'c.componenttype', 'c.uid', 'c.uri') |
|
| 1393 | - ->from('calendarobjects', 'c'); |
|
| 1394 | - |
|
| 1395 | - if (isset($options['timerange'])) { |
|
| 1396 | - if (isset($options['timerange']['start'])) { |
|
| 1397 | - $outerQuery->andWhere($outerQuery->expr()->gt('lastoccurence', |
|
| 1398 | - $outerQuery->createNamedParameter($options['timerange']['start']->getTimeStamp))); |
|
| 1399 | - |
|
| 1400 | - } |
|
| 1401 | - if (isset($options['timerange']['end'])) { |
|
| 1402 | - $outerQuery->andWhere($outerQuery->expr()->lt('firstoccurence', |
|
| 1403 | - $outerQuery->createNamedParameter($options['timerange']['end']->getTimeStamp))); |
|
| 1404 | - } |
|
| 1405 | - } |
|
| 1406 | - |
|
| 1407 | - if (isset($options['types'])) { |
|
| 1408 | - $or = $outerQuery->expr()->orX(); |
|
| 1409 | - foreach($options['types'] as $type) { |
|
| 1410 | - $or->add($outerQuery->expr()->eq('componenttype', |
|
| 1411 | - $outerQuery->createNamedParameter($type))); |
|
| 1412 | - } |
|
| 1413 | - $outerQuery->andWhere($or); |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - $outerQuery->andWhere($outerQuery->expr()->in('c.id', |
|
| 1417 | - $outerQuery->createFunction($innerQuery->getSQL()))); |
|
| 1418 | - |
|
| 1419 | - if ($offset) { |
|
| 1420 | - $outerQuery->setFirstResult($offset); |
|
| 1421 | - } |
|
| 1422 | - if ($limit) { |
|
| 1423 | - $outerQuery->setMaxResults($limit); |
|
| 1424 | - } |
|
| 1425 | - |
|
| 1426 | - $result = $outerQuery->execute(); |
|
| 1427 | - $calendarObjects = $result->fetchAll(); |
|
| 1428 | - |
|
| 1429 | - return array_map(function($o) { |
|
| 1430 | - $calendarData = Reader::read($o['calendardata']); |
|
| 1431 | - $comps = $calendarData->getComponents(); |
|
| 1432 | - $objects = []; |
|
| 1433 | - $timezones = []; |
|
| 1434 | - foreach($comps as $comp) { |
|
| 1435 | - if ($comp instanceof VTimeZone) { |
|
| 1436 | - $timezones[] = $comp; |
|
| 1437 | - } else { |
|
| 1438 | - $objects[] = $comp; |
|
| 1439 | - } |
|
| 1440 | - } |
|
| 1441 | - |
|
| 1442 | - return [ |
|
| 1443 | - 'id' => $o['id'], |
|
| 1444 | - 'type' => $o['componenttype'], |
|
| 1445 | - 'uid' => $o['uid'], |
|
| 1446 | - 'uri' => $o['uri'], |
|
| 1447 | - 'objects' => array_map(function($c) { |
|
| 1448 | - return $this->transformSearchData($c); |
|
| 1449 | - }, $objects), |
|
| 1450 | - 'timezones' => array_map(function($c) { |
|
| 1451 | - return $this->transformSearchData($c); |
|
| 1452 | - }, $timezones), |
|
| 1453 | - ]; |
|
| 1454 | - }, $calendarObjects); |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - /** |
|
| 1458 | - * @param Component $comp |
|
| 1459 | - * @return array |
|
| 1460 | - */ |
|
| 1461 | - private function transformSearchData(Component $comp) { |
|
| 1462 | - $data = []; |
|
| 1463 | - /** @var Component[] $subComponents */ |
|
| 1464 | - $subComponents = $comp->getComponents(); |
|
| 1465 | - /** @var Property[] $properties */ |
|
| 1466 | - $properties = array_filter($comp->children(), function($c) { |
|
| 1467 | - return $c instanceof Property; |
|
| 1468 | - }); |
|
| 1469 | - $validationRules = $comp->getValidationRules(); |
|
| 1470 | - |
|
| 1471 | - foreach($subComponents as $subComponent) { |
|
| 1472 | - $name = $subComponent->name; |
|
| 1473 | - if (!isset($data[$name])) { |
|
| 1474 | - $data[$name] = []; |
|
| 1475 | - } |
|
| 1476 | - $data[$name][] = $this->transformSearchData($subComponent); |
|
| 1477 | - } |
|
| 1478 | - |
|
| 1479 | - foreach($properties as $property) { |
|
| 1480 | - $name = $property->name; |
|
| 1481 | - if (!isset($validationRules[$name])) { |
|
| 1482 | - $validationRules[$name] = '*'; |
|
| 1483 | - } |
|
| 1484 | - |
|
| 1485 | - $rule = $validationRules[$property->name]; |
|
| 1486 | - if ($rule === '+' || $rule === '*') { // multiple |
|
| 1487 | - if (!isset($data[$name])) { |
|
| 1488 | - $data[$name] = []; |
|
| 1489 | - } |
|
| 1490 | - |
|
| 1491 | - $data[$name][] = $this->transformSearchProperty($property); |
|
| 1492 | - } else { // once |
|
| 1493 | - $data[$name] = $this->transformSearchProperty($property); |
|
| 1494 | - } |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - return $data; |
|
| 1498 | - } |
|
| 1499 | - |
|
| 1500 | - /** |
|
| 1501 | - * @param Property $prop |
|
| 1502 | - * @return array |
|
| 1503 | - */ |
|
| 1504 | - private function transformSearchProperty(Property $prop) { |
|
| 1505 | - // No need to check Date, as it extends DateTime |
|
| 1506 | - if ($prop instanceof Property\ICalendar\DateTime) { |
|
| 1507 | - $value = $prop->getDateTime(); |
|
| 1508 | - } else { |
|
| 1509 | - $value = $prop->getValue(); |
|
| 1510 | - } |
|
| 1511 | - |
|
| 1512 | - return [ |
|
| 1513 | - $value, |
|
| 1514 | - $prop->parameters() |
|
| 1515 | - ]; |
|
| 1516 | - } |
|
| 1517 | - |
|
| 1518 | - /** |
|
| 1519 | - * Searches through all of a users calendars and calendar objects to find |
|
| 1520 | - * an object with a specific UID. |
|
| 1521 | - * |
|
| 1522 | - * This method should return the path to this object, relative to the |
|
| 1523 | - * calendar home, so this path usually only contains two parts: |
|
| 1524 | - * |
|
| 1525 | - * calendarpath/objectpath.ics |
|
| 1526 | - * |
|
| 1527 | - * If the uid is not found, return null. |
|
| 1528 | - * |
|
| 1529 | - * This method should only consider * objects that the principal owns, so |
|
| 1530 | - * any calendars owned by other principals that also appear in this |
|
| 1531 | - * collection should be ignored. |
|
| 1532 | - * |
|
| 1533 | - * @param string $principalUri |
|
| 1534 | - * @param string $uid |
|
| 1535 | - * @return string|null |
|
| 1536 | - */ |
|
| 1537 | - function getCalendarObjectByUID($principalUri, $uid) { |
|
| 1538 | - |
|
| 1539 | - $query = $this->db->getQueryBuilder(); |
|
| 1540 | - $query->selectAlias('c.uri', 'calendaruri')->selectAlias('co.uri', 'objecturi') |
|
| 1541 | - ->from('calendarobjects', 'co') |
|
| 1542 | - ->leftJoin('co', 'calendars', 'c', $query->expr()->eq('co.calendarid', 'c.id')) |
|
| 1543 | - ->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri))) |
|
| 1544 | - ->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid))); |
|
| 1545 | - |
|
| 1546 | - $stmt = $query->execute(); |
|
| 1547 | - |
|
| 1548 | - if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1549 | - return $row['calendaruri'] . '/' . $row['objecturi']; |
|
| 1550 | - } |
|
| 1551 | - |
|
| 1552 | - return null; |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - /** |
|
| 1556 | - * The getChanges method returns all the changes that have happened, since |
|
| 1557 | - * the specified syncToken in the specified calendar. |
|
| 1558 | - * |
|
| 1559 | - * This function should return an array, such as the following: |
|
| 1560 | - * |
|
| 1561 | - * [ |
|
| 1562 | - * 'syncToken' => 'The current synctoken', |
|
| 1563 | - * 'added' => [ |
|
| 1564 | - * 'new.txt', |
|
| 1565 | - * ], |
|
| 1566 | - * 'modified' => [ |
|
| 1567 | - * 'modified.txt', |
|
| 1568 | - * ], |
|
| 1569 | - * 'deleted' => [ |
|
| 1570 | - * 'foo.php.bak', |
|
| 1571 | - * 'old.txt' |
|
| 1572 | - * ] |
|
| 1573 | - * ); |
|
| 1574 | - * |
|
| 1575 | - * The returned syncToken property should reflect the *current* syncToken |
|
| 1576 | - * of the calendar, as reported in the {http://sabredav.org/ns}sync-token |
|
| 1577 | - * property This is * needed here too, to ensure the operation is atomic. |
|
| 1578 | - * |
|
| 1579 | - * If the $syncToken argument is specified as null, this is an initial |
|
| 1580 | - * sync, and all members should be reported. |
|
| 1581 | - * |
|
| 1582 | - * The modified property is an array of nodenames that have changed since |
|
| 1583 | - * the last token. |
|
| 1584 | - * |
|
| 1585 | - * The deleted property is an array with nodenames, that have been deleted |
|
| 1586 | - * from collection. |
|
| 1587 | - * |
|
| 1588 | - * The $syncLevel argument is basically the 'depth' of the report. If it's |
|
| 1589 | - * 1, you only have to report changes that happened only directly in |
|
| 1590 | - * immediate descendants. If it's 2, it should also include changes from |
|
| 1591 | - * the nodes below the child collections. (grandchildren) |
|
| 1592 | - * |
|
| 1593 | - * The $limit argument allows a client to specify how many results should |
|
| 1594 | - * be returned at most. If the limit is not specified, it should be treated |
|
| 1595 | - * as infinite. |
|
| 1596 | - * |
|
| 1597 | - * If the limit (infinite or not) is higher than you're willing to return, |
|
| 1598 | - * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
| 1599 | - * |
|
| 1600 | - * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
| 1601 | - * return null. |
|
| 1602 | - * |
|
| 1603 | - * The limit is 'suggestive'. You are free to ignore it. |
|
| 1604 | - * |
|
| 1605 | - * @param string $calendarId |
|
| 1606 | - * @param string $syncToken |
|
| 1607 | - * @param int $syncLevel |
|
| 1608 | - * @param int $limit |
|
| 1609 | - * @return array |
|
| 1610 | - */ |
|
| 1611 | - function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
|
| 1612 | - // Current synctoken |
|
| 1613 | - $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
| 1614 | - $stmt->execute([ $calendarId ]); |
|
| 1615 | - $currentToken = $stmt->fetchColumn(0); |
|
| 1616 | - |
|
| 1617 | - if (is_null($currentToken)) { |
|
| 1618 | - return null; |
|
| 1619 | - } |
|
| 1620 | - |
|
| 1621 | - $result = [ |
|
| 1622 | - 'syncToken' => $currentToken, |
|
| 1623 | - 'added' => [], |
|
| 1624 | - 'modified' => [], |
|
| 1625 | - 'deleted' => [], |
|
| 1626 | - ]; |
|
| 1627 | - |
|
| 1628 | - if ($syncToken) { |
|
| 1629 | - |
|
| 1630 | - $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
|
| 1631 | - if ($limit>0) { |
|
| 1632 | - $query.= " LIMIT " . (int)$limit; |
|
| 1633 | - } |
|
| 1634 | - |
|
| 1635 | - // Fetching all changes |
|
| 1636 | - $stmt = $this->db->prepare($query); |
|
| 1637 | - $stmt->execute([$syncToken, $currentToken, $calendarId]); |
|
| 1638 | - |
|
| 1639 | - $changes = []; |
|
| 1640 | - |
|
| 1641 | - // This loop ensures that any duplicates are overwritten, only the |
|
| 1642 | - // last change on a node is relevant. |
|
| 1643 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1644 | - |
|
| 1645 | - $changes[$row['uri']] = $row['operation']; |
|
| 1646 | - |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - foreach($changes as $uri => $operation) { |
|
| 1650 | - |
|
| 1651 | - switch($operation) { |
|
| 1652 | - case 1 : |
|
| 1653 | - $result['added'][] = $uri; |
|
| 1654 | - break; |
|
| 1655 | - case 2 : |
|
| 1656 | - $result['modified'][] = $uri; |
|
| 1657 | - break; |
|
| 1658 | - case 3 : |
|
| 1659 | - $result['deleted'][] = $uri; |
|
| 1660 | - break; |
|
| 1661 | - } |
|
| 1662 | - |
|
| 1663 | - } |
|
| 1664 | - } else { |
|
| 1665 | - // No synctoken supplied, this is the initial sync. |
|
| 1666 | - $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?"; |
|
| 1667 | - $stmt = $this->db->prepare($query); |
|
| 1668 | - $stmt->execute([$calendarId]); |
|
| 1669 | - |
|
| 1670 | - $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
| 1671 | - } |
|
| 1672 | - return $result; |
|
| 1673 | - |
|
| 1674 | - } |
|
| 1675 | - |
|
| 1676 | - /** |
|
| 1677 | - * Returns a list of subscriptions for a principal. |
|
| 1678 | - * |
|
| 1679 | - * Every subscription is an array with the following keys: |
|
| 1680 | - * * id, a unique id that will be used by other functions to modify the |
|
| 1681 | - * subscription. This can be the same as the uri or a database key. |
|
| 1682 | - * * uri. This is just the 'base uri' or 'filename' of the subscription. |
|
| 1683 | - * * principaluri. The owner of the subscription. Almost always the same as |
|
| 1684 | - * principalUri passed to this method. |
|
| 1685 | - * |
|
| 1686 | - * Furthermore, all the subscription info must be returned too: |
|
| 1687 | - * |
|
| 1688 | - * 1. {DAV:}displayname |
|
| 1689 | - * 2. {http://apple.com/ns/ical/}refreshrate |
|
| 1690 | - * 3. {http://calendarserver.org/ns/}subscribed-strip-todos (omit if todos |
|
| 1691 | - * should not be stripped). |
|
| 1692 | - * 4. {http://calendarserver.org/ns/}subscribed-strip-alarms (omit if alarms |
|
| 1693 | - * should not be stripped). |
|
| 1694 | - * 5. {http://calendarserver.org/ns/}subscribed-strip-attachments (omit if |
|
| 1695 | - * attachments should not be stripped). |
|
| 1696 | - * 6. {http://calendarserver.org/ns/}source (Must be a |
|
| 1697 | - * Sabre\DAV\Property\Href). |
|
| 1698 | - * 7. {http://apple.com/ns/ical/}calendar-color |
|
| 1699 | - * 8. {http://apple.com/ns/ical/}calendar-order |
|
| 1700 | - * 9. {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
| 1701 | - * (should just be an instance of |
|
| 1702 | - * Sabre\CalDAV\Property\SupportedCalendarComponentSet, with a bunch of |
|
| 1703 | - * default components). |
|
| 1704 | - * |
|
| 1705 | - * @param string $principalUri |
|
| 1706 | - * @return array |
|
| 1707 | - */ |
|
| 1708 | - function getSubscriptionsForUser($principalUri) { |
|
| 1709 | - $fields = array_values($this->subscriptionPropertyMap); |
|
| 1710 | - $fields[] = 'id'; |
|
| 1711 | - $fields[] = 'uri'; |
|
| 1712 | - $fields[] = 'source'; |
|
| 1713 | - $fields[] = 'principaluri'; |
|
| 1714 | - $fields[] = 'lastmodified'; |
|
| 1715 | - |
|
| 1716 | - $query = $this->db->getQueryBuilder(); |
|
| 1717 | - $query->select($fields) |
|
| 1718 | - ->from('calendarsubscriptions') |
|
| 1719 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
| 1720 | - ->orderBy('calendarorder', 'asc'); |
|
| 1721 | - $stmt =$query->execute(); |
|
| 1722 | - |
|
| 1723 | - $subscriptions = []; |
|
| 1724 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1725 | - |
|
| 1726 | - $subscription = [ |
|
| 1727 | - 'id' => $row['id'], |
|
| 1728 | - 'uri' => $row['uri'], |
|
| 1729 | - 'principaluri' => $row['principaluri'], |
|
| 1730 | - 'source' => $row['source'], |
|
| 1731 | - 'lastmodified' => $row['lastmodified'], |
|
| 1732 | - |
|
| 1733 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
| 1734 | - ]; |
|
| 1735 | - |
|
| 1736 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
| 1737 | - if (!is_null($row[$dbName])) { |
|
| 1738 | - $subscription[$xmlName] = $row[$dbName]; |
|
| 1739 | - } |
|
| 1740 | - } |
|
| 1741 | - |
|
| 1742 | - $subscriptions[] = $subscription; |
|
| 1743 | - |
|
| 1744 | - } |
|
| 1745 | - |
|
| 1746 | - return $subscriptions; |
|
| 1747 | - } |
|
| 1748 | - |
|
| 1749 | - /** |
|
| 1750 | - * Creates a new subscription for a principal. |
|
| 1751 | - * |
|
| 1752 | - * If the creation was a success, an id must be returned that can be used to reference |
|
| 1753 | - * this subscription in other methods, such as updateSubscription. |
|
| 1754 | - * |
|
| 1755 | - * @param string $principalUri |
|
| 1756 | - * @param string $uri |
|
| 1757 | - * @param array $properties |
|
| 1758 | - * @return mixed |
|
| 1759 | - */ |
|
| 1760 | - function createSubscription($principalUri, $uri, array $properties) { |
|
| 1761 | - |
|
| 1762 | - if (!isset($properties['{http://calendarserver.org/ns/}source'])) { |
|
| 1763 | - throw new Forbidden('The {http://calendarserver.org/ns/}source property is required when creating subscriptions'); |
|
| 1764 | - } |
|
| 1765 | - |
|
| 1766 | - $values = [ |
|
| 1767 | - 'principaluri' => $principalUri, |
|
| 1768 | - 'uri' => $uri, |
|
| 1769 | - 'source' => $properties['{http://calendarserver.org/ns/}source']->getHref(), |
|
| 1770 | - 'lastmodified' => time(), |
|
| 1771 | - ]; |
|
| 1772 | - |
|
| 1773 | - $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
|
| 1774 | - |
|
| 1775 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
| 1776 | - if (array_key_exists($xmlName, $properties)) { |
|
| 1777 | - $values[$dbName] = $properties[$xmlName]; |
|
| 1778 | - if (in_array($dbName, $propertiesBoolean)) { |
|
| 1779 | - $values[$dbName] = true; |
|
| 1780 | - } |
|
| 1781 | - } |
|
| 1782 | - } |
|
| 1783 | - |
|
| 1784 | - $valuesToInsert = array(); |
|
| 1785 | - |
|
| 1786 | - $query = $this->db->getQueryBuilder(); |
|
| 1787 | - |
|
| 1788 | - foreach (array_keys($values) as $name) { |
|
| 1789 | - $valuesToInsert[$name] = $query->createNamedParameter($values[$name]); |
|
| 1790 | - } |
|
| 1791 | - |
|
| 1792 | - $query->insert('calendarsubscriptions') |
|
| 1793 | - ->values($valuesToInsert) |
|
| 1794 | - ->execute(); |
|
| 1795 | - |
|
| 1796 | - return $this->db->lastInsertId('*PREFIX*calendarsubscriptions'); |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - /** |
|
| 1800 | - * Updates a subscription |
|
| 1801 | - * |
|
| 1802 | - * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
| 1803 | - * To do the actual updates, you must tell this object which properties |
|
| 1804 | - * you're going to process with the handle() method. |
|
| 1805 | - * |
|
| 1806 | - * Calling the handle method is like telling the PropPatch object "I |
|
| 1807 | - * promise I can handle updating this property". |
|
| 1808 | - * |
|
| 1809 | - * Read the PropPatch documentation for more info and examples. |
|
| 1810 | - * |
|
| 1811 | - * @param mixed $subscriptionId |
|
| 1812 | - * @param PropPatch $propPatch |
|
| 1813 | - * @return void |
|
| 1814 | - */ |
|
| 1815 | - function updateSubscription($subscriptionId, PropPatch $propPatch) { |
|
| 1816 | - $supportedProperties = array_keys($this->subscriptionPropertyMap); |
|
| 1817 | - $supportedProperties[] = '{http://calendarserver.org/ns/}source'; |
|
| 1818 | - |
|
| 1819 | - /** |
|
| 1820 | - * @suppress SqlInjectionChecker |
|
| 1821 | - */ |
|
| 1822 | - $propPatch->handle($supportedProperties, function($mutations) use ($subscriptionId) { |
|
| 1823 | - |
|
| 1824 | - $newValues = []; |
|
| 1825 | - |
|
| 1826 | - foreach($mutations as $propertyName=>$propertyValue) { |
|
| 1827 | - if ($propertyName === '{http://calendarserver.org/ns/}source') { |
|
| 1828 | - $newValues['source'] = $propertyValue->getHref(); |
|
| 1829 | - } else { |
|
| 1830 | - $fieldName = $this->subscriptionPropertyMap[$propertyName]; |
|
| 1831 | - $newValues[$fieldName] = $propertyValue; |
|
| 1832 | - } |
|
| 1833 | - } |
|
| 1834 | - |
|
| 1835 | - $query = $this->db->getQueryBuilder(); |
|
| 1836 | - $query->update('calendarsubscriptions') |
|
| 1837 | - ->set('lastmodified', $query->createNamedParameter(time())); |
|
| 1838 | - foreach($newValues as $fieldName=>$value) { |
|
| 1839 | - $query->set($fieldName, $query->createNamedParameter($value)); |
|
| 1840 | - } |
|
| 1841 | - $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
| 1842 | - ->execute(); |
|
| 1843 | - |
|
| 1844 | - return true; |
|
| 1845 | - |
|
| 1846 | - }); |
|
| 1847 | - } |
|
| 1848 | - |
|
| 1849 | - /** |
|
| 1850 | - * Deletes a subscription. |
|
| 1851 | - * |
|
| 1852 | - * @param mixed $subscriptionId |
|
| 1853 | - * @return void |
|
| 1854 | - */ |
|
| 1855 | - function deleteSubscription($subscriptionId) { |
|
| 1856 | - $query = $this->db->getQueryBuilder(); |
|
| 1857 | - $query->delete('calendarsubscriptions') |
|
| 1858 | - ->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
| 1859 | - ->execute(); |
|
| 1860 | - } |
|
| 1861 | - |
|
| 1862 | - /** |
|
| 1863 | - * Returns a single scheduling object for the inbox collection. |
|
| 1864 | - * |
|
| 1865 | - * The returned array should contain the following elements: |
|
| 1866 | - * * uri - A unique basename for the object. This will be used to |
|
| 1867 | - * construct a full uri. |
|
| 1868 | - * * calendardata - The iCalendar object |
|
| 1869 | - * * lastmodified - The last modification date. Can be an int for a unix |
|
| 1870 | - * timestamp, or a PHP DateTime object. |
|
| 1871 | - * * etag - A unique token that must change if the object changed. |
|
| 1872 | - * * size - The size of the object, in bytes. |
|
| 1873 | - * |
|
| 1874 | - * @param string $principalUri |
|
| 1875 | - * @param string $objectUri |
|
| 1876 | - * @return array |
|
| 1877 | - */ |
|
| 1878 | - function getSchedulingObject($principalUri, $objectUri) { |
|
| 1879 | - $query = $this->db->getQueryBuilder(); |
|
| 1880 | - $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
| 1881 | - ->from('schedulingobjects') |
|
| 1882 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
| 1883 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
| 1884 | - ->execute(); |
|
| 1885 | - |
|
| 1886 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 1887 | - |
|
| 1888 | - if(!$row) { |
|
| 1889 | - return null; |
|
| 1890 | - } |
|
| 1891 | - |
|
| 1892 | - return [ |
|
| 1893 | - 'uri' => $row['uri'], |
|
| 1894 | - 'calendardata' => $row['calendardata'], |
|
| 1895 | - 'lastmodified' => $row['lastmodified'], |
|
| 1896 | - 'etag' => '"' . $row['etag'] . '"', |
|
| 1897 | - 'size' => (int)$row['size'], |
|
| 1898 | - ]; |
|
| 1899 | - } |
|
| 1900 | - |
|
| 1901 | - /** |
|
| 1902 | - * Returns all scheduling objects for the inbox collection. |
|
| 1903 | - * |
|
| 1904 | - * These objects should be returned as an array. Every item in the array |
|
| 1905 | - * should follow the same structure as returned from getSchedulingObject. |
|
| 1906 | - * |
|
| 1907 | - * The main difference is that 'calendardata' is optional. |
|
| 1908 | - * |
|
| 1909 | - * @param string $principalUri |
|
| 1910 | - * @return array |
|
| 1911 | - */ |
|
| 1912 | - function getSchedulingObjects($principalUri) { |
|
| 1913 | - $query = $this->db->getQueryBuilder(); |
|
| 1914 | - $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
| 1915 | - ->from('schedulingobjects') |
|
| 1916 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
| 1917 | - ->execute(); |
|
| 1918 | - |
|
| 1919 | - $result = []; |
|
| 1920 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
| 1921 | - $result[] = [ |
|
| 1922 | - 'calendardata' => $row['calendardata'], |
|
| 1923 | - 'uri' => $row['uri'], |
|
| 1924 | - 'lastmodified' => $row['lastmodified'], |
|
| 1925 | - 'etag' => '"' . $row['etag'] . '"', |
|
| 1926 | - 'size' => (int)$row['size'], |
|
| 1927 | - ]; |
|
| 1928 | - } |
|
| 1929 | - |
|
| 1930 | - return $result; |
|
| 1931 | - } |
|
| 1932 | - |
|
| 1933 | - /** |
|
| 1934 | - * Deletes a scheduling object from the inbox collection. |
|
| 1935 | - * |
|
| 1936 | - * @param string $principalUri |
|
| 1937 | - * @param string $objectUri |
|
| 1938 | - * @return void |
|
| 1939 | - */ |
|
| 1940 | - function deleteSchedulingObject($principalUri, $objectUri) { |
|
| 1941 | - $query = $this->db->getQueryBuilder(); |
|
| 1942 | - $query->delete('schedulingobjects') |
|
| 1943 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
| 1944 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
| 1945 | - ->execute(); |
|
| 1946 | - } |
|
| 1947 | - |
|
| 1948 | - /** |
|
| 1949 | - * Creates a new scheduling object. This should land in a users' inbox. |
|
| 1950 | - * |
|
| 1951 | - * @param string $principalUri |
|
| 1952 | - * @param string $objectUri |
|
| 1953 | - * @param string $objectData |
|
| 1954 | - * @return void |
|
| 1955 | - */ |
|
| 1956 | - function createSchedulingObject($principalUri, $objectUri, $objectData) { |
|
| 1957 | - $query = $this->db->getQueryBuilder(); |
|
| 1958 | - $query->insert('schedulingobjects') |
|
| 1959 | - ->values([ |
|
| 1960 | - 'principaluri' => $query->createNamedParameter($principalUri), |
|
| 1961 | - 'calendardata' => $query->createNamedParameter($objectData), |
|
| 1962 | - 'uri' => $query->createNamedParameter($objectUri), |
|
| 1963 | - 'lastmodified' => $query->createNamedParameter(time()), |
|
| 1964 | - 'etag' => $query->createNamedParameter(md5($objectData)), |
|
| 1965 | - 'size' => $query->createNamedParameter(strlen($objectData)) |
|
| 1966 | - ]) |
|
| 1967 | - ->execute(); |
|
| 1968 | - } |
|
| 1969 | - |
|
| 1970 | - /** |
|
| 1971 | - * Adds a change record to the calendarchanges table. |
|
| 1972 | - * |
|
| 1973 | - * @param mixed $calendarId |
|
| 1974 | - * @param string $objectUri |
|
| 1975 | - * @param int $operation 1 = add, 2 = modify, 3 = delete. |
|
| 1976 | - * @return void |
|
| 1977 | - */ |
|
| 1978 | - protected function addChange($calendarId, $objectUri, $operation) { |
|
| 1979 | - |
|
| 1980 | - $stmt = $this->db->prepare('INSERT INTO `*PREFIX*calendarchanges` (`uri`, `synctoken`, `calendarid`, `operation`) SELECT ?, `synctoken`, ?, ? FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
| 1981 | - $stmt->execute([ |
|
| 1982 | - $objectUri, |
|
| 1983 | - $calendarId, |
|
| 1984 | - $operation, |
|
| 1985 | - $calendarId |
|
| 1986 | - ]); |
|
| 1987 | - $stmt = $this->db->prepare('UPDATE `*PREFIX*calendars` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?'); |
|
| 1988 | - $stmt->execute([ |
|
| 1989 | - $calendarId |
|
| 1990 | - ]); |
|
| 1991 | - |
|
| 1992 | - } |
|
| 1993 | - |
|
| 1994 | - /** |
|
| 1995 | - * Parses some information from calendar objects, used for optimized |
|
| 1996 | - * calendar-queries. |
|
| 1997 | - * |
|
| 1998 | - * Returns an array with the following keys: |
|
| 1999 | - * * etag - An md5 checksum of the object without the quotes. |
|
| 2000 | - * * size - Size of the object in bytes |
|
| 2001 | - * * componentType - VEVENT, VTODO or VJOURNAL |
|
| 2002 | - * * firstOccurence |
|
| 2003 | - * * lastOccurence |
|
| 2004 | - * * uid - value of the UID property |
|
| 2005 | - * |
|
| 2006 | - * @param string $calendarData |
|
| 2007 | - * @return array |
|
| 2008 | - */ |
|
| 2009 | - public function getDenormalizedData($calendarData) { |
|
| 2010 | - |
|
| 2011 | - $vObject = Reader::read($calendarData); |
|
| 2012 | - $componentType = null; |
|
| 2013 | - $component = null; |
|
| 2014 | - $firstOccurrence = null; |
|
| 2015 | - $lastOccurrence = null; |
|
| 2016 | - $uid = null; |
|
| 2017 | - $classification = self::CLASSIFICATION_PUBLIC; |
|
| 2018 | - foreach($vObject->getComponents() as $component) { |
|
| 2019 | - if ($component->name!=='VTIMEZONE') { |
|
| 2020 | - $componentType = $component->name; |
|
| 2021 | - $uid = (string)$component->UID; |
|
| 2022 | - break; |
|
| 2023 | - } |
|
| 2024 | - } |
|
| 2025 | - if (!$componentType) { |
|
| 2026 | - throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); |
|
| 2027 | - } |
|
| 2028 | - if ($componentType === 'VEVENT' && $component->DTSTART) { |
|
| 2029 | - $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
| 2030 | - // Finding the last occurrence is a bit harder |
|
| 2031 | - if (!isset($component->RRULE)) { |
|
| 2032 | - if (isset($component->DTEND)) { |
|
| 2033 | - $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
| 2034 | - } elseif (isset($component->DURATION)) { |
|
| 2035 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
| 2036 | - $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
| 2037 | - $lastOccurrence = $endDate->getTimeStamp(); |
|
| 2038 | - } elseif (!$component->DTSTART->hasTime()) { |
|
| 2039 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
| 2040 | - $endDate->modify('+1 day'); |
|
| 2041 | - $lastOccurrence = $endDate->getTimeStamp(); |
|
| 2042 | - } else { |
|
| 2043 | - $lastOccurrence = $firstOccurrence; |
|
| 2044 | - } |
|
| 2045 | - } else { |
|
| 2046 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
| 2047 | - $maxDate = new \DateTime(self::MAX_DATE); |
|
| 2048 | - if ($it->isInfinite()) { |
|
| 2049 | - $lastOccurrence = $maxDate->getTimestamp(); |
|
| 2050 | - } else { |
|
| 2051 | - $end = $it->getDtEnd(); |
|
| 2052 | - while($it->valid() && $end < $maxDate) { |
|
| 2053 | - $end = $it->getDtEnd(); |
|
| 2054 | - $it->next(); |
|
| 2055 | - |
|
| 2056 | - } |
|
| 2057 | - $lastOccurrence = $end->getTimestamp(); |
|
| 2058 | - } |
|
| 2059 | - |
|
| 2060 | - } |
|
| 2061 | - } |
|
| 2062 | - |
|
| 2063 | - if ($component->CLASS) { |
|
| 2064 | - $classification = CalDavBackend::CLASSIFICATION_PRIVATE; |
|
| 2065 | - switch ($component->CLASS->getValue()) { |
|
| 2066 | - case 'PUBLIC': |
|
| 2067 | - $classification = CalDavBackend::CLASSIFICATION_PUBLIC; |
|
| 2068 | - break; |
|
| 2069 | - case 'CONFIDENTIAL': |
|
| 2070 | - $classification = CalDavBackend::CLASSIFICATION_CONFIDENTIAL; |
|
| 2071 | - break; |
|
| 2072 | - } |
|
| 2073 | - } |
|
| 2074 | - return [ |
|
| 2075 | - 'etag' => md5($calendarData), |
|
| 2076 | - 'size' => strlen($calendarData), |
|
| 2077 | - 'componentType' => $componentType, |
|
| 2078 | - 'firstOccurence' => is_null($firstOccurrence) ? null : max(0, $firstOccurrence), |
|
| 2079 | - 'lastOccurence' => $lastOccurrence, |
|
| 2080 | - 'uid' => $uid, |
|
| 2081 | - 'classification' => $classification |
|
| 2082 | - ]; |
|
| 2083 | - |
|
| 2084 | - } |
|
| 2085 | - |
|
| 2086 | - private function readBlob($cardData) { |
|
| 2087 | - if (is_resource($cardData)) { |
|
| 2088 | - return stream_get_contents($cardData); |
|
| 2089 | - } |
|
| 2090 | - |
|
| 2091 | - return $cardData; |
|
| 2092 | - } |
|
| 2093 | - |
|
| 2094 | - /** |
|
| 2095 | - * @param IShareable $shareable |
|
| 2096 | - * @param array $add |
|
| 2097 | - * @param array $remove |
|
| 2098 | - */ |
|
| 2099 | - public function updateShares($shareable, $add, $remove) { |
|
| 2100 | - $calendarId = $shareable->getResourceId(); |
|
| 2101 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent( |
|
| 2102 | - '\OCA\DAV\CalDAV\CalDavBackend::updateShares', |
|
| 2103 | - [ |
|
| 2104 | - 'calendarId' => $calendarId, |
|
| 2105 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
| 2106 | - 'shares' => $this->getShares($calendarId), |
|
| 2107 | - 'add' => $add, |
|
| 2108 | - 'remove' => $remove, |
|
| 2109 | - ])); |
|
| 2110 | - $this->sharingBackend->updateShares($shareable, $add, $remove); |
|
| 2111 | - } |
|
| 2112 | - |
|
| 2113 | - /** |
|
| 2114 | - * @param int $resourceId |
|
| 2115 | - * @return array |
|
| 2116 | - */ |
|
| 2117 | - public function getShares($resourceId) { |
|
| 2118 | - return $this->sharingBackend->getShares($resourceId); |
|
| 2119 | - } |
|
| 2120 | - |
|
| 2121 | - /** |
|
| 2122 | - * @param boolean $value |
|
| 2123 | - * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
| 2124 | - * @return string|null |
|
| 2125 | - */ |
|
| 2126 | - public function setPublishStatus($value, $calendar) { |
|
| 2127 | - $query = $this->db->getQueryBuilder(); |
|
| 2128 | - if ($value) { |
|
| 2129 | - $publicUri = $this->random->generate(16, ISecureRandom::CHAR_HUMAN_READABLE); |
|
| 2130 | - $query->insert('dav_shares') |
|
| 2131 | - ->values([ |
|
| 2132 | - 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), |
|
| 2133 | - 'type' => $query->createNamedParameter('calendar'), |
|
| 2134 | - 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), |
|
| 2135 | - 'resourceid' => $query->createNamedParameter($calendar->getResourceId()), |
|
| 2136 | - 'publicuri' => $query->createNamedParameter($publicUri) |
|
| 2137 | - ]); |
|
| 2138 | - $query->execute(); |
|
| 2139 | - return $publicUri; |
|
| 2140 | - } |
|
| 2141 | - $query->delete('dav_shares') |
|
| 2142 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
| 2143 | - ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); |
|
| 2144 | - $query->execute(); |
|
| 2145 | - return null; |
|
| 2146 | - } |
|
| 2147 | - |
|
| 2148 | - /** |
|
| 2149 | - * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
| 2150 | - * @return mixed |
|
| 2151 | - */ |
|
| 2152 | - public function getPublishStatus($calendar) { |
|
| 2153 | - $query = $this->db->getQueryBuilder(); |
|
| 2154 | - $result = $query->select('publicuri') |
|
| 2155 | - ->from('dav_shares') |
|
| 2156 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
| 2157 | - ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
| 2158 | - ->execute(); |
|
| 2159 | - |
|
| 2160 | - $row = $result->fetch(); |
|
| 2161 | - $result->closeCursor(); |
|
| 2162 | - return $row ? reset($row) : false; |
|
| 2163 | - } |
|
| 2164 | - |
|
| 2165 | - /** |
|
| 2166 | - * @param int $resourceId |
|
| 2167 | - * @param array $acl |
|
| 2168 | - * @return array |
|
| 2169 | - */ |
|
| 2170 | - public function applyShareAcl($resourceId, $acl) { |
|
| 2171 | - return $this->sharingBackend->applyShareAcl($resourceId, $acl); |
|
| 2172 | - } |
|
| 2173 | - |
|
| 2174 | - |
|
| 2175 | - |
|
| 2176 | - /** |
|
| 2177 | - * update properties table |
|
| 2178 | - * |
|
| 2179 | - * @param int $calendarId |
|
| 2180 | - * @param string $objectUri |
|
| 2181 | - * @param string $calendarData |
|
| 2182 | - */ |
|
| 2183 | - public function updateProperties($calendarId, $objectUri, $calendarData) { |
|
| 2184 | - $objectId = $this->getCalendarObjectId($calendarId, $objectUri); |
|
| 2185 | - |
|
| 2186 | - try { |
|
| 2187 | - $vCalendar = $this->readCalendarData($calendarData); |
|
| 2188 | - } catch (\Exception $ex) { |
|
| 2189 | - return; |
|
| 2190 | - } |
|
| 2191 | - |
|
| 2192 | - $this->purgeProperties($calendarId, $objectId); |
|
| 2193 | - |
|
| 2194 | - $query = $this->db->getQueryBuilder(); |
|
| 2195 | - $query->insert($this->dbObjectPropertiesTable) |
|
| 2196 | - ->values( |
|
| 2197 | - [ |
|
| 2198 | - 'calendarid' => $query->createNamedParameter($calendarId), |
|
| 2199 | - 'objectid' => $query->createNamedParameter($objectId), |
|
| 2200 | - 'name' => $query->createParameter('name'), |
|
| 2201 | - 'parameter' => $query->createParameter('parameter'), |
|
| 2202 | - 'value' => $query->createParameter('value'), |
|
| 2203 | - ] |
|
| 2204 | - ); |
|
| 2205 | - |
|
| 2206 | - $indexComponents = ['VEVENT', 'VJOURNAL', 'VTODO']; |
|
| 2207 | - foreach ($vCalendar->getComponents() as $component) { |
|
| 2208 | - if (!in_array($component->name, $indexComponents)) { |
|
| 2209 | - continue; |
|
| 2210 | - } |
|
| 2211 | - |
|
| 2212 | - foreach ($component->children() as $property) { |
|
| 2213 | - if (in_array($property->name, self::$indexProperties)) { |
|
| 2214 | - $value = $property->getValue(); |
|
| 2215 | - // is this a shitty db? |
|
| 2216 | - if (!$this->db->supports4ByteText()) { |
|
| 2217 | - $value = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $value); |
|
| 2218 | - } |
|
| 2219 | - $value = substr($value, 0, 254); |
|
| 2220 | - |
|
| 2221 | - $query->setParameter('name', $property->name); |
|
| 2222 | - $query->setParameter('parameter', null); |
|
| 2223 | - $query->setParameter('value', $value); |
|
| 2224 | - $query->execute(); |
|
| 2225 | - } |
|
| 2226 | - |
|
| 2227 | - if (in_array($property->name, array_keys(self::$indexParameters))) { |
|
| 2228 | - $parameters = $property->parameters(); |
|
| 2229 | - $indexedParametersForProperty = self::$indexParameters[$property->name]; |
|
| 2230 | - |
|
| 2231 | - foreach ($parameters as $key => $value) { |
|
| 2232 | - if (in_array($key, $indexedParametersForProperty)) { |
|
| 2233 | - // is this a shitty db? |
|
| 2234 | - if ($this->db->supports4ByteText()) { |
|
| 2235 | - $value = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $value); |
|
| 2236 | - } |
|
| 2237 | - $value = substr($value, 0, 254); |
|
| 2238 | - |
|
| 2239 | - $query->setParameter('name', $property->name); |
|
| 2240 | - $query->setParameter('parameter', substr($key, 0, 254)); |
|
| 2241 | - $query->setParameter('value', substr($value, 0, 254)); |
|
| 2242 | - $query->execute(); |
|
| 2243 | - } |
|
| 2244 | - } |
|
| 2245 | - } |
|
| 2246 | - } |
|
| 2247 | - } |
|
| 2248 | - } |
|
| 2249 | - |
|
| 2250 | - /** |
|
| 2251 | - * read VCalendar data into a VCalendar object |
|
| 2252 | - * |
|
| 2253 | - * @param string $objectData |
|
| 2254 | - * @return VCalendar |
|
| 2255 | - */ |
|
| 2256 | - protected function readCalendarData($objectData) { |
|
| 2257 | - return Reader::read($objectData); |
|
| 2258 | - } |
|
| 2259 | - |
|
| 2260 | - /** |
|
| 2261 | - * delete all properties from a given calendar object |
|
| 2262 | - * |
|
| 2263 | - * @param int $calendarId |
|
| 2264 | - * @param int $objectId |
|
| 2265 | - */ |
|
| 2266 | - protected function purgeProperties($calendarId, $objectId) { |
|
| 2267 | - $query = $this->db->getQueryBuilder(); |
|
| 2268 | - $query->delete($this->dbObjectPropertiesTable) |
|
| 2269 | - ->where($query->expr()->eq('objectid', $query->createNamedParameter($objectId))) |
|
| 2270 | - ->andWhere($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
| 2271 | - $query->execute(); |
|
| 2272 | - } |
|
| 2273 | - |
|
| 2274 | - /** |
|
| 2275 | - * get ID from a given calendar object |
|
| 2276 | - * |
|
| 2277 | - * @param int $calendarId |
|
| 2278 | - * @param string $uri |
|
| 2279 | - * @return int |
|
| 2280 | - */ |
|
| 2281 | - protected function getCalendarObjectId($calendarId, $uri) { |
|
| 2282 | - $query = $this->db->getQueryBuilder(); |
|
| 2283 | - $query->select('id')->from('calendarobjects') |
|
| 2284 | - ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
| 2285 | - ->andWhere($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
| 2286 | - |
|
| 2287 | - $result = $query->execute(); |
|
| 2288 | - $objectIds = $result->fetch(); |
|
| 2289 | - $result->closeCursor(); |
|
| 2290 | - |
|
| 2291 | - if (!isset($objectIds['id'])) { |
|
| 2292 | - throw new \InvalidArgumentException('Calendarobject does not exists: ' . $uri); |
|
| 2293 | - } |
|
| 2294 | - |
|
| 2295 | - return (int)$objectIds['id']; |
|
| 2296 | - } |
|
| 2297 | - |
|
| 2298 | - private function convertPrincipal($principalUri, $toV2) { |
|
| 2299 | - if ($this->principalBackend->getPrincipalPrefix() === 'principals') { |
|
| 2300 | - list(, $name) = Uri\split($principalUri); |
|
| 2301 | - if ($toV2 === true) { |
|
| 2302 | - return "principals/users/$name"; |
|
| 2303 | - } |
|
| 2304 | - return "principals/$name"; |
|
| 2305 | - } |
|
| 2306 | - return $principalUri; |
|
| 2307 | - } |
|
| 2308 | - |
|
| 2309 | - private function addOwnerPrincipal(&$calendarInfo) { |
|
| 2310 | - $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'; |
|
| 2311 | - $displaynameKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'; |
|
| 2312 | - if (isset($calendarInfo[$ownerPrincipalKey])) { |
|
| 2313 | - $uri = $calendarInfo[$ownerPrincipalKey]; |
|
| 2314 | - } else { |
|
| 2315 | - $uri = $calendarInfo['principaluri']; |
|
| 2316 | - } |
|
| 2317 | - |
|
| 2318 | - $principalInformation = $this->principalBackend->getPrincipalByPath($uri); |
|
| 2319 | - if (isset($principalInformation['{DAV:}displayname'])) { |
|
| 2320 | - $calendarInfo[$displaynameKey] = $principalInformation['{DAV:}displayname']; |
|
| 2321 | - } |
|
| 2322 | - } |
|
| 424 | + /** |
|
| 425 | + * @return array |
|
| 426 | + */ |
|
| 427 | + public function getPublicCalendars() { |
|
| 428 | + $fields = array_values($this->propertyMap); |
|
| 429 | + $fields[] = 'a.id'; |
|
| 430 | + $fields[] = 'a.uri'; |
|
| 431 | + $fields[] = 'a.synctoken'; |
|
| 432 | + $fields[] = 'a.components'; |
|
| 433 | + $fields[] = 'a.principaluri'; |
|
| 434 | + $fields[] = 'a.transparent'; |
|
| 435 | + $fields[] = 's.access'; |
|
| 436 | + $fields[] = 's.publicuri'; |
|
| 437 | + $calendars = []; |
|
| 438 | + $query = $this->db->getQueryBuilder(); |
|
| 439 | + $result = $query->select($fields) |
|
| 440 | + ->from('dav_shares', 's') |
|
| 441 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
| 442 | + ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
| 443 | + ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
| 444 | + ->execute(); |
|
| 445 | + |
|
| 446 | + while($row = $result->fetch()) { |
|
| 447 | + list(, $name) = Uri\split($row['principaluri']); |
|
| 448 | + $row['displayname'] = $row['displayname'] . "($name)"; |
|
| 449 | + $components = []; |
|
| 450 | + if ($row['components']) { |
|
| 451 | + $components = explode(',',$row['components']); |
|
| 452 | + } |
|
| 453 | + $calendar = [ |
|
| 454 | + 'id' => $row['id'], |
|
| 455 | + 'uri' => $row['publicuri'], |
|
| 456 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 457 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 458 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 459 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 460 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 461 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
| 462 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
| 463 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
| 464 | + ]; |
|
| 465 | + |
|
| 466 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 467 | + $calendar[$xmlName] = $row[$dbName]; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $this->addOwnerPrincipal($calendar); |
|
| 471 | + |
|
| 472 | + if (!isset($calendars[$calendar['id']])) { |
|
| 473 | + $calendars[$calendar['id']] = $calendar; |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + $result->closeCursor(); |
|
| 477 | + |
|
| 478 | + return array_values($calendars); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @param string $uri |
|
| 483 | + * @return array |
|
| 484 | + * @throws NotFound |
|
| 485 | + */ |
|
| 486 | + public function getPublicCalendar($uri) { |
|
| 487 | + $fields = array_values($this->propertyMap); |
|
| 488 | + $fields[] = 'a.id'; |
|
| 489 | + $fields[] = 'a.uri'; |
|
| 490 | + $fields[] = 'a.synctoken'; |
|
| 491 | + $fields[] = 'a.components'; |
|
| 492 | + $fields[] = 'a.principaluri'; |
|
| 493 | + $fields[] = 'a.transparent'; |
|
| 494 | + $fields[] = 's.access'; |
|
| 495 | + $fields[] = 's.publicuri'; |
|
| 496 | + $query = $this->db->getQueryBuilder(); |
|
| 497 | + $result = $query->select($fields) |
|
| 498 | + ->from('dav_shares', 's') |
|
| 499 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
| 500 | + ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
| 501 | + ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
| 502 | + ->andWhere($query->expr()->eq('s.publicuri', $query->createNamedParameter($uri))) |
|
| 503 | + ->execute(); |
|
| 504 | + |
|
| 505 | + $row = $result->fetch(\PDO::FETCH_ASSOC); |
|
| 506 | + |
|
| 507 | + $result->closeCursor(); |
|
| 508 | + |
|
| 509 | + if ($row === false) { |
|
| 510 | + throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + list(, $name) = Uri\split($row['principaluri']); |
|
| 514 | + $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
| 515 | + $components = []; |
|
| 516 | + if ($row['components']) { |
|
| 517 | + $components = explode(',',$row['components']); |
|
| 518 | + } |
|
| 519 | + $calendar = [ |
|
| 520 | + 'id' => $row['id'], |
|
| 521 | + 'uri' => $row['publicuri'], |
|
| 522 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 523 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 524 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 525 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 526 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 527 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 528 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
| 529 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
| 530 | + ]; |
|
| 531 | + |
|
| 532 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 533 | + $calendar[$xmlName] = $row[$dbName]; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + $this->addOwnerPrincipal($calendar); |
|
| 537 | + |
|
| 538 | + return $calendar; |
|
| 539 | + |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * @param string $principal |
|
| 544 | + * @param string $uri |
|
| 545 | + * @return array|null |
|
| 546 | + */ |
|
| 547 | + public function getCalendarByUri($principal, $uri) { |
|
| 548 | + $fields = array_values($this->propertyMap); |
|
| 549 | + $fields[] = 'id'; |
|
| 550 | + $fields[] = 'uri'; |
|
| 551 | + $fields[] = 'synctoken'; |
|
| 552 | + $fields[] = 'components'; |
|
| 553 | + $fields[] = 'principaluri'; |
|
| 554 | + $fields[] = 'transparent'; |
|
| 555 | + |
|
| 556 | + // Making fields a comma-delimited list |
|
| 557 | + $query = $this->db->getQueryBuilder(); |
|
| 558 | + $query->select($fields)->from('calendars') |
|
| 559 | + ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
| 560 | + ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) |
|
| 561 | + ->setMaxResults(1); |
|
| 562 | + $stmt = $query->execute(); |
|
| 563 | + |
|
| 564 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 565 | + $stmt->closeCursor(); |
|
| 566 | + if ($row === false) { |
|
| 567 | + return null; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + $components = []; |
|
| 571 | + if ($row['components']) { |
|
| 572 | + $components = explode(',',$row['components']); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + $calendar = [ |
|
| 576 | + 'id' => $row['id'], |
|
| 577 | + 'uri' => $row['uri'], |
|
| 578 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 579 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 580 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 581 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 582 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 583 | + ]; |
|
| 584 | + |
|
| 585 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 586 | + $calendar[$xmlName] = $row[$dbName]; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + $this->addOwnerPrincipal($calendar); |
|
| 590 | + |
|
| 591 | + return $calendar; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + public function getCalendarById($calendarId) { |
|
| 595 | + $fields = array_values($this->propertyMap); |
|
| 596 | + $fields[] = 'id'; |
|
| 597 | + $fields[] = 'uri'; |
|
| 598 | + $fields[] = 'synctoken'; |
|
| 599 | + $fields[] = 'components'; |
|
| 600 | + $fields[] = 'principaluri'; |
|
| 601 | + $fields[] = 'transparent'; |
|
| 602 | + |
|
| 603 | + // Making fields a comma-delimited list |
|
| 604 | + $query = $this->db->getQueryBuilder(); |
|
| 605 | + $query->select($fields)->from('calendars') |
|
| 606 | + ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))) |
|
| 607 | + ->setMaxResults(1); |
|
| 608 | + $stmt = $query->execute(); |
|
| 609 | + |
|
| 610 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 611 | + $stmt->closeCursor(); |
|
| 612 | + if ($row === false) { |
|
| 613 | + return null; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + $components = []; |
|
| 617 | + if ($row['components']) { |
|
| 618 | + $components = explode(',',$row['components']); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + $calendar = [ |
|
| 622 | + 'id' => $row['id'], |
|
| 623 | + 'uri' => $row['uri'], |
|
| 624 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 625 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 626 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 627 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 628 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 629 | + ]; |
|
| 630 | + |
|
| 631 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 632 | + $calendar[$xmlName] = $row[$dbName]; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + $this->addOwnerPrincipal($calendar); |
|
| 636 | + |
|
| 637 | + return $calendar; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * Creates a new calendar for a principal. |
|
| 642 | + * |
|
| 643 | + * If the creation was a success, an id must be returned that can be used to reference |
|
| 644 | + * this calendar in other methods, such as updateCalendar. |
|
| 645 | + * |
|
| 646 | + * @param string $principalUri |
|
| 647 | + * @param string $calendarUri |
|
| 648 | + * @param array $properties |
|
| 649 | + * @return int |
|
| 650 | + * @suppress SqlInjectionChecker |
|
| 651 | + */ |
|
| 652 | + function createCalendar($principalUri, $calendarUri, array $properties) { |
|
| 653 | + $values = [ |
|
| 654 | + 'principaluri' => $this->convertPrincipal($principalUri, true), |
|
| 655 | + 'uri' => $calendarUri, |
|
| 656 | + 'synctoken' => 1, |
|
| 657 | + 'transparent' => 0, |
|
| 658 | + 'components' => 'VEVENT,VTODO', |
|
| 659 | + 'displayname' => $calendarUri |
|
| 660 | + ]; |
|
| 661 | + |
|
| 662 | + // Default value |
|
| 663 | + $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
|
| 664 | + if (isset($properties[$sccs])) { |
|
| 665 | + if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
|
| 666 | + throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
| 667 | + } |
|
| 668 | + $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
| 669 | + } |
|
| 670 | + $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
| 671 | + if (isset($properties[$transp])) { |
|
| 672 | + $values['transparent'] = (int) ($properties[$transp]->getValue() === 'transparent'); |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 676 | + if (isset($properties[$xmlName])) { |
|
| 677 | + $values[$dbName] = $properties[$xmlName]; |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + $query = $this->db->getQueryBuilder(); |
|
| 682 | + $query->insert('calendars'); |
|
| 683 | + foreach($values as $column => $value) { |
|
| 684 | + $query->setValue($column, $query->createNamedParameter($value)); |
|
| 685 | + } |
|
| 686 | + $query->execute(); |
|
| 687 | + $calendarId = $query->getLastInsertId(); |
|
| 688 | + |
|
| 689 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent( |
|
| 690 | + '\OCA\DAV\CalDAV\CalDavBackend::createCalendar', |
|
| 691 | + [ |
|
| 692 | + 'calendarId' => $calendarId, |
|
| 693 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
| 694 | + ])); |
|
| 695 | + |
|
| 696 | + return $calendarId; |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * Updates properties for a calendar. |
|
| 701 | + * |
|
| 702 | + * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
| 703 | + * To do the actual updates, you must tell this object which properties |
|
| 704 | + * you're going to process with the handle() method. |
|
| 705 | + * |
|
| 706 | + * Calling the handle method is like telling the PropPatch object "I |
|
| 707 | + * promise I can handle updating this property". |
|
| 708 | + * |
|
| 709 | + * Read the PropPatch documentation for more info and examples. |
|
| 710 | + * |
|
| 711 | + * @param mixed $calendarId |
|
| 712 | + * @param PropPatch $propPatch |
|
| 713 | + * @return void |
|
| 714 | + */ |
|
| 715 | + function updateCalendar($calendarId, PropPatch $propPatch) { |
|
| 716 | + $supportedProperties = array_keys($this->propertyMap); |
|
| 717 | + $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * @suppress SqlInjectionChecker |
|
| 721 | + */ |
|
| 722 | + $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
|
| 723 | + $newValues = []; |
|
| 724 | + foreach ($mutations as $propertyName => $propertyValue) { |
|
| 725 | + |
|
| 726 | + switch ($propertyName) { |
|
| 727 | + case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
| 728 | + $fieldName = 'transparent'; |
|
| 729 | + $newValues[$fieldName] = (int) ($propertyValue->getValue() === 'transparent'); |
|
| 730 | + break; |
|
| 731 | + default : |
|
| 732 | + $fieldName = $this->propertyMap[$propertyName]; |
|
| 733 | + $newValues[$fieldName] = $propertyValue; |
|
| 734 | + break; |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + } |
|
| 738 | + $query = $this->db->getQueryBuilder(); |
|
| 739 | + $query->update('calendars'); |
|
| 740 | + foreach ($newValues as $fieldName => $value) { |
|
| 741 | + $query->set($fieldName, $query->createNamedParameter($value)); |
|
| 742 | + } |
|
| 743 | + $query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); |
|
| 744 | + $query->execute(); |
|
| 745 | + |
|
| 746 | + $this->addChange($calendarId, "", 2); |
|
| 747 | + |
|
| 748 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent( |
|
| 749 | + '\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', |
|
| 750 | + [ |
|
| 751 | + 'calendarId' => $calendarId, |
|
| 752 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
| 753 | + 'shares' => $this->getShares($calendarId), |
|
| 754 | + 'propertyMutations' => $mutations, |
|
| 755 | + ])); |
|
| 756 | + |
|
| 757 | + return true; |
|
| 758 | + }); |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + /** |
|
| 762 | + * Delete a calendar and all it's objects |
|
| 763 | + * |
|
| 764 | + * @param mixed $calendarId |
|
| 765 | + * @return void |
|
| 766 | + */ |
|
| 767 | + function deleteCalendar($calendarId) { |
|
| 768 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', new GenericEvent( |
|
| 769 | + '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', |
|
| 770 | + [ |
|
| 771 | + 'calendarId' => $calendarId, |
|
| 772 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
| 773 | + 'shares' => $this->getShares($calendarId), |
|
| 774 | + ])); |
|
| 775 | + |
|
| 776 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?'); |
|
| 777 | + $stmt->execute([$calendarId]); |
|
| 778 | + |
|
| 779 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
| 780 | + $stmt->execute([$calendarId]); |
|
| 781 | + |
|
| 782 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarchanges` WHERE `calendarid` = ?'); |
|
| 783 | + $stmt->execute([$calendarId]); |
|
| 784 | + |
|
| 785 | + $this->sharingBackend->deleteAllShares($calendarId); |
|
| 786 | + |
|
| 787 | + $query = $this->db->getQueryBuilder(); |
|
| 788 | + $query->delete($this->dbObjectPropertiesTable) |
|
| 789 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
| 790 | + ->execute(); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * Delete all of an user's shares |
|
| 795 | + * |
|
| 796 | + * @param string $principaluri |
|
| 797 | + * @return void |
|
| 798 | + */ |
|
| 799 | + function deleteAllSharesByUser($principaluri) { |
|
| 800 | + $this->sharingBackend->deleteAllSharesByUser($principaluri); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * Returns all calendar objects within a calendar. |
|
| 805 | + * |
|
| 806 | + * Every item contains an array with the following keys: |
|
| 807 | + * * calendardata - The iCalendar-compatible calendar data |
|
| 808 | + * * uri - a unique key which will be used to construct the uri. This can |
|
| 809 | + * be any arbitrary string, but making sure it ends with '.ics' is a |
|
| 810 | + * good idea. This is only the basename, or filename, not the full |
|
| 811 | + * path. |
|
| 812 | + * * lastmodified - a timestamp of the last modification time |
|
| 813 | + * * etag - An arbitrary string, surrounded by double-quotes. (e.g.: |
|
| 814 | + * '"abcdef"') |
|
| 815 | + * * size - The size of the calendar objects, in bytes. |
|
| 816 | + * * component - optional, a string containing the type of object, such |
|
| 817 | + * as 'vevent' or 'vtodo'. If specified, this will be used to populate |
|
| 818 | + * the Content-Type header. |
|
| 819 | + * |
|
| 820 | + * Note that the etag is optional, but it's highly encouraged to return for |
|
| 821 | + * speed reasons. |
|
| 822 | + * |
|
| 823 | + * The calendardata is also optional. If it's not returned |
|
| 824 | + * 'getCalendarObject' will be called later, which *is* expected to return |
|
| 825 | + * calendardata. |
|
| 826 | + * |
|
| 827 | + * If neither etag or size are specified, the calendardata will be |
|
| 828 | + * used/fetched to determine these numbers. If both are specified the |
|
| 829 | + * amount of times this is needed is reduced by a great degree. |
|
| 830 | + * |
|
| 831 | + * @param mixed $calendarId |
|
| 832 | + * @return array |
|
| 833 | + */ |
|
| 834 | + function getCalendarObjects($calendarId) { |
|
| 835 | + $query = $this->db->getQueryBuilder(); |
|
| 836 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'componenttype', 'classification']) |
|
| 837 | + ->from('calendarobjects') |
|
| 838 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
| 839 | + $stmt = $query->execute(); |
|
| 840 | + |
|
| 841 | + $result = []; |
|
| 842 | + foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
| 843 | + $result[] = [ |
|
| 844 | + 'id' => $row['id'], |
|
| 845 | + 'uri' => $row['uri'], |
|
| 846 | + 'lastmodified' => $row['lastmodified'], |
|
| 847 | + 'etag' => '"' . $row['etag'] . '"', |
|
| 848 | + 'calendarid' => $row['calendarid'], |
|
| 849 | + 'size' => (int)$row['size'], |
|
| 850 | + 'component' => strtolower($row['componenttype']), |
|
| 851 | + 'classification'=> (int)$row['classification'] |
|
| 852 | + ]; |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + return $result; |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * Returns information from a single calendar object, based on it's object |
|
| 860 | + * uri. |
|
| 861 | + * |
|
| 862 | + * The object uri is only the basename, or filename and not a full path. |
|
| 863 | + * |
|
| 864 | + * The returned array must have the same keys as getCalendarObjects. The |
|
| 865 | + * 'calendardata' object is required here though, while it's not required |
|
| 866 | + * for getCalendarObjects. |
|
| 867 | + * |
|
| 868 | + * This method must return null if the object did not exist. |
|
| 869 | + * |
|
| 870 | + * @param mixed $calendarId |
|
| 871 | + * @param string $objectUri |
|
| 872 | + * @return array|null |
|
| 873 | + */ |
|
| 874 | + function getCalendarObject($calendarId, $objectUri) { |
|
| 875 | + |
|
| 876 | + $query = $this->db->getQueryBuilder(); |
|
| 877 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
| 878 | + ->from('calendarobjects') |
|
| 879 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
| 880 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))); |
|
| 881 | + $stmt = $query->execute(); |
|
| 882 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 883 | + |
|
| 884 | + if(!$row) return null; |
|
| 885 | + |
|
| 886 | + return [ |
|
| 887 | + 'id' => $row['id'], |
|
| 888 | + 'uri' => $row['uri'], |
|
| 889 | + 'lastmodified' => $row['lastmodified'], |
|
| 890 | + 'etag' => '"' . $row['etag'] . '"', |
|
| 891 | + 'calendarid' => $row['calendarid'], |
|
| 892 | + 'size' => (int)$row['size'], |
|
| 893 | + 'calendardata' => $this->readBlob($row['calendardata']), |
|
| 894 | + 'component' => strtolower($row['componenttype']), |
|
| 895 | + 'classification'=> (int)$row['classification'] |
|
| 896 | + ]; |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * Returns a list of calendar objects. |
|
| 901 | + * |
|
| 902 | + * This method should work identical to getCalendarObject, but instead |
|
| 903 | + * return all the calendar objects in the list as an array. |
|
| 904 | + * |
|
| 905 | + * If the backend supports this, it may allow for some speed-ups. |
|
| 906 | + * |
|
| 907 | + * @param mixed $calendarId |
|
| 908 | + * @param string[] $uris |
|
| 909 | + * @return array |
|
| 910 | + */ |
|
| 911 | + function getMultipleCalendarObjects($calendarId, array $uris) { |
|
| 912 | + if (empty($uris)) { |
|
| 913 | + return []; |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + $chunks = array_chunk($uris, 100); |
|
| 917 | + $objects = []; |
|
| 918 | + |
|
| 919 | + $query = $this->db->getQueryBuilder(); |
|
| 920 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
| 921 | + ->from('calendarobjects') |
|
| 922 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
| 923 | + ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); |
|
| 924 | + |
|
| 925 | + foreach ($chunks as $uris) { |
|
| 926 | + $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); |
|
| 927 | + $result = $query->execute(); |
|
| 928 | + |
|
| 929 | + while ($row = $result->fetch()) { |
|
| 930 | + $objects[] = [ |
|
| 931 | + 'id' => $row['id'], |
|
| 932 | + 'uri' => $row['uri'], |
|
| 933 | + 'lastmodified' => $row['lastmodified'], |
|
| 934 | + 'etag' => '"' . $row['etag'] . '"', |
|
| 935 | + 'calendarid' => $row['calendarid'], |
|
| 936 | + 'size' => (int)$row['size'], |
|
| 937 | + 'calendardata' => $this->readBlob($row['calendardata']), |
|
| 938 | + 'component' => strtolower($row['componenttype']), |
|
| 939 | + 'classification' => (int)$row['classification'] |
|
| 940 | + ]; |
|
| 941 | + } |
|
| 942 | + $result->closeCursor(); |
|
| 943 | + } |
|
| 944 | + return $objects; |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + /** |
|
| 948 | + * Creates a new calendar object. |
|
| 949 | + * |
|
| 950 | + * The object uri is only the basename, or filename and not a full path. |
|
| 951 | + * |
|
| 952 | + * It is possible return an etag from this function, which will be used in |
|
| 953 | + * the response to this PUT request. Note that the ETag must be surrounded |
|
| 954 | + * by double-quotes. |
|
| 955 | + * |
|
| 956 | + * However, you should only really return this ETag if you don't mangle the |
|
| 957 | + * calendar-data. If the result of a subsequent GET to this object is not |
|
| 958 | + * the exact same as this request body, you should omit the ETag. |
|
| 959 | + * |
|
| 960 | + * @param mixed $calendarId |
|
| 961 | + * @param string $objectUri |
|
| 962 | + * @param string $calendarData |
|
| 963 | + * @return string |
|
| 964 | + */ |
|
| 965 | + function createCalendarObject($calendarId, $objectUri, $calendarData) { |
|
| 966 | + $extraData = $this->getDenormalizedData($calendarData); |
|
| 967 | + |
|
| 968 | + $q = $this->db->getQueryBuilder(); |
|
| 969 | + $q->select($q->createFunction('COUNT(*)')) |
|
| 970 | + ->from('calendarobjects') |
|
| 971 | + ->where($q->expr()->eq('calendarid', $q->createNamedParameter($calendarId))) |
|
| 972 | + ->andWhere($q->expr()->eq('uid', $q->createNamedParameter($extraData['uid']))); |
|
| 973 | + |
|
| 974 | + $result = $q->execute(); |
|
| 975 | + $count = (int) $result->fetchColumn(); |
|
| 976 | + $result->closeCursor(); |
|
| 977 | + |
|
| 978 | + if ($count !== 0) { |
|
| 979 | + throw new \Sabre\DAV\Exception\BadRequest('Calendar object with uid already exists in this calendar collection.'); |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + $query = $this->db->getQueryBuilder(); |
|
| 983 | + $query->insert('calendarobjects') |
|
| 984 | + ->values([ |
|
| 985 | + 'calendarid' => $query->createNamedParameter($calendarId), |
|
| 986 | + 'uri' => $query->createNamedParameter($objectUri), |
|
| 987 | + 'calendardata' => $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB), |
|
| 988 | + 'lastmodified' => $query->createNamedParameter(time()), |
|
| 989 | + 'etag' => $query->createNamedParameter($extraData['etag']), |
|
| 990 | + 'size' => $query->createNamedParameter($extraData['size']), |
|
| 991 | + 'componenttype' => $query->createNamedParameter($extraData['componentType']), |
|
| 992 | + 'firstoccurence' => $query->createNamedParameter($extraData['firstOccurence']), |
|
| 993 | + 'lastoccurence' => $query->createNamedParameter($extraData['lastOccurence']), |
|
| 994 | + 'classification' => $query->createNamedParameter($extraData['classification']), |
|
| 995 | + 'uid' => $query->createNamedParameter($extraData['uid']), |
|
| 996 | + ]) |
|
| 997 | + ->execute(); |
|
| 998 | + |
|
| 999 | + $this->updateProperties($calendarId, $objectUri, $calendarData); |
|
| 1000 | + |
|
| 1001 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( |
|
| 1002 | + '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', |
|
| 1003 | + [ |
|
| 1004 | + 'calendarId' => $calendarId, |
|
| 1005 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
| 1006 | + 'shares' => $this->getShares($calendarId), |
|
| 1007 | + 'objectData' => $this->getCalendarObject($calendarId, $objectUri), |
|
| 1008 | + ] |
|
| 1009 | + )); |
|
| 1010 | + $this->addChange($calendarId, $objectUri, 1); |
|
| 1011 | + |
|
| 1012 | + return '"' . $extraData['etag'] . '"'; |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + /** |
|
| 1016 | + * Updates an existing calendarobject, based on it's uri. |
|
| 1017 | + * |
|
| 1018 | + * The object uri is only the basename, or filename and not a full path. |
|
| 1019 | + * |
|
| 1020 | + * It is possible return an etag from this function, which will be used in |
|
| 1021 | + * the response to this PUT request. Note that the ETag must be surrounded |
|
| 1022 | + * by double-quotes. |
|
| 1023 | + * |
|
| 1024 | + * However, you should only really return this ETag if you don't mangle the |
|
| 1025 | + * calendar-data. If the result of a subsequent GET to this object is not |
|
| 1026 | + * the exact same as this request body, you should omit the ETag. |
|
| 1027 | + * |
|
| 1028 | + * @param mixed $calendarId |
|
| 1029 | + * @param string $objectUri |
|
| 1030 | + * @param string $calendarData |
|
| 1031 | + * @return string |
|
| 1032 | + */ |
|
| 1033 | + function updateCalendarObject($calendarId, $objectUri, $calendarData) { |
|
| 1034 | + $extraData = $this->getDenormalizedData($calendarData); |
|
| 1035 | + |
|
| 1036 | + $query = $this->db->getQueryBuilder(); |
|
| 1037 | + $query->update('calendarobjects') |
|
| 1038 | + ->set('calendardata', $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB)) |
|
| 1039 | + ->set('lastmodified', $query->createNamedParameter(time())) |
|
| 1040 | + ->set('etag', $query->createNamedParameter($extraData['etag'])) |
|
| 1041 | + ->set('size', $query->createNamedParameter($extraData['size'])) |
|
| 1042 | + ->set('componenttype', $query->createNamedParameter($extraData['componentType'])) |
|
| 1043 | + ->set('firstoccurence', $query->createNamedParameter($extraData['firstOccurence'])) |
|
| 1044 | + ->set('lastoccurence', $query->createNamedParameter($extraData['lastOccurence'])) |
|
| 1045 | + ->set('classification', $query->createNamedParameter($extraData['classification'])) |
|
| 1046 | + ->set('uid', $query->createNamedParameter($extraData['uid'])) |
|
| 1047 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
| 1048 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
| 1049 | + ->execute(); |
|
| 1050 | + |
|
| 1051 | + $this->updateProperties($calendarId, $objectUri, $calendarData); |
|
| 1052 | + |
|
| 1053 | + $data = $this->getCalendarObject($calendarId, $objectUri); |
|
| 1054 | + if (is_array($data)) { |
|
| 1055 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( |
|
| 1056 | + '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', |
|
| 1057 | + [ |
|
| 1058 | + 'calendarId' => $calendarId, |
|
| 1059 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
| 1060 | + 'shares' => $this->getShares($calendarId), |
|
| 1061 | + 'objectData' => $data, |
|
| 1062 | + ] |
|
| 1063 | + )); |
|
| 1064 | + } |
|
| 1065 | + $this->addChange($calendarId, $objectUri, 2); |
|
| 1066 | + |
|
| 1067 | + return '"' . $extraData['etag'] . '"'; |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + /** |
|
| 1071 | + * @param int $calendarObjectId |
|
| 1072 | + * @param int $classification |
|
| 1073 | + */ |
|
| 1074 | + public function setClassification($calendarObjectId, $classification) { |
|
| 1075 | + if (!in_array($classification, [ |
|
| 1076 | + self::CLASSIFICATION_PUBLIC, self::CLASSIFICATION_PRIVATE, self::CLASSIFICATION_CONFIDENTIAL |
|
| 1077 | + ])) { |
|
| 1078 | + throw new \InvalidArgumentException(); |
|
| 1079 | + } |
|
| 1080 | + $query = $this->db->getQueryBuilder(); |
|
| 1081 | + $query->update('calendarobjects') |
|
| 1082 | + ->set('classification', $query->createNamedParameter($classification)) |
|
| 1083 | + ->where($query->expr()->eq('id', $query->createNamedParameter($calendarObjectId))) |
|
| 1084 | + ->execute(); |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * Deletes an existing calendar object. |
|
| 1089 | + * |
|
| 1090 | + * The object uri is only the basename, or filename and not a full path. |
|
| 1091 | + * |
|
| 1092 | + * @param mixed $calendarId |
|
| 1093 | + * @param string $objectUri |
|
| 1094 | + * @return void |
|
| 1095 | + */ |
|
| 1096 | + function deleteCalendarObject($calendarId, $objectUri) { |
|
| 1097 | + $data = $this->getCalendarObject($calendarId, $objectUri); |
|
| 1098 | + if (is_array($data)) { |
|
| 1099 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( |
|
| 1100 | + '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', |
|
| 1101 | + [ |
|
| 1102 | + 'calendarId' => $calendarId, |
|
| 1103 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
| 1104 | + 'shares' => $this->getShares($calendarId), |
|
| 1105 | + 'objectData' => $data, |
|
| 1106 | + ] |
|
| 1107 | + )); |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ?'); |
|
| 1111 | + $stmt->execute([$calendarId, $objectUri]); |
|
| 1112 | + |
|
| 1113 | + $this->purgeProperties($calendarId, $data['id']); |
|
| 1114 | + |
|
| 1115 | + $this->addChange($calendarId, $objectUri, 3); |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + /** |
|
| 1119 | + * Performs a calendar-query on the contents of this calendar. |
|
| 1120 | + * |
|
| 1121 | + * The calendar-query is defined in RFC4791 : CalDAV. Using the |
|
| 1122 | + * calendar-query it is possible for a client to request a specific set of |
|
| 1123 | + * object, based on contents of iCalendar properties, date-ranges and |
|
| 1124 | + * iCalendar component types (VTODO, VEVENT). |
|
| 1125 | + * |
|
| 1126 | + * This method should just return a list of (relative) urls that match this |
|
| 1127 | + * query. |
|
| 1128 | + * |
|
| 1129 | + * The list of filters are specified as an array. The exact array is |
|
| 1130 | + * documented by Sabre\CalDAV\CalendarQueryParser. |
|
| 1131 | + * |
|
| 1132 | + * Note that it is extremely likely that getCalendarObject for every path |
|
| 1133 | + * returned from this method will be called almost immediately after. You |
|
| 1134 | + * may want to anticipate this to speed up these requests. |
|
| 1135 | + * |
|
| 1136 | + * This method provides a default implementation, which parses *all* the |
|
| 1137 | + * iCalendar objects in the specified calendar. |
|
| 1138 | + * |
|
| 1139 | + * This default may well be good enough for personal use, and calendars |
|
| 1140 | + * that aren't very large. But if you anticipate high usage, big calendars |
|
| 1141 | + * or high loads, you are strongly advised to optimize certain paths. |
|
| 1142 | + * |
|
| 1143 | + * The best way to do so is override this method and to optimize |
|
| 1144 | + * specifically for 'common filters'. |
|
| 1145 | + * |
|
| 1146 | + * Requests that are extremely common are: |
|
| 1147 | + * * requests for just VEVENTS |
|
| 1148 | + * * requests for just VTODO |
|
| 1149 | + * * requests with a time-range-filter on either VEVENT or VTODO. |
|
| 1150 | + * |
|
| 1151 | + * ..and combinations of these requests. It may not be worth it to try to |
|
| 1152 | + * handle every possible situation and just rely on the (relatively |
|
| 1153 | + * easy to use) CalendarQueryValidator to handle the rest. |
|
| 1154 | + * |
|
| 1155 | + * Note that especially time-range-filters may be difficult to parse. A |
|
| 1156 | + * time-range filter specified on a VEVENT must for instance also handle |
|
| 1157 | + * recurrence rules correctly. |
|
| 1158 | + * A good example of how to interprete all these filters can also simply |
|
| 1159 | + * be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct |
|
| 1160 | + * as possible, so it gives you a good idea on what type of stuff you need |
|
| 1161 | + * to think of. |
|
| 1162 | + * |
|
| 1163 | + * @param mixed $calendarId |
|
| 1164 | + * @param array $filters |
|
| 1165 | + * @return array |
|
| 1166 | + */ |
|
| 1167 | + function calendarQuery($calendarId, array $filters) { |
|
| 1168 | + $componentType = null; |
|
| 1169 | + $requirePostFilter = true; |
|
| 1170 | + $timeRange = null; |
|
| 1171 | + |
|
| 1172 | + // if no filters were specified, we don't need to filter after a query |
|
| 1173 | + if (!$filters['prop-filters'] && !$filters['comp-filters']) { |
|
| 1174 | + $requirePostFilter = false; |
|
| 1175 | + } |
|
| 1176 | + |
|
| 1177 | + // Figuring out if there's a component filter |
|
| 1178 | + if (count($filters['comp-filters']) > 0 && !$filters['comp-filters'][0]['is-not-defined']) { |
|
| 1179 | + $componentType = $filters['comp-filters'][0]['name']; |
|
| 1180 | + |
|
| 1181 | + // Checking if we need post-filters |
|
| 1182 | + if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['time-range'] && !$filters['comp-filters'][0]['prop-filters']) { |
|
| 1183 | + $requirePostFilter = false; |
|
| 1184 | + } |
|
| 1185 | + // There was a time-range filter |
|
| 1186 | + if ($componentType === 'VEVENT' && isset($filters['comp-filters'][0]['time-range'])) { |
|
| 1187 | + $timeRange = $filters['comp-filters'][0]['time-range']; |
|
| 1188 | + |
|
| 1189 | + // If start time OR the end time is not specified, we can do a |
|
| 1190 | + // 100% accurate mysql query. |
|
| 1191 | + if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && (!$timeRange['start'] || !$timeRange['end'])) { |
|
| 1192 | + $requirePostFilter = false; |
|
| 1193 | + } |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + } |
|
| 1197 | + $columns = ['uri']; |
|
| 1198 | + if ($requirePostFilter) { |
|
| 1199 | + $columns = ['uri', 'calendardata']; |
|
| 1200 | + } |
|
| 1201 | + $query = $this->db->getQueryBuilder(); |
|
| 1202 | + $query->select($columns) |
|
| 1203 | + ->from('calendarobjects') |
|
| 1204 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
| 1205 | + |
|
| 1206 | + if ($componentType) { |
|
| 1207 | + $query->andWhere($query->expr()->eq('componenttype', $query->createNamedParameter($componentType))); |
|
| 1208 | + } |
|
| 1209 | + |
|
| 1210 | + if ($timeRange && $timeRange['start']) { |
|
| 1211 | + $query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($timeRange['start']->getTimeStamp()))); |
|
| 1212 | + } |
|
| 1213 | + if ($timeRange && $timeRange['end']) { |
|
| 1214 | + $query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($timeRange['end']->getTimeStamp()))); |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + $stmt = $query->execute(); |
|
| 1218 | + |
|
| 1219 | + $result = []; |
|
| 1220 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1221 | + if ($requirePostFilter) { |
|
| 1222 | + if (!$this->validateFilterForObject($row, $filters)) { |
|
| 1223 | + continue; |
|
| 1224 | + } |
|
| 1225 | + } |
|
| 1226 | + $result[] = $row['uri']; |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + return $result; |
|
| 1230 | + } |
|
| 1231 | + |
|
| 1232 | + /** |
|
| 1233 | + * custom Nextcloud search extension for CalDAV |
|
| 1234 | + * |
|
| 1235 | + * @param string $principalUri |
|
| 1236 | + * @param array $filters |
|
| 1237 | + * @param integer|null $limit |
|
| 1238 | + * @param integer|null $offset |
|
| 1239 | + * @return array |
|
| 1240 | + */ |
|
| 1241 | + public function calendarSearch($principalUri, array $filters, $limit=null, $offset=null) { |
|
| 1242 | + $calendars = $this->getCalendarsForUser($principalUri); |
|
| 1243 | + $ownCalendars = []; |
|
| 1244 | + $sharedCalendars = []; |
|
| 1245 | + |
|
| 1246 | + $uriMapper = []; |
|
| 1247 | + |
|
| 1248 | + foreach($calendars as $calendar) { |
|
| 1249 | + if ($calendar['{http://owncloud.org/ns}owner-principal'] === $principalUri) { |
|
| 1250 | + $ownCalendars[] = $calendar['id']; |
|
| 1251 | + } else { |
|
| 1252 | + $sharedCalendars[] = $calendar['id']; |
|
| 1253 | + } |
|
| 1254 | + $uriMapper[$calendar['id']] = $calendar['uri']; |
|
| 1255 | + } |
|
| 1256 | + if (count($ownCalendars) === 0 && count($sharedCalendars) === 0) { |
|
| 1257 | + return []; |
|
| 1258 | + } |
|
| 1259 | + |
|
| 1260 | + $query = $this->db->getQueryBuilder(); |
|
| 1261 | + // Calendar id expressions |
|
| 1262 | + $calendarExpressions = []; |
|
| 1263 | + foreach($ownCalendars as $id) { |
|
| 1264 | + $calendarExpressions[] = $query->expr() |
|
| 1265 | + ->eq('c.calendarid', $query->createNamedParameter($id)); |
|
| 1266 | + } |
|
| 1267 | + foreach($sharedCalendars as $id) { |
|
| 1268 | + $calendarExpressions[] = $query->expr()->andX( |
|
| 1269 | + $query->expr()->eq('c.calendarid', |
|
| 1270 | + $query->createNamedParameter($id)), |
|
| 1271 | + $query->expr()->eq('c.classification', |
|
| 1272 | + $query->createNamedParameter(self::CLASSIFICATION_PUBLIC)) |
|
| 1273 | + ); |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + if (count($calendarExpressions) === 1) { |
|
| 1277 | + $calExpr = $calendarExpressions[0]; |
|
| 1278 | + } else { |
|
| 1279 | + $calExpr = call_user_func_array([$query->expr(), 'orX'], $calendarExpressions); |
|
| 1280 | + } |
|
| 1281 | + |
|
| 1282 | + // Component expressions |
|
| 1283 | + $compExpressions = []; |
|
| 1284 | + foreach($filters['comps'] as $comp) { |
|
| 1285 | + $compExpressions[] = $query->expr() |
|
| 1286 | + ->eq('c.componenttype', $query->createNamedParameter($comp)); |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + if (count($compExpressions) === 1) { |
|
| 1290 | + $compExpr = $compExpressions[0]; |
|
| 1291 | + } else { |
|
| 1292 | + $compExpr = call_user_func_array([$query->expr(), 'orX'], $compExpressions); |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + if (!isset($filters['props'])) { |
|
| 1296 | + $filters['props'] = []; |
|
| 1297 | + } |
|
| 1298 | + if (!isset($filters['params'])) { |
|
| 1299 | + $filters['params'] = []; |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + $propParamExpressions = []; |
|
| 1303 | + foreach($filters['props'] as $prop) { |
|
| 1304 | + $propParamExpressions[] = $query->expr()->andX( |
|
| 1305 | + $query->expr()->eq('i.name', $query->createNamedParameter($prop)), |
|
| 1306 | + $query->expr()->isNull('i.parameter') |
|
| 1307 | + ); |
|
| 1308 | + } |
|
| 1309 | + foreach($filters['params'] as $param) { |
|
| 1310 | + $propParamExpressions[] = $query->expr()->andX( |
|
| 1311 | + $query->expr()->eq('i.name', $query->createNamedParameter($param['property'])), |
|
| 1312 | + $query->expr()->eq('i.parameter', $query->createNamedParameter($param['parameter'])) |
|
| 1313 | + ); |
|
| 1314 | + } |
|
| 1315 | + |
|
| 1316 | + if (count($propParamExpressions) === 1) { |
|
| 1317 | + $propParamExpr = $propParamExpressions[0]; |
|
| 1318 | + } else { |
|
| 1319 | + $propParamExpr = call_user_func_array([$query->expr(), 'orX'], $propParamExpressions); |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + $query->select(['c.calendarid', 'c.uri']) |
|
| 1323 | + ->from($this->dbObjectPropertiesTable, 'i') |
|
| 1324 | + ->join('i', 'calendarobjects', 'c', $query->expr()->eq('i.objectid', 'c.id')) |
|
| 1325 | + ->where($calExpr) |
|
| 1326 | + ->andWhere($compExpr) |
|
| 1327 | + ->andWhere($propParamExpr) |
|
| 1328 | + ->andWhere($query->expr()->iLike('i.value', |
|
| 1329 | + $query->createNamedParameter('%'.$this->db->escapeLikeParameter($filters['search-term']).'%'))); |
|
| 1330 | + |
|
| 1331 | + if ($offset) { |
|
| 1332 | + $query->setFirstResult($offset); |
|
| 1333 | + } |
|
| 1334 | + if ($limit) { |
|
| 1335 | + $query->setMaxResults($limit); |
|
| 1336 | + } |
|
| 1337 | + |
|
| 1338 | + $stmt = $query->execute(); |
|
| 1339 | + |
|
| 1340 | + $result = []; |
|
| 1341 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1342 | + $path = $uriMapper[$row['calendarid']] . '/' . $row['uri']; |
|
| 1343 | + if (!in_array($path, $result)) { |
|
| 1344 | + $result[] = $path; |
|
| 1345 | + } |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + return $result; |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + /** |
|
| 1352 | + * used for Nextcloud's calendar API |
|
| 1353 | + * |
|
| 1354 | + * @param array $calendarInfo |
|
| 1355 | + * @param string $pattern |
|
| 1356 | + * @param array $searchProperties |
|
| 1357 | + * @param array $options |
|
| 1358 | + * @param integer|null $limit |
|
| 1359 | + * @param integer|null $offset |
|
| 1360 | + * |
|
| 1361 | + * @return array |
|
| 1362 | + */ |
|
| 1363 | + public function search(array $calendarInfo, $pattern, array $searchProperties, |
|
| 1364 | + array $options, $limit, $offset) { |
|
| 1365 | + $outerQuery = $this->db->getQueryBuilder(); |
|
| 1366 | + $innerQuery = $this->db->getQueryBuilder(); |
|
| 1367 | + |
|
| 1368 | + $innerQuery->selectDistinct('op.objectid') |
|
| 1369 | + ->from($this->dbObjectPropertiesTable, 'op') |
|
| 1370 | + ->andWhere($innerQuery->expr()->eq('op.calendarid', |
|
| 1371 | + $outerQuery->createNamedParameter($calendarInfo['id']))); |
|
| 1372 | + |
|
| 1373 | + // only return public items for shared calendars for now |
|
| 1374 | + if ($calendarInfo['principaluri'] !== $calendarInfo['{http://owncloud.org/ns}owner-principal']) { |
|
| 1375 | + $innerQuery->andWhere($innerQuery->expr()->eq('c.classification', |
|
| 1376 | + $outerQuery->createNamedParameter(self::CLASSIFICATION_PUBLIC))); |
|
| 1377 | + } |
|
| 1378 | + |
|
| 1379 | + $or = $innerQuery->expr()->orX(); |
|
| 1380 | + foreach($searchProperties as $searchProperty) { |
|
| 1381 | + $or->add($innerQuery->expr()->eq('op.name', |
|
| 1382 | + $outerQuery->createNamedParameter($searchProperty))); |
|
| 1383 | + } |
|
| 1384 | + $innerQuery->andWhere($or); |
|
| 1385 | + |
|
| 1386 | + if ($pattern !== '') { |
|
| 1387 | + $innerQuery->andWhere($innerQuery->expr()->iLike('op.value', |
|
| 1388 | + $outerQuery->createNamedParameter('%' . |
|
| 1389 | + $this->db->escapeLikeParameter($pattern) . '%'))); |
|
| 1390 | + } |
|
| 1391 | + |
|
| 1392 | + $outerQuery->select('c.id', 'c.calendardata', 'c.componenttype', 'c.uid', 'c.uri') |
|
| 1393 | + ->from('calendarobjects', 'c'); |
|
| 1394 | + |
|
| 1395 | + if (isset($options['timerange'])) { |
|
| 1396 | + if (isset($options['timerange']['start'])) { |
|
| 1397 | + $outerQuery->andWhere($outerQuery->expr()->gt('lastoccurence', |
|
| 1398 | + $outerQuery->createNamedParameter($options['timerange']['start']->getTimeStamp))); |
|
| 1399 | + |
|
| 1400 | + } |
|
| 1401 | + if (isset($options['timerange']['end'])) { |
|
| 1402 | + $outerQuery->andWhere($outerQuery->expr()->lt('firstoccurence', |
|
| 1403 | + $outerQuery->createNamedParameter($options['timerange']['end']->getTimeStamp))); |
|
| 1404 | + } |
|
| 1405 | + } |
|
| 1406 | + |
|
| 1407 | + if (isset($options['types'])) { |
|
| 1408 | + $or = $outerQuery->expr()->orX(); |
|
| 1409 | + foreach($options['types'] as $type) { |
|
| 1410 | + $or->add($outerQuery->expr()->eq('componenttype', |
|
| 1411 | + $outerQuery->createNamedParameter($type))); |
|
| 1412 | + } |
|
| 1413 | + $outerQuery->andWhere($or); |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + $outerQuery->andWhere($outerQuery->expr()->in('c.id', |
|
| 1417 | + $outerQuery->createFunction($innerQuery->getSQL()))); |
|
| 1418 | + |
|
| 1419 | + if ($offset) { |
|
| 1420 | + $outerQuery->setFirstResult($offset); |
|
| 1421 | + } |
|
| 1422 | + if ($limit) { |
|
| 1423 | + $outerQuery->setMaxResults($limit); |
|
| 1424 | + } |
|
| 1425 | + |
|
| 1426 | + $result = $outerQuery->execute(); |
|
| 1427 | + $calendarObjects = $result->fetchAll(); |
|
| 1428 | + |
|
| 1429 | + return array_map(function($o) { |
|
| 1430 | + $calendarData = Reader::read($o['calendardata']); |
|
| 1431 | + $comps = $calendarData->getComponents(); |
|
| 1432 | + $objects = []; |
|
| 1433 | + $timezones = []; |
|
| 1434 | + foreach($comps as $comp) { |
|
| 1435 | + if ($comp instanceof VTimeZone) { |
|
| 1436 | + $timezones[] = $comp; |
|
| 1437 | + } else { |
|
| 1438 | + $objects[] = $comp; |
|
| 1439 | + } |
|
| 1440 | + } |
|
| 1441 | + |
|
| 1442 | + return [ |
|
| 1443 | + 'id' => $o['id'], |
|
| 1444 | + 'type' => $o['componenttype'], |
|
| 1445 | + 'uid' => $o['uid'], |
|
| 1446 | + 'uri' => $o['uri'], |
|
| 1447 | + 'objects' => array_map(function($c) { |
|
| 1448 | + return $this->transformSearchData($c); |
|
| 1449 | + }, $objects), |
|
| 1450 | + 'timezones' => array_map(function($c) { |
|
| 1451 | + return $this->transformSearchData($c); |
|
| 1452 | + }, $timezones), |
|
| 1453 | + ]; |
|
| 1454 | + }, $calendarObjects); |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + /** |
|
| 1458 | + * @param Component $comp |
|
| 1459 | + * @return array |
|
| 1460 | + */ |
|
| 1461 | + private function transformSearchData(Component $comp) { |
|
| 1462 | + $data = []; |
|
| 1463 | + /** @var Component[] $subComponents */ |
|
| 1464 | + $subComponents = $comp->getComponents(); |
|
| 1465 | + /** @var Property[] $properties */ |
|
| 1466 | + $properties = array_filter($comp->children(), function($c) { |
|
| 1467 | + return $c instanceof Property; |
|
| 1468 | + }); |
|
| 1469 | + $validationRules = $comp->getValidationRules(); |
|
| 1470 | + |
|
| 1471 | + foreach($subComponents as $subComponent) { |
|
| 1472 | + $name = $subComponent->name; |
|
| 1473 | + if (!isset($data[$name])) { |
|
| 1474 | + $data[$name] = []; |
|
| 1475 | + } |
|
| 1476 | + $data[$name][] = $this->transformSearchData($subComponent); |
|
| 1477 | + } |
|
| 1478 | + |
|
| 1479 | + foreach($properties as $property) { |
|
| 1480 | + $name = $property->name; |
|
| 1481 | + if (!isset($validationRules[$name])) { |
|
| 1482 | + $validationRules[$name] = '*'; |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + $rule = $validationRules[$property->name]; |
|
| 1486 | + if ($rule === '+' || $rule === '*') { // multiple |
|
| 1487 | + if (!isset($data[$name])) { |
|
| 1488 | + $data[$name] = []; |
|
| 1489 | + } |
|
| 1490 | + |
|
| 1491 | + $data[$name][] = $this->transformSearchProperty($property); |
|
| 1492 | + } else { // once |
|
| 1493 | + $data[$name] = $this->transformSearchProperty($property); |
|
| 1494 | + } |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + return $data; |
|
| 1498 | + } |
|
| 1499 | + |
|
| 1500 | + /** |
|
| 1501 | + * @param Property $prop |
|
| 1502 | + * @return array |
|
| 1503 | + */ |
|
| 1504 | + private function transformSearchProperty(Property $prop) { |
|
| 1505 | + // No need to check Date, as it extends DateTime |
|
| 1506 | + if ($prop instanceof Property\ICalendar\DateTime) { |
|
| 1507 | + $value = $prop->getDateTime(); |
|
| 1508 | + } else { |
|
| 1509 | + $value = $prop->getValue(); |
|
| 1510 | + } |
|
| 1511 | + |
|
| 1512 | + return [ |
|
| 1513 | + $value, |
|
| 1514 | + $prop->parameters() |
|
| 1515 | + ]; |
|
| 1516 | + } |
|
| 1517 | + |
|
| 1518 | + /** |
|
| 1519 | + * Searches through all of a users calendars and calendar objects to find |
|
| 1520 | + * an object with a specific UID. |
|
| 1521 | + * |
|
| 1522 | + * This method should return the path to this object, relative to the |
|
| 1523 | + * calendar home, so this path usually only contains two parts: |
|
| 1524 | + * |
|
| 1525 | + * calendarpath/objectpath.ics |
|
| 1526 | + * |
|
| 1527 | + * If the uid is not found, return null. |
|
| 1528 | + * |
|
| 1529 | + * This method should only consider * objects that the principal owns, so |
|
| 1530 | + * any calendars owned by other principals that also appear in this |
|
| 1531 | + * collection should be ignored. |
|
| 1532 | + * |
|
| 1533 | + * @param string $principalUri |
|
| 1534 | + * @param string $uid |
|
| 1535 | + * @return string|null |
|
| 1536 | + */ |
|
| 1537 | + function getCalendarObjectByUID($principalUri, $uid) { |
|
| 1538 | + |
|
| 1539 | + $query = $this->db->getQueryBuilder(); |
|
| 1540 | + $query->selectAlias('c.uri', 'calendaruri')->selectAlias('co.uri', 'objecturi') |
|
| 1541 | + ->from('calendarobjects', 'co') |
|
| 1542 | + ->leftJoin('co', 'calendars', 'c', $query->expr()->eq('co.calendarid', 'c.id')) |
|
| 1543 | + ->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri))) |
|
| 1544 | + ->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid))); |
|
| 1545 | + |
|
| 1546 | + $stmt = $query->execute(); |
|
| 1547 | + |
|
| 1548 | + if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1549 | + return $row['calendaruri'] . '/' . $row['objecturi']; |
|
| 1550 | + } |
|
| 1551 | + |
|
| 1552 | + return null; |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + /** |
|
| 1556 | + * The getChanges method returns all the changes that have happened, since |
|
| 1557 | + * the specified syncToken in the specified calendar. |
|
| 1558 | + * |
|
| 1559 | + * This function should return an array, such as the following: |
|
| 1560 | + * |
|
| 1561 | + * [ |
|
| 1562 | + * 'syncToken' => 'The current synctoken', |
|
| 1563 | + * 'added' => [ |
|
| 1564 | + * 'new.txt', |
|
| 1565 | + * ], |
|
| 1566 | + * 'modified' => [ |
|
| 1567 | + * 'modified.txt', |
|
| 1568 | + * ], |
|
| 1569 | + * 'deleted' => [ |
|
| 1570 | + * 'foo.php.bak', |
|
| 1571 | + * 'old.txt' |
|
| 1572 | + * ] |
|
| 1573 | + * ); |
|
| 1574 | + * |
|
| 1575 | + * The returned syncToken property should reflect the *current* syncToken |
|
| 1576 | + * of the calendar, as reported in the {http://sabredav.org/ns}sync-token |
|
| 1577 | + * property This is * needed here too, to ensure the operation is atomic. |
|
| 1578 | + * |
|
| 1579 | + * If the $syncToken argument is specified as null, this is an initial |
|
| 1580 | + * sync, and all members should be reported. |
|
| 1581 | + * |
|
| 1582 | + * The modified property is an array of nodenames that have changed since |
|
| 1583 | + * the last token. |
|
| 1584 | + * |
|
| 1585 | + * The deleted property is an array with nodenames, that have been deleted |
|
| 1586 | + * from collection. |
|
| 1587 | + * |
|
| 1588 | + * The $syncLevel argument is basically the 'depth' of the report. If it's |
|
| 1589 | + * 1, you only have to report changes that happened only directly in |
|
| 1590 | + * immediate descendants. If it's 2, it should also include changes from |
|
| 1591 | + * the nodes below the child collections. (grandchildren) |
|
| 1592 | + * |
|
| 1593 | + * The $limit argument allows a client to specify how many results should |
|
| 1594 | + * be returned at most. If the limit is not specified, it should be treated |
|
| 1595 | + * as infinite. |
|
| 1596 | + * |
|
| 1597 | + * If the limit (infinite or not) is higher than you're willing to return, |
|
| 1598 | + * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
| 1599 | + * |
|
| 1600 | + * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
| 1601 | + * return null. |
|
| 1602 | + * |
|
| 1603 | + * The limit is 'suggestive'. You are free to ignore it. |
|
| 1604 | + * |
|
| 1605 | + * @param string $calendarId |
|
| 1606 | + * @param string $syncToken |
|
| 1607 | + * @param int $syncLevel |
|
| 1608 | + * @param int $limit |
|
| 1609 | + * @return array |
|
| 1610 | + */ |
|
| 1611 | + function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
|
| 1612 | + // Current synctoken |
|
| 1613 | + $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
| 1614 | + $stmt->execute([ $calendarId ]); |
|
| 1615 | + $currentToken = $stmt->fetchColumn(0); |
|
| 1616 | + |
|
| 1617 | + if (is_null($currentToken)) { |
|
| 1618 | + return null; |
|
| 1619 | + } |
|
| 1620 | + |
|
| 1621 | + $result = [ |
|
| 1622 | + 'syncToken' => $currentToken, |
|
| 1623 | + 'added' => [], |
|
| 1624 | + 'modified' => [], |
|
| 1625 | + 'deleted' => [], |
|
| 1626 | + ]; |
|
| 1627 | + |
|
| 1628 | + if ($syncToken) { |
|
| 1629 | + |
|
| 1630 | + $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
|
| 1631 | + if ($limit>0) { |
|
| 1632 | + $query.= " LIMIT " . (int)$limit; |
|
| 1633 | + } |
|
| 1634 | + |
|
| 1635 | + // Fetching all changes |
|
| 1636 | + $stmt = $this->db->prepare($query); |
|
| 1637 | + $stmt->execute([$syncToken, $currentToken, $calendarId]); |
|
| 1638 | + |
|
| 1639 | + $changes = []; |
|
| 1640 | + |
|
| 1641 | + // This loop ensures that any duplicates are overwritten, only the |
|
| 1642 | + // last change on a node is relevant. |
|
| 1643 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1644 | + |
|
| 1645 | + $changes[$row['uri']] = $row['operation']; |
|
| 1646 | + |
|
| 1647 | + } |
|
| 1648 | + |
|
| 1649 | + foreach($changes as $uri => $operation) { |
|
| 1650 | + |
|
| 1651 | + switch($operation) { |
|
| 1652 | + case 1 : |
|
| 1653 | + $result['added'][] = $uri; |
|
| 1654 | + break; |
|
| 1655 | + case 2 : |
|
| 1656 | + $result['modified'][] = $uri; |
|
| 1657 | + break; |
|
| 1658 | + case 3 : |
|
| 1659 | + $result['deleted'][] = $uri; |
|
| 1660 | + break; |
|
| 1661 | + } |
|
| 1662 | + |
|
| 1663 | + } |
|
| 1664 | + } else { |
|
| 1665 | + // No synctoken supplied, this is the initial sync. |
|
| 1666 | + $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?"; |
|
| 1667 | + $stmt = $this->db->prepare($query); |
|
| 1668 | + $stmt->execute([$calendarId]); |
|
| 1669 | + |
|
| 1670 | + $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
| 1671 | + } |
|
| 1672 | + return $result; |
|
| 1673 | + |
|
| 1674 | + } |
|
| 1675 | + |
|
| 1676 | + /** |
|
| 1677 | + * Returns a list of subscriptions for a principal. |
|
| 1678 | + * |
|
| 1679 | + * Every subscription is an array with the following keys: |
|
| 1680 | + * * id, a unique id that will be used by other functions to modify the |
|
| 1681 | + * subscription. This can be the same as the uri or a database key. |
|
| 1682 | + * * uri. This is just the 'base uri' or 'filename' of the subscription. |
|
| 1683 | + * * principaluri. The owner of the subscription. Almost always the same as |
|
| 1684 | + * principalUri passed to this method. |
|
| 1685 | + * |
|
| 1686 | + * Furthermore, all the subscription info must be returned too: |
|
| 1687 | + * |
|
| 1688 | + * 1. {DAV:}displayname |
|
| 1689 | + * 2. {http://apple.com/ns/ical/}refreshrate |
|
| 1690 | + * 3. {http://calendarserver.org/ns/}subscribed-strip-todos (omit if todos |
|
| 1691 | + * should not be stripped). |
|
| 1692 | + * 4. {http://calendarserver.org/ns/}subscribed-strip-alarms (omit if alarms |
|
| 1693 | + * should not be stripped). |
|
| 1694 | + * 5. {http://calendarserver.org/ns/}subscribed-strip-attachments (omit if |
|
| 1695 | + * attachments should not be stripped). |
|
| 1696 | + * 6. {http://calendarserver.org/ns/}source (Must be a |
|
| 1697 | + * Sabre\DAV\Property\Href). |
|
| 1698 | + * 7. {http://apple.com/ns/ical/}calendar-color |
|
| 1699 | + * 8. {http://apple.com/ns/ical/}calendar-order |
|
| 1700 | + * 9. {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
| 1701 | + * (should just be an instance of |
|
| 1702 | + * Sabre\CalDAV\Property\SupportedCalendarComponentSet, with a bunch of |
|
| 1703 | + * default components). |
|
| 1704 | + * |
|
| 1705 | + * @param string $principalUri |
|
| 1706 | + * @return array |
|
| 1707 | + */ |
|
| 1708 | + function getSubscriptionsForUser($principalUri) { |
|
| 1709 | + $fields = array_values($this->subscriptionPropertyMap); |
|
| 1710 | + $fields[] = 'id'; |
|
| 1711 | + $fields[] = 'uri'; |
|
| 1712 | + $fields[] = 'source'; |
|
| 1713 | + $fields[] = 'principaluri'; |
|
| 1714 | + $fields[] = 'lastmodified'; |
|
| 1715 | + |
|
| 1716 | + $query = $this->db->getQueryBuilder(); |
|
| 1717 | + $query->select($fields) |
|
| 1718 | + ->from('calendarsubscriptions') |
|
| 1719 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
| 1720 | + ->orderBy('calendarorder', 'asc'); |
|
| 1721 | + $stmt =$query->execute(); |
|
| 1722 | + |
|
| 1723 | + $subscriptions = []; |
|
| 1724 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1725 | + |
|
| 1726 | + $subscription = [ |
|
| 1727 | + 'id' => $row['id'], |
|
| 1728 | + 'uri' => $row['uri'], |
|
| 1729 | + 'principaluri' => $row['principaluri'], |
|
| 1730 | + 'source' => $row['source'], |
|
| 1731 | + 'lastmodified' => $row['lastmodified'], |
|
| 1732 | + |
|
| 1733 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
| 1734 | + ]; |
|
| 1735 | + |
|
| 1736 | + foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
| 1737 | + if (!is_null($row[$dbName])) { |
|
| 1738 | + $subscription[$xmlName] = $row[$dbName]; |
|
| 1739 | + } |
|
| 1740 | + } |
|
| 1741 | + |
|
| 1742 | + $subscriptions[] = $subscription; |
|
| 1743 | + |
|
| 1744 | + } |
|
| 1745 | + |
|
| 1746 | + return $subscriptions; |
|
| 1747 | + } |
|
| 1748 | + |
|
| 1749 | + /** |
|
| 1750 | + * Creates a new subscription for a principal. |
|
| 1751 | + * |
|
| 1752 | + * If the creation was a success, an id must be returned that can be used to reference |
|
| 1753 | + * this subscription in other methods, such as updateSubscription. |
|
| 1754 | + * |
|
| 1755 | + * @param string $principalUri |
|
| 1756 | + * @param string $uri |
|
| 1757 | + * @param array $properties |
|
| 1758 | + * @return mixed |
|
| 1759 | + */ |
|
| 1760 | + function createSubscription($principalUri, $uri, array $properties) { |
|
| 1761 | + |
|
| 1762 | + if (!isset($properties['{http://calendarserver.org/ns/}source'])) { |
|
| 1763 | + throw new Forbidden('The {http://calendarserver.org/ns/}source property is required when creating subscriptions'); |
|
| 1764 | + } |
|
| 1765 | + |
|
| 1766 | + $values = [ |
|
| 1767 | + 'principaluri' => $principalUri, |
|
| 1768 | + 'uri' => $uri, |
|
| 1769 | + 'source' => $properties['{http://calendarserver.org/ns/}source']->getHref(), |
|
| 1770 | + 'lastmodified' => time(), |
|
| 1771 | + ]; |
|
| 1772 | + |
|
| 1773 | + $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
|
| 1774 | + |
|
| 1775 | + foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
| 1776 | + if (array_key_exists($xmlName, $properties)) { |
|
| 1777 | + $values[$dbName] = $properties[$xmlName]; |
|
| 1778 | + if (in_array($dbName, $propertiesBoolean)) { |
|
| 1779 | + $values[$dbName] = true; |
|
| 1780 | + } |
|
| 1781 | + } |
|
| 1782 | + } |
|
| 1783 | + |
|
| 1784 | + $valuesToInsert = array(); |
|
| 1785 | + |
|
| 1786 | + $query = $this->db->getQueryBuilder(); |
|
| 1787 | + |
|
| 1788 | + foreach (array_keys($values) as $name) { |
|
| 1789 | + $valuesToInsert[$name] = $query->createNamedParameter($values[$name]); |
|
| 1790 | + } |
|
| 1791 | + |
|
| 1792 | + $query->insert('calendarsubscriptions') |
|
| 1793 | + ->values($valuesToInsert) |
|
| 1794 | + ->execute(); |
|
| 1795 | + |
|
| 1796 | + return $this->db->lastInsertId('*PREFIX*calendarsubscriptions'); |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + /** |
|
| 1800 | + * Updates a subscription |
|
| 1801 | + * |
|
| 1802 | + * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
| 1803 | + * To do the actual updates, you must tell this object which properties |
|
| 1804 | + * you're going to process with the handle() method. |
|
| 1805 | + * |
|
| 1806 | + * Calling the handle method is like telling the PropPatch object "I |
|
| 1807 | + * promise I can handle updating this property". |
|
| 1808 | + * |
|
| 1809 | + * Read the PropPatch documentation for more info and examples. |
|
| 1810 | + * |
|
| 1811 | + * @param mixed $subscriptionId |
|
| 1812 | + * @param PropPatch $propPatch |
|
| 1813 | + * @return void |
|
| 1814 | + */ |
|
| 1815 | + function updateSubscription($subscriptionId, PropPatch $propPatch) { |
|
| 1816 | + $supportedProperties = array_keys($this->subscriptionPropertyMap); |
|
| 1817 | + $supportedProperties[] = '{http://calendarserver.org/ns/}source'; |
|
| 1818 | + |
|
| 1819 | + /** |
|
| 1820 | + * @suppress SqlInjectionChecker |
|
| 1821 | + */ |
|
| 1822 | + $propPatch->handle($supportedProperties, function($mutations) use ($subscriptionId) { |
|
| 1823 | + |
|
| 1824 | + $newValues = []; |
|
| 1825 | + |
|
| 1826 | + foreach($mutations as $propertyName=>$propertyValue) { |
|
| 1827 | + if ($propertyName === '{http://calendarserver.org/ns/}source') { |
|
| 1828 | + $newValues['source'] = $propertyValue->getHref(); |
|
| 1829 | + } else { |
|
| 1830 | + $fieldName = $this->subscriptionPropertyMap[$propertyName]; |
|
| 1831 | + $newValues[$fieldName] = $propertyValue; |
|
| 1832 | + } |
|
| 1833 | + } |
|
| 1834 | + |
|
| 1835 | + $query = $this->db->getQueryBuilder(); |
|
| 1836 | + $query->update('calendarsubscriptions') |
|
| 1837 | + ->set('lastmodified', $query->createNamedParameter(time())); |
|
| 1838 | + foreach($newValues as $fieldName=>$value) { |
|
| 1839 | + $query->set($fieldName, $query->createNamedParameter($value)); |
|
| 1840 | + } |
|
| 1841 | + $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
| 1842 | + ->execute(); |
|
| 1843 | + |
|
| 1844 | + return true; |
|
| 1845 | + |
|
| 1846 | + }); |
|
| 1847 | + } |
|
| 1848 | + |
|
| 1849 | + /** |
|
| 1850 | + * Deletes a subscription. |
|
| 1851 | + * |
|
| 1852 | + * @param mixed $subscriptionId |
|
| 1853 | + * @return void |
|
| 1854 | + */ |
|
| 1855 | + function deleteSubscription($subscriptionId) { |
|
| 1856 | + $query = $this->db->getQueryBuilder(); |
|
| 1857 | + $query->delete('calendarsubscriptions') |
|
| 1858 | + ->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
| 1859 | + ->execute(); |
|
| 1860 | + } |
|
| 1861 | + |
|
| 1862 | + /** |
|
| 1863 | + * Returns a single scheduling object for the inbox collection. |
|
| 1864 | + * |
|
| 1865 | + * The returned array should contain the following elements: |
|
| 1866 | + * * uri - A unique basename for the object. This will be used to |
|
| 1867 | + * construct a full uri. |
|
| 1868 | + * * calendardata - The iCalendar object |
|
| 1869 | + * * lastmodified - The last modification date. Can be an int for a unix |
|
| 1870 | + * timestamp, or a PHP DateTime object. |
|
| 1871 | + * * etag - A unique token that must change if the object changed. |
|
| 1872 | + * * size - The size of the object, in bytes. |
|
| 1873 | + * |
|
| 1874 | + * @param string $principalUri |
|
| 1875 | + * @param string $objectUri |
|
| 1876 | + * @return array |
|
| 1877 | + */ |
|
| 1878 | + function getSchedulingObject($principalUri, $objectUri) { |
|
| 1879 | + $query = $this->db->getQueryBuilder(); |
|
| 1880 | + $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
| 1881 | + ->from('schedulingobjects') |
|
| 1882 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
| 1883 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
| 1884 | + ->execute(); |
|
| 1885 | + |
|
| 1886 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 1887 | + |
|
| 1888 | + if(!$row) { |
|
| 1889 | + return null; |
|
| 1890 | + } |
|
| 1891 | + |
|
| 1892 | + return [ |
|
| 1893 | + 'uri' => $row['uri'], |
|
| 1894 | + 'calendardata' => $row['calendardata'], |
|
| 1895 | + 'lastmodified' => $row['lastmodified'], |
|
| 1896 | + 'etag' => '"' . $row['etag'] . '"', |
|
| 1897 | + 'size' => (int)$row['size'], |
|
| 1898 | + ]; |
|
| 1899 | + } |
|
| 1900 | + |
|
| 1901 | + /** |
|
| 1902 | + * Returns all scheduling objects for the inbox collection. |
|
| 1903 | + * |
|
| 1904 | + * These objects should be returned as an array. Every item in the array |
|
| 1905 | + * should follow the same structure as returned from getSchedulingObject. |
|
| 1906 | + * |
|
| 1907 | + * The main difference is that 'calendardata' is optional. |
|
| 1908 | + * |
|
| 1909 | + * @param string $principalUri |
|
| 1910 | + * @return array |
|
| 1911 | + */ |
|
| 1912 | + function getSchedulingObjects($principalUri) { |
|
| 1913 | + $query = $this->db->getQueryBuilder(); |
|
| 1914 | + $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
| 1915 | + ->from('schedulingobjects') |
|
| 1916 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
| 1917 | + ->execute(); |
|
| 1918 | + |
|
| 1919 | + $result = []; |
|
| 1920 | + foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
| 1921 | + $result[] = [ |
|
| 1922 | + 'calendardata' => $row['calendardata'], |
|
| 1923 | + 'uri' => $row['uri'], |
|
| 1924 | + 'lastmodified' => $row['lastmodified'], |
|
| 1925 | + 'etag' => '"' . $row['etag'] . '"', |
|
| 1926 | + 'size' => (int)$row['size'], |
|
| 1927 | + ]; |
|
| 1928 | + } |
|
| 1929 | + |
|
| 1930 | + return $result; |
|
| 1931 | + } |
|
| 1932 | + |
|
| 1933 | + /** |
|
| 1934 | + * Deletes a scheduling object from the inbox collection. |
|
| 1935 | + * |
|
| 1936 | + * @param string $principalUri |
|
| 1937 | + * @param string $objectUri |
|
| 1938 | + * @return void |
|
| 1939 | + */ |
|
| 1940 | + function deleteSchedulingObject($principalUri, $objectUri) { |
|
| 1941 | + $query = $this->db->getQueryBuilder(); |
|
| 1942 | + $query->delete('schedulingobjects') |
|
| 1943 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
| 1944 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
| 1945 | + ->execute(); |
|
| 1946 | + } |
|
| 1947 | + |
|
| 1948 | + /** |
|
| 1949 | + * Creates a new scheduling object. This should land in a users' inbox. |
|
| 1950 | + * |
|
| 1951 | + * @param string $principalUri |
|
| 1952 | + * @param string $objectUri |
|
| 1953 | + * @param string $objectData |
|
| 1954 | + * @return void |
|
| 1955 | + */ |
|
| 1956 | + function createSchedulingObject($principalUri, $objectUri, $objectData) { |
|
| 1957 | + $query = $this->db->getQueryBuilder(); |
|
| 1958 | + $query->insert('schedulingobjects') |
|
| 1959 | + ->values([ |
|
| 1960 | + 'principaluri' => $query->createNamedParameter($principalUri), |
|
| 1961 | + 'calendardata' => $query->createNamedParameter($objectData), |
|
| 1962 | + 'uri' => $query->createNamedParameter($objectUri), |
|
| 1963 | + 'lastmodified' => $query->createNamedParameter(time()), |
|
| 1964 | + 'etag' => $query->createNamedParameter(md5($objectData)), |
|
| 1965 | + 'size' => $query->createNamedParameter(strlen($objectData)) |
|
| 1966 | + ]) |
|
| 1967 | + ->execute(); |
|
| 1968 | + } |
|
| 1969 | + |
|
| 1970 | + /** |
|
| 1971 | + * Adds a change record to the calendarchanges table. |
|
| 1972 | + * |
|
| 1973 | + * @param mixed $calendarId |
|
| 1974 | + * @param string $objectUri |
|
| 1975 | + * @param int $operation 1 = add, 2 = modify, 3 = delete. |
|
| 1976 | + * @return void |
|
| 1977 | + */ |
|
| 1978 | + protected function addChange($calendarId, $objectUri, $operation) { |
|
| 1979 | + |
|
| 1980 | + $stmt = $this->db->prepare('INSERT INTO `*PREFIX*calendarchanges` (`uri`, `synctoken`, `calendarid`, `operation`) SELECT ?, `synctoken`, ?, ? FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
| 1981 | + $stmt->execute([ |
|
| 1982 | + $objectUri, |
|
| 1983 | + $calendarId, |
|
| 1984 | + $operation, |
|
| 1985 | + $calendarId |
|
| 1986 | + ]); |
|
| 1987 | + $stmt = $this->db->prepare('UPDATE `*PREFIX*calendars` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?'); |
|
| 1988 | + $stmt->execute([ |
|
| 1989 | + $calendarId |
|
| 1990 | + ]); |
|
| 1991 | + |
|
| 1992 | + } |
|
| 1993 | + |
|
| 1994 | + /** |
|
| 1995 | + * Parses some information from calendar objects, used for optimized |
|
| 1996 | + * calendar-queries. |
|
| 1997 | + * |
|
| 1998 | + * Returns an array with the following keys: |
|
| 1999 | + * * etag - An md5 checksum of the object without the quotes. |
|
| 2000 | + * * size - Size of the object in bytes |
|
| 2001 | + * * componentType - VEVENT, VTODO or VJOURNAL |
|
| 2002 | + * * firstOccurence |
|
| 2003 | + * * lastOccurence |
|
| 2004 | + * * uid - value of the UID property |
|
| 2005 | + * |
|
| 2006 | + * @param string $calendarData |
|
| 2007 | + * @return array |
|
| 2008 | + */ |
|
| 2009 | + public function getDenormalizedData($calendarData) { |
|
| 2010 | + |
|
| 2011 | + $vObject = Reader::read($calendarData); |
|
| 2012 | + $componentType = null; |
|
| 2013 | + $component = null; |
|
| 2014 | + $firstOccurrence = null; |
|
| 2015 | + $lastOccurrence = null; |
|
| 2016 | + $uid = null; |
|
| 2017 | + $classification = self::CLASSIFICATION_PUBLIC; |
|
| 2018 | + foreach($vObject->getComponents() as $component) { |
|
| 2019 | + if ($component->name!=='VTIMEZONE') { |
|
| 2020 | + $componentType = $component->name; |
|
| 2021 | + $uid = (string)$component->UID; |
|
| 2022 | + break; |
|
| 2023 | + } |
|
| 2024 | + } |
|
| 2025 | + if (!$componentType) { |
|
| 2026 | + throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); |
|
| 2027 | + } |
|
| 2028 | + if ($componentType === 'VEVENT' && $component->DTSTART) { |
|
| 2029 | + $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
| 2030 | + // Finding the last occurrence is a bit harder |
|
| 2031 | + if (!isset($component->RRULE)) { |
|
| 2032 | + if (isset($component->DTEND)) { |
|
| 2033 | + $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
| 2034 | + } elseif (isset($component->DURATION)) { |
|
| 2035 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
| 2036 | + $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
| 2037 | + $lastOccurrence = $endDate->getTimeStamp(); |
|
| 2038 | + } elseif (!$component->DTSTART->hasTime()) { |
|
| 2039 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
| 2040 | + $endDate->modify('+1 day'); |
|
| 2041 | + $lastOccurrence = $endDate->getTimeStamp(); |
|
| 2042 | + } else { |
|
| 2043 | + $lastOccurrence = $firstOccurrence; |
|
| 2044 | + } |
|
| 2045 | + } else { |
|
| 2046 | + $it = new EventIterator($vObject, (string)$component->UID); |
|
| 2047 | + $maxDate = new \DateTime(self::MAX_DATE); |
|
| 2048 | + if ($it->isInfinite()) { |
|
| 2049 | + $lastOccurrence = $maxDate->getTimestamp(); |
|
| 2050 | + } else { |
|
| 2051 | + $end = $it->getDtEnd(); |
|
| 2052 | + while($it->valid() && $end < $maxDate) { |
|
| 2053 | + $end = $it->getDtEnd(); |
|
| 2054 | + $it->next(); |
|
| 2055 | + |
|
| 2056 | + } |
|
| 2057 | + $lastOccurrence = $end->getTimestamp(); |
|
| 2058 | + } |
|
| 2059 | + |
|
| 2060 | + } |
|
| 2061 | + } |
|
| 2062 | + |
|
| 2063 | + if ($component->CLASS) { |
|
| 2064 | + $classification = CalDavBackend::CLASSIFICATION_PRIVATE; |
|
| 2065 | + switch ($component->CLASS->getValue()) { |
|
| 2066 | + case 'PUBLIC': |
|
| 2067 | + $classification = CalDavBackend::CLASSIFICATION_PUBLIC; |
|
| 2068 | + break; |
|
| 2069 | + case 'CONFIDENTIAL': |
|
| 2070 | + $classification = CalDavBackend::CLASSIFICATION_CONFIDENTIAL; |
|
| 2071 | + break; |
|
| 2072 | + } |
|
| 2073 | + } |
|
| 2074 | + return [ |
|
| 2075 | + 'etag' => md5($calendarData), |
|
| 2076 | + 'size' => strlen($calendarData), |
|
| 2077 | + 'componentType' => $componentType, |
|
| 2078 | + 'firstOccurence' => is_null($firstOccurrence) ? null : max(0, $firstOccurrence), |
|
| 2079 | + 'lastOccurence' => $lastOccurrence, |
|
| 2080 | + 'uid' => $uid, |
|
| 2081 | + 'classification' => $classification |
|
| 2082 | + ]; |
|
| 2083 | + |
|
| 2084 | + } |
|
| 2085 | + |
|
| 2086 | + private function readBlob($cardData) { |
|
| 2087 | + if (is_resource($cardData)) { |
|
| 2088 | + return stream_get_contents($cardData); |
|
| 2089 | + } |
|
| 2090 | + |
|
| 2091 | + return $cardData; |
|
| 2092 | + } |
|
| 2093 | + |
|
| 2094 | + /** |
|
| 2095 | + * @param IShareable $shareable |
|
| 2096 | + * @param array $add |
|
| 2097 | + * @param array $remove |
|
| 2098 | + */ |
|
| 2099 | + public function updateShares($shareable, $add, $remove) { |
|
| 2100 | + $calendarId = $shareable->getResourceId(); |
|
| 2101 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent( |
|
| 2102 | + '\OCA\DAV\CalDAV\CalDavBackend::updateShares', |
|
| 2103 | + [ |
|
| 2104 | + 'calendarId' => $calendarId, |
|
| 2105 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
| 2106 | + 'shares' => $this->getShares($calendarId), |
|
| 2107 | + 'add' => $add, |
|
| 2108 | + 'remove' => $remove, |
|
| 2109 | + ])); |
|
| 2110 | + $this->sharingBackend->updateShares($shareable, $add, $remove); |
|
| 2111 | + } |
|
| 2112 | + |
|
| 2113 | + /** |
|
| 2114 | + * @param int $resourceId |
|
| 2115 | + * @return array |
|
| 2116 | + */ |
|
| 2117 | + public function getShares($resourceId) { |
|
| 2118 | + return $this->sharingBackend->getShares($resourceId); |
|
| 2119 | + } |
|
| 2120 | + |
|
| 2121 | + /** |
|
| 2122 | + * @param boolean $value |
|
| 2123 | + * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
| 2124 | + * @return string|null |
|
| 2125 | + */ |
|
| 2126 | + public function setPublishStatus($value, $calendar) { |
|
| 2127 | + $query = $this->db->getQueryBuilder(); |
|
| 2128 | + if ($value) { |
|
| 2129 | + $publicUri = $this->random->generate(16, ISecureRandom::CHAR_HUMAN_READABLE); |
|
| 2130 | + $query->insert('dav_shares') |
|
| 2131 | + ->values([ |
|
| 2132 | + 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), |
|
| 2133 | + 'type' => $query->createNamedParameter('calendar'), |
|
| 2134 | + 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), |
|
| 2135 | + 'resourceid' => $query->createNamedParameter($calendar->getResourceId()), |
|
| 2136 | + 'publicuri' => $query->createNamedParameter($publicUri) |
|
| 2137 | + ]); |
|
| 2138 | + $query->execute(); |
|
| 2139 | + return $publicUri; |
|
| 2140 | + } |
|
| 2141 | + $query->delete('dav_shares') |
|
| 2142 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
| 2143 | + ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); |
|
| 2144 | + $query->execute(); |
|
| 2145 | + return null; |
|
| 2146 | + } |
|
| 2147 | + |
|
| 2148 | + /** |
|
| 2149 | + * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
| 2150 | + * @return mixed |
|
| 2151 | + */ |
|
| 2152 | + public function getPublishStatus($calendar) { |
|
| 2153 | + $query = $this->db->getQueryBuilder(); |
|
| 2154 | + $result = $query->select('publicuri') |
|
| 2155 | + ->from('dav_shares') |
|
| 2156 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
| 2157 | + ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
| 2158 | + ->execute(); |
|
| 2159 | + |
|
| 2160 | + $row = $result->fetch(); |
|
| 2161 | + $result->closeCursor(); |
|
| 2162 | + return $row ? reset($row) : false; |
|
| 2163 | + } |
|
| 2164 | + |
|
| 2165 | + /** |
|
| 2166 | + * @param int $resourceId |
|
| 2167 | + * @param array $acl |
|
| 2168 | + * @return array |
|
| 2169 | + */ |
|
| 2170 | + public function applyShareAcl($resourceId, $acl) { |
|
| 2171 | + return $this->sharingBackend->applyShareAcl($resourceId, $acl); |
|
| 2172 | + } |
|
| 2173 | + |
|
| 2174 | + |
|
| 2175 | + |
|
| 2176 | + /** |
|
| 2177 | + * update properties table |
|
| 2178 | + * |
|
| 2179 | + * @param int $calendarId |
|
| 2180 | + * @param string $objectUri |
|
| 2181 | + * @param string $calendarData |
|
| 2182 | + */ |
|
| 2183 | + public function updateProperties($calendarId, $objectUri, $calendarData) { |
|
| 2184 | + $objectId = $this->getCalendarObjectId($calendarId, $objectUri); |
|
| 2185 | + |
|
| 2186 | + try { |
|
| 2187 | + $vCalendar = $this->readCalendarData($calendarData); |
|
| 2188 | + } catch (\Exception $ex) { |
|
| 2189 | + return; |
|
| 2190 | + } |
|
| 2191 | + |
|
| 2192 | + $this->purgeProperties($calendarId, $objectId); |
|
| 2193 | + |
|
| 2194 | + $query = $this->db->getQueryBuilder(); |
|
| 2195 | + $query->insert($this->dbObjectPropertiesTable) |
|
| 2196 | + ->values( |
|
| 2197 | + [ |
|
| 2198 | + 'calendarid' => $query->createNamedParameter($calendarId), |
|
| 2199 | + 'objectid' => $query->createNamedParameter($objectId), |
|
| 2200 | + 'name' => $query->createParameter('name'), |
|
| 2201 | + 'parameter' => $query->createParameter('parameter'), |
|
| 2202 | + 'value' => $query->createParameter('value'), |
|
| 2203 | + ] |
|
| 2204 | + ); |
|
| 2205 | + |
|
| 2206 | + $indexComponents = ['VEVENT', 'VJOURNAL', 'VTODO']; |
|
| 2207 | + foreach ($vCalendar->getComponents() as $component) { |
|
| 2208 | + if (!in_array($component->name, $indexComponents)) { |
|
| 2209 | + continue; |
|
| 2210 | + } |
|
| 2211 | + |
|
| 2212 | + foreach ($component->children() as $property) { |
|
| 2213 | + if (in_array($property->name, self::$indexProperties)) { |
|
| 2214 | + $value = $property->getValue(); |
|
| 2215 | + // is this a shitty db? |
|
| 2216 | + if (!$this->db->supports4ByteText()) { |
|
| 2217 | + $value = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $value); |
|
| 2218 | + } |
|
| 2219 | + $value = substr($value, 0, 254); |
|
| 2220 | + |
|
| 2221 | + $query->setParameter('name', $property->name); |
|
| 2222 | + $query->setParameter('parameter', null); |
|
| 2223 | + $query->setParameter('value', $value); |
|
| 2224 | + $query->execute(); |
|
| 2225 | + } |
|
| 2226 | + |
|
| 2227 | + if (in_array($property->name, array_keys(self::$indexParameters))) { |
|
| 2228 | + $parameters = $property->parameters(); |
|
| 2229 | + $indexedParametersForProperty = self::$indexParameters[$property->name]; |
|
| 2230 | + |
|
| 2231 | + foreach ($parameters as $key => $value) { |
|
| 2232 | + if (in_array($key, $indexedParametersForProperty)) { |
|
| 2233 | + // is this a shitty db? |
|
| 2234 | + if ($this->db->supports4ByteText()) { |
|
| 2235 | + $value = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $value); |
|
| 2236 | + } |
|
| 2237 | + $value = substr($value, 0, 254); |
|
| 2238 | + |
|
| 2239 | + $query->setParameter('name', $property->name); |
|
| 2240 | + $query->setParameter('parameter', substr($key, 0, 254)); |
|
| 2241 | + $query->setParameter('value', substr($value, 0, 254)); |
|
| 2242 | + $query->execute(); |
|
| 2243 | + } |
|
| 2244 | + } |
|
| 2245 | + } |
|
| 2246 | + } |
|
| 2247 | + } |
|
| 2248 | + } |
|
| 2249 | + |
|
| 2250 | + /** |
|
| 2251 | + * read VCalendar data into a VCalendar object |
|
| 2252 | + * |
|
| 2253 | + * @param string $objectData |
|
| 2254 | + * @return VCalendar |
|
| 2255 | + */ |
|
| 2256 | + protected function readCalendarData($objectData) { |
|
| 2257 | + return Reader::read($objectData); |
|
| 2258 | + } |
|
| 2259 | + |
|
| 2260 | + /** |
|
| 2261 | + * delete all properties from a given calendar object |
|
| 2262 | + * |
|
| 2263 | + * @param int $calendarId |
|
| 2264 | + * @param int $objectId |
|
| 2265 | + */ |
|
| 2266 | + protected function purgeProperties($calendarId, $objectId) { |
|
| 2267 | + $query = $this->db->getQueryBuilder(); |
|
| 2268 | + $query->delete($this->dbObjectPropertiesTable) |
|
| 2269 | + ->where($query->expr()->eq('objectid', $query->createNamedParameter($objectId))) |
|
| 2270 | + ->andWhere($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
| 2271 | + $query->execute(); |
|
| 2272 | + } |
|
| 2273 | + |
|
| 2274 | + /** |
|
| 2275 | + * get ID from a given calendar object |
|
| 2276 | + * |
|
| 2277 | + * @param int $calendarId |
|
| 2278 | + * @param string $uri |
|
| 2279 | + * @return int |
|
| 2280 | + */ |
|
| 2281 | + protected function getCalendarObjectId($calendarId, $uri) { |
|
| 2282 | + $query = $this->db->getQueryBuilder(); |
|
| 2283 | + $query->select('id')->from('calendarobjects') |
|
| 2284 | + ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
| 2285 | + ->andWhere($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
| 2286 | + |
|
| 2287 | + $result = $query->execute(); |
|
| 2288 | + $objectIds = $result->fetch(); |
|
| 2289 | + $result->closeCursor(); |
|
| 2290 | + |
|
| 2291 | + if (!isset($objectIds['id'])) { |
|
| 2292 | + throw new \InvalidArgumentException('Calendarobject does not exists: ' . $uri); |
|
| 2293 | + } |
|
| 2294 | + |
|
| 2295 | + return (int)$objectIds['id']; |
|
| 2296 | + } |
|
| 2297 | + |
|
| 2298 | + private function convertPrincipal($principalUri, $toV2) { |
|
| 2299 | + if ($this->principalBackend->getPrincipalPrefix() === 'principals') { |
|
| 2300 | + list(, $name) = Uri\split($principalUri); |
|
| 2301 | + if ($toV2 === true) { |
|
| 2302 | + return "principals/users/$name"; |
|
| 2303 | + } |
|
| 2304 | + return "principals/$name"; |
|
| 2305 | + } |
|
| 2306 | + return $principalUri; |
|
| 2307 | + } |
|
| 2308 | + |
|
| 2309 | + private function addOwnerPrincipal(&$calendarInfo) { |
|
| 2310 | + $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'; |
|
| 2311 | + $displaynameKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'; |
|
| 2312 | + if (isset($calendarInfo[$ownerPrincipalKey])) { |
|
| 2313 | + $uri = $calendarInfo[$ownerPrincipalKey]; |
|
| 2314 | + } else { |
|
| 2315 | + $uri = $calendarInfo['principaluri']; |
|
| 2316 | + } |
|
| 2317 | + |
|
| 2318 | + $principalInformation = $this->principalBackend->getPrincipalByPath($uri); |
|
| 2319 | + if (isset($principalInformation['{DAV:}displayname'])) { |
|
| 2320 | + $calendarInfo[$displaynameKey] = $principalInformation['{DAV:}displayname']; |
|
| 2321 | + } |
|
| 2322 | + } |
|
| 2323 | 2323 | } |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - return (int)$query->execute()->fetchColumn(); |
|
| 211 | + return (int) $query->execute()->fetchColumn(); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -255,25 +255,25 @@ discard block |
||
| 255 | 255 | $stmt = $query->execute(); |
| 256 | 256 | |
| 257 | 257 | $calendars = []; |
| 258 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 258 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 259 | 259 | |
| 260 | 260 | $components = []; |
| 261 | 261 | if ($row['components']) { |
| 262 | - $components = explode(',',$row['components']); |
|
| 262 | + $components = explode(',', $row['components']); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | $calendar = [ |
| 266 | 266 | 'id' => $row['id'], |
| 267 | 267 | 'uri' => $row['uri'], |
| 268 | 268 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
| 269 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 270 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 271 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 272 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 273 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
| 269 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
| 270 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
| 271 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 272 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
| 273 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
| 274 | 274 | ]; |
| 275 | 275 | |
| 276 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 276 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
| 277 | 277 | $calendar[$xmlName] = $row[$dbName]; |
| 278 | 278 | } |
| 279 | 279 | |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | $principals = array_map(function($principal) { |
| 292 | 292 | return urldecode($principal); |
| 293 | 293 | }, $principals); |
| 294 | - $principals[]= $principalUri; |
|
| 294 | + $principals[] = $principalUri; |
|
| 295 | 295 | |
| 296 | 296 | $fields = array_values($this->propertyMap); |
| 297 | 297 | $fields[] = 'a.id'; |
@@ -311,8 +311,8 @@ discard block |
||
| 311 | 311 | ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
| 312 | 312 | ->execute(); |
| 313 | 313 | |
| 314 | - $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
| 315 | - while($row = $result->fetch()) { |
|
| 314 | + $readOnlyPropertyName = '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only'; |
|
| 315 | + while ($row = $result->fetch()) { |
|
| 316 | 316 | if ($row['principaluri'] === $principalUri) { |
| 317 | 317 | continue; |
| 318 | 318 | } |
@@ -331,25 +331,25 @@ discard block |
||
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | list(, $name) = Uri\split($row['principaluri']); |
| 334 | - $uri = $row['uri'] . '_shared_by_' . $name; |
|
| 335 | - $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
| 334 | + $uri = $row['uri'].'_shared_by_'.$name; |
|
| 335 | + $row['displayname'] = $row['displayname'].' ('.$this->getUserDisplayName($name).')'; |
|
| 336 | 336 | $components = []; |
| 337 | 337 | if ($row['components']) { |
| 338 | - $components = explode(',',$row['components']); |
|
| 338 | + $components = explode(',', $row['components']); |
|
| 339 | 339 | } |
| 340 | 340 | $calendar = [ |
| 341 | 341 | 'id' => $row['id'], |
| 342 | 342 | 'uri' => $uri, |
| 343 | 343 | 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
| 344 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 345 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 346 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 347 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 348 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 344 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
| 345 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
| 346 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 347 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
| 348 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 349 | 349 | $readOnlyPropertyName => $readOnly, |
| 350 | 350 | ]; |
| 351 | 351 | |
| 352 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 352 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
| 353 | 353 | $calendar[$xmlName] = $row[$dbName]; |
| 354 | 354 | } |
| 355 | 355 | |
@@ -378,21 +378,21 @@ discard block |
||
| 378 | 378 | ->orderBy('calendarorder', 'ASC'); |
| 379 | 379 | $stmt = $query->execute(); |
| 380 | 380 | $calendars = []; |
| 381 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 381 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 382 | 382 | $components = []; |
| 383 | 383 | if ($row['components']) { |
| 384 | - $components = explode(',',$row['components']); |
|
| 384 | + $components = explode(',', $row['components']); |
|
| 385 | 385 | } |
| 386 | 386 | $calendar = [ |
| 387 | 387 | 'id' => $row['id'], |
| 388 | 388 | 'uri' => $row['uri'], |
| 389 | 389 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
| 390 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 391 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 392 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 393 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 390 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
| 391 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
| 392 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 393 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
| 394 | 394 | ]; |
| 395 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 395 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
| 396 | 396 | $calendar[$xmlName] = $row[$dbName]; |
| 397 | 397 | } |
| 398 | 398 | |
@@ -443,27 +443,27 @@ discard block |
||
| 443 | 443 | ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
| 444 | 444 | ->execute(); |
| 445 | 445 | |
| 446 | - while($row = $result->fetch()) { |
|
| 446 | + while ($row = $result->fetch()) { |
|
| 447 | 447 | list(, $name) = Uri\split($row['principaluri']); |
| 448 | - $row['displayname'] = $row['displayname'] . "($name)"; |
|
| 448 | + $row['displayname'] = $row['displayname']."($name)"; |
|
| 449 | 449 | $components = []; |
| 450 | 450 | if ($row['components']) { |
| 451 | - $components = explode(',',$row['components']); |
|
| 451 | + $components = explode(',', $row['components']); |
|
| 452 | 452 | } |
| 453 | 453 | $calendar = [ |
| 454 | 454 | 'id' => $row['id'], |
| 455 | 455 | 'uri' => $row['publicuri'], |
| 456 | 456 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
| 457 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 458 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 459 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 460 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 461 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
| 462 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
| 463 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
| 457 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
| 458 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
| 459 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 460 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
| 461 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
| 462 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only' => (int) $row['access'] === Backend::ACCESS_READ, |
|
| 463 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}public' => (int) $row['access'] === self::ACCESS_PUBLIC, |
|
| 464 | 464 | ]; |
| 465 | 465 | |
| 466 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 466 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
| 467 | 467 | $calendar[$xmlName] = $row[$dbName]; |
| 468 | 468 | } |
| 469 | 469 | |
@@ -507,29 +507,29 @@ discard block |
||
| 507 | 507 | $result->closeCursor(); |
| 508 | 508 | |
| 509 | 509 | if ($row === false) { |
| 510 | - throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
| 510 | + throw new NotFound('Node with name \''.$uri.'\' could not be found'); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | list(, $name) = Uri\split($row['principaluri']); |
| 514 | - $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
| 514 | + $row['displayname'] = $row['displayname'].' '."($name)"; |
|
| 515 | 515 | $components = []; |
| 516 | 516 | if ($row['components']) { |
| 517 | - $components = explode(',',$row['components']); |
|
| 517 | + $components = explode(',', $row['components']); |
|
| 518 | 518 | } |
| 519 | 519 | $calendar = [ |
| 520 | 520 | 'id' => $row['id'], |
| 521 | 521 | 'uri' => $row['publicuri'], |
| 522 | 522 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
| 523 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 524 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 525 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 526 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 527 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 528 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
| 529 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
| 523 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
| 524 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
| 525 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 526 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
| 527 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
| 528 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only' => (int) $row['access'] === Backend::ACCESS_READ, |
|
| 529 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}public' => (int) $row['access'] === self::ACCESS_PUBLIC, |
|
| 530 | 530 | ]; |
| 531 | 531 | |
| 532 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 532 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
| 533 | 533 | $calendar[$xmlName] = $row[$dbName]; |
| 534 | 534 | } |
| 535 | 535 | |
@@ -569,20 +569,20 @@ discard block |
||
| 569 | 569 | |
| 570 | 570 | $components = []; |
| 571 | 571 | if ($row['components']) { |
| 572 | - $components = explode(',',$row['components']); |
|
| 572 | + $components = explode(',', $row['components']); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | $calendar = [ |
| 576 | 576 | 'id' => $row['id'], |
| 577 | 577 | 'uri' => $row['uri'], |
| 578 | 578 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
| 579 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 580 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 581 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 582 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 579 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
| 580 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
| 581 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 582 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
| 583 | 583 | ]; |
| 584 | 584 | |
| 585 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 585 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
| 586 | 586 | $calendar[$xmlName] = $row[$dbName]; |
| 587 | 587 | } |
| 588 | 588 | |
@@ -615,20 +615,20 @@ discard block |
||
| 615 | 615 | |
| 616 | 616 | $components = []; |
| 617 | 617 | if ($row['components']) { |
| 618 | - $components = explode(',',$row['components']); |
|
| 618 | + $components = explode(',', $row['components']); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | $calendar = [ |
| 622 | 622 | 'id' => $row['id'], |
| 623 | 623 | 'uri' => $row['uri'], |
| 624 | 624 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
| 625 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
| 626 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
| 627 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 628 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
| 625 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
| 626 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
| 627 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
| 628 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
| 629 | 629 | ]; |
| 630 | 630 | |
| 631 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 631 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
| 632 | 632 | $calendar[$xmlName] = $row[$dbName]; |
| 633 | 633 | } |
| 634 | 634 | |
@@ -663,16 +663,16 @@ discard block |
||
| 663 | 663 | $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
| 664 | 664 | if (isset($properties[$sccs])) { |
| 665 | 665 | if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
| 666 | - throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
| 666 | + throw new DAV\Exception('The '.$sccs.' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
| 667 | 667 | } |
| 668 | - $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
| 668 | + $values['components'] = implode(',', $properties[$sccs]->getValue()); |
|
| 669 | 669 | } |
| 670 | - $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
| 670 | + $transp = '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp'; |
|
| 671 | 671 | if (isset($properties[$transp])) { |
| 672 | 672 | $values['transparent'] = (int) ($properties[$transp]->getValue() === 'transparent'); |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
| 675 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
| 676 | 676 | if (isset($properties[$xmlName])) { |
| 677 | 677 | $values[$dbName] = $properties[$xmlName]; |
| 678 | 678 | } |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | |
| 681 | 681 | $query = $this->db->getQueryBuilder(); |
| 682 | 682 | $query->insert('calendars'); |
| 683 | - foreach($values as $column => $value) { |
|
| 683 | + foreach ($values as $column => $value) { |
|
| 684 | 684 | $query->setValue($column, $query->createNamedParameter($value)); |
| 685 | 685 | } |
| 686 | 686 | $query->execute(); |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | */ |
| 715 | 715 | function updateCalendar($calendarId, PropPatch $propPatch) { |
| 716 | 716 | $supportedProperties = array_keys($this->propertyMap); |
| 717 | - $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
| 717 | + $supportedProperties[] = '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp'; |
|
| 718 | 718 | |
| 719 | 719 | /** |
| 720 | 720 | * @suppress SqlInjectionChecker |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | foreach ($mutations as $propertyName => $propertyValue) { |
| 725 | 725 | |
| 726 | 726 | switch ($propertyName) { |
| 727 | - case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
| 727 | + case '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' : |
|
| 728 | 728 | $fieldName = 'transparent'; |
| 729 | 729 | $newValues[$fieldName] = (int) ($propertyValue->getValue() === 'transparent'); |
| 730 | 730 | break; |
@@ -839,16 +839,16 @@ discard block |
||
| 839 | 839 | $stmt = $query->execute(); |
| 840 | 840 | |
| 841 | 841 | $result = []; |
| 842 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
| 842 | + foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
| 843 | 843 | $result[] = [ |
| 844 | 844 | 'id' => $row['id'], |
| 845 | 845 | 'uri' => $row['uri'], |
| 846 | 846 | 'lastmodified' => $row['lastmodified'], |
| 847 | - 'etag' => '"' . $row['etag'] . '"', |
|
| 847 | + 'etag' => '"'.$row['etag'].'"', |
|
| 848 | 848 | 'calendarid' => $row['calendarid'], |
| 849 | - 'size' => (int)$row['size'], |
|
| 849 | + 'size' => (int) $row['size'], |
|
| 850 | 850 | 'component' => strtolower($row['componenttype']), |
| 851 | - 'classification'=> (int)$row['classification'] |
|
| 851 | + 'classification'=> (int) $row['classification'] |
|
| 852 | 852 | ]; |
| 853 | 853 | } |
| 854 | 854 | |
@@ -881,18 +881,18 @@ discard block |
||
| 881 | 881 | $stmt = $query->execute(); |
| 882 | 882 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 883 | 883 | |
| 884 | - if(!$row) return null; |
|
| 884 | + if (!$row) return null; |
|
| 885 | 885 | |
| 886 | 886 | return [ |
| 887 | 887 | 'id' => $row['id'], |
| 888 | 888 | 'uri' => $row['uri'], |
| 889 | 889 | 'lastmodified' => $row['lastmodified'], |
| 890 | - 'etag' => '"' . $row['etag'] . '"', |
|
| 890 | + 'etag' => '"'.$row['etag'].'"', |
|
| 891 | 891 | 'calendarid' => $row['calendarid'], |
| 892 | - 'size' => (int)$row['size'], |
|
| 892 | + 'size' => (int) $row['size'], |
|
| 893 | 893 | 'calendardata' => $this->readBlob($row['calendardata']), |
| 894 | 894 | 'component' => strtolower($row['componenttype']), |
| 895 | - 'classification'=> (int)$row['classification'] |
|
| 895 | + 'classification'=> (int) $row['classification'] |
|
| 896 | 896 | ]; |
| 897 | 897 | } |
| 898 | 898 | |
@@ -931,12 +931,12 @@ discard block |
||
| 931 | 931 | 'id' => $row['id'], |
| 932 | 932 | 'uri' => $row['uri'], |
| 933 | 933 | 'lastmodified' => $row['lastmodified'], |
| 934 | - 'etag' => '"' . $row['etag'] . '"', |
|
| 934 | + 'etag' => '"'.$row['etag'].'"', |
|
| 935 | 935 | 'calendarid' => $row['calendarid'], |
| 936 | - 'size' => (int)$row['size'], |
|
| 936 | + 'size' => (int) $row['size'], |
|
| 937 | 937 | 'calendardata' => $this->readBlob($row['calendardata']), |
| 938 | 938 | 'component' => strtolower($row['componenttype']), |
| 939 | - 'classification' => (int)$row['classification'] |
|
| 939 | + 'classification' => (int) $row['classification'] |
|
| 940 | 940 | ]; |
| 941 | 941 | } |
| 942 | 942 | $result->closeCursor(); |
@@ -1009,7 +1009,7 @@ discard block |
||
| 1009 | 1009 | )); |
| 1010 | 1010 | $this->addChange($calendarId, $objectUri, 1); |
| 1011 | 1011 | |
| 1012 | - return '"' . $extraData['etag'] . '"'; |
|
| 1012 | + return '"'.$extraData['etag'].'"'; |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | /** |
@@ -1064,7 +1064,7 @@ discard block |
||
| 1064 | 1064 | } |
| 1065 | 1065 | $this->addChange($calendarId, $objectUri, 2); |
| 1066 | 1066 | |
| 1067 | - return '"' . $extraData['etag'] . '"'; |
|
| 1067 | + return '"'.$extraData['etag'].'"'; |
|
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | 1070 | /** |
@@ -1217,7 +1217,7 @@ discard block |
||
| 1217 | 1217 | $stmt = $query->execute(); |
| 1218 | 1218 | |
| 1219 | 1219 | $result = []; |
| 1220 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1220 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1221 | 1221 | if ($requirePostFilter) { |
| 1222 | 1222 | if (!$this->validateFilterForObject($row, $filters)) { |
| 1223 | 1223 | continue; |
@@ -1238,14 +1238,14 @@ discard block |
||
| 1238 | 1238 | * @param integer|null $offset |
| 1239 | 1239 | * @return array |
| 1240 | 1240 | */ |
| 1241 | - public function calendarSearch($principalUri, array $filters, $limit=null, $offset=null) { |
|
| 1241 | + public function calendarSearch($principalUri, array $filters, $limit = null, $offset = null) { |
|
| 1242 | 1242 | $calendars = $this->getCalendarsForUser($principalUri); |
| 1243 | 1243 | $ownCalendars = []; |
| 1244 | 1244 | $sharedCalendars = []; |
| 1245 | 1245 | |
| 1246 | 1246 | $uriMapper = []; |
| 1247 | 1247 | |
| 1248 | - foreach($calendars as $calendar) { |
|
| 1248 | + foreach ($calendars as $calendar) { |
|
| 1249 | 1249 | if ($calendar['{http://owncloud.org/ns}owner-principal'] === $principalUri) { |
| 1250 | 1250 | $ownCalendars[] = $calendar['id']; |
| 1251 | 1251 | } else { |
@@ -1260,11 +1260,11 @@ discard block |
||
| 1260 | 1260 | $query = $this->db->getQueryBuilder(); |
| 1261 | 1261 | // Calendar id expressions |
| 1262 | 1262 | $calendarExpressions = []; |
| 1263 | - foreach($ownCalendars as $id) { |
|
| 1263 | + foreach ($ownCalendars as $id) { |
|
| 1264 | 1264 | $calendarExpressions[] = $query->expr() |
| 1265 | 1265 | ->eq('c.calendarid', $query->createNamedParameter($id)); |
| 1266 | 1266 | } |
| 1267 | - foreach($sharedCalendars as $id) { |
|
| 1267 | + foreach ($sharedCalendars as $id) { |
|
| 1268 | 1268 | $calendarExpressions[] = $query->expr()->andX( |
| 1269 | 1269 | $query->expr()->eq('c.calendarid', |
| 1270 | 1270 | $query->createNamedParameter($id)), |
@@ -1281,7 +1281,7 @@ discard block |
||
| 1281 | 1281 | |
| 1282 | 1282 | // Component expressions |
| 1283 | 1283 | $compExpressions = []; |
| 1284 | - foreach($filters['comps'] as $comp) { |
|
| 1284 | + foreach ($filters['comps'] as $comp) { |
|
| 1285 | 1285 | $compExpressions[] = $query->expr() |
| 1286 | 1286 | ->eq('c.componenttype', $query->createNamedParameter($comp)); |
| 1287 | 1287 | } |
@@ -1300,13 +1300,13 @@ discard block |
||
| 1300 | 1300 | } |
| 1301 | 1301 | |
| 1302 | 1302 | $propParamExpressions = []; |
| 1303 | - foreach($filters['props'] as $prop) { |
|
| 1303 | + foreach ($filters['props'] as $prop) { |
|
| 1304 | 1304 | $propParamExpressions[] = $query->expr()->andX( |
| 1305 | 1305 | $query->expr()->eq('i.name', $query->createNamedParameter($prop)), |
| 1306 | 1306 | $query->expr()->isNull('i.parameter') |
| 1307 | 1307 | ); |
| 1308 | 1308 | } |
| 1309 | - foreach($filters['params'] as $param) { |
|
| 1309 | + foreach ($filters['params'] as $param) { |
|
| 1310 | 1310 | $propParamExpressions[] = $query->expr()->andX( |
| 1311 | 1311 | $query->expr()->eq('i.name', $query->createNamedParameter($param['property'])), |
| 1312 | 1312 | $query->expr()->eq('i.parameter', $query->createNamedParameter($param['parameter'])) |
@@ -1338,8 +1338,8 @@ discard block |
||
| 1338 | 1338 | $stmt = $query->execute(); |
| 1339 | 1339 | |
| 1340 | 1340 | $result = []; |
| 1341 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1342 | - $path = $uriMapper[$row['calendarid']] . '/' . $row['uri']; |
|
| 1341 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1342 | + $path = $uriMapper[$row['calendarid']].'/'.$row['uri']; |
|
| 1343 | 1343 | if (!in_array($path, $result)) { |
| 1344 | 1344 | $result[] = $path; |
| 1345 | 1345 | } |
@@ -1377,7 +1377,7 @@ discard block |
||
| 1377 | 1377 | } |
| 1378 | 1378 | |
| 1379 | 1379 | $or = $innerQuery->expr()->orX(); |
| 1380 | - foreach($searchProperties as $searchProperty) { |
|
| 1380 | + foreach ($searchProperties as $searchProperty) { |
|
| 1381 | 1381 | $or->add($innerQuery->expr()->eq('op.name', |
| 1382 | 1382 | $outerQuery->createNamedParameter($searchProperty))); |
| 1383 | 1383 | } |
@@ -1385,8 +1385,8 @@ discard block |
||
| 1385 | 1385 | |
| 1386 | 1386 | if ($pattern !== '') { |
| 1387 | 1387 | $innerQuery->andWhere($innerQuery->expr()->iLike('op.value', |
| 1388 | - $outerQuery->createNamedParameter('%' . |
|
| 1389 | - $this->db->escapeLikeParameter($pattern) . '%'))); |
|
| 1388 | + $outerQuery->createNamedParameter('%'. |
|
| 1389 | + $this->db->escapeLikeParameter($pattern).'%'))); |
|
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | 1392 | $outerQuery->select('c.id', 'c.calendardata', 'c.componenttype', 'c.uid', 'c.uri') |
@@ -1406,7 +1406,7 @@ discard block |
||
| 1406 | 1406 | |
| 1407 | 1407 | if (isset($options['types'])) { |
| 1408 | 1408 | $or = $outerQuery->expr()->orX(); |
| 1409 | - foreach($options['types'] as $type) { |
|
| 1409 | + foreach ($options['types'] as $type) { |
|
| 1410 | 1410 | $or->add($outerQuery->expr()->eq('componenttype', |
| 1411 | 1411 | $outerQuery->createNamedParameter($type))); |
| 1412 | 1412 | } |
@@ -1431,7 +1431,7 @@ discard block |
||
| 1431 | 1431 | $comps = $calendarData->getComponents(); |
| 1432 | 1432 | $objects = []; |
| 1433 | 1433 | $timezones = []; |
| 1434 | - foreach($comps as $comp) { |
|
| 1434 | + foreach ($comps as $comp) { |
|
| 1435 | 1435 | if ($comp instanceof VTimeZone) { |
| 1436 | 1436 | $timezones[] = $comp; |
| 1437 | 1437 | } else { |
@@ -1468,7 +1468,7 @@ discard block |
||
| 1468 | 1468 | }); |
| 1469 | 1469 | $validationRules = $comp->getValidationRules(); |
| 1470 | 1470 | |
| 1471 | - foreach($subComponents as $subComponent) { |
|
| 1471 | + foreach ($subComponents as $subComponent) { |
|
| 1472 | 1472 | $name = $subComponent->name; |
| 1473 | 1473 | if (!isset($data[$name])) { |
| 1474 | 1474 | $data[$name] = []; |
@@ -1476,7 +1476,7 @@ discard block |
||
| 1476 | 1476 | $data[$name][] = $this->transformSearchData($subComponent); |
| 1477 | 1477 | } |
| 1478 | 1478 | |
| 1479 | - foreach($properties as $property) { |
|
| 1479 | + foreach ($properties as $property) { |
|
| 1480 | 1480 | $name = $property->name; |
| 1481 | 1481 | if (!isset($validationRules[$name])) { |
| 1482 | 1482 | $validationRules[$name] = '*'; |
@@ -1546,7 +1546,7 @@ discard block |
||
| 1546 | 1546 | $stmt = $query->execute(); |
| 1547 | 1547 | |
| 1548 | 1548 | if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
| 1549 | - return $row['calendaruri'] . '/' . $row['objecturi']; |
|
| 1549 | + return $row['calendaruri'].'/'.$row['objecturi']; |
|
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | 1552 | return null; |
@@ -1611,7 +1611,7 @@ discard block |
||
| 1611 | 1611 | function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
| 1612 | 1612 | // Current synctoken |
| 1613 | 1613 | $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
| 1614 | - $stmt->execute([ $calendarId ]); |
|
| 1614 | + $stmt->execute([$calendarId]); |
|
| 1615 | 1615 | $currentToken = $stmt->fetchColumn(0); |
| 1616 | 1616 | |
| 1617 | 1617 | if (is_null($currentToken)) { |
@@ -1628,8 +1628,8 @@ discard block |
||
| 1628 | 1628 | if ($syncToken) { |
| 1629 | 1629 | |
| 1630 | 1630 | $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
| 1631 | - if ($limit>0) { |
|
| 1632 | - $query.= " LIMIT " . (int)$limit; |
|
| 1631 | + if ($limit > 0) { |
|
| 1632 | + $query .= " LIMIT ".(int) $limit; |
|
| 1633 | 1633 | } |
| 1634 | 1634 | |
| 1635 | 1635 | // Fetching all changes |
@@ -1640,15 +1640,15 @@ discard block |
||
| 1640 | 1640 | |
| 1641 | 1641 | // This loop ensures that any duplicates are overwritten, only the |
| 1642 | 1642 | // last change on a node is relevant. |
| 1643 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1643 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1644 | 1644 | |
| 1645 | 1645 | $changes[$row['uri']] = $row['operation']; |
| 1646 | 1646 | |
| 1647 | 1647 | } |
| 1648 | 1648 | |
| 1649 | - foreach($changes as $uri => $operation) { |
|
| 1649 | + foreach ($changes as $uri => $operation) { |
|
| 1650 | 1650 | |
| 1651 | - switch($operation) { |
|
| 1651 | + switch ($operation) { |
|
| 1652 | 1652 | case 1 : |
| 1653 | 1653 | $result['added'][] = $uri; |
| 1654 | 1654 | break; |
@@ -1718,10 +1718,10 @@ discard block |
||
| 1718 | 1718 | ->from('calendarsubscriptions') |
| 1719 | 1719 | ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
| 1720 | 1720 | ->orderBy('calendarorder', 'asc'); |
| 1721 | - $stmt =$query->execute(); |
|
| 1721 | + $stmt = $query->execute(); |
|
| 1722 | 1722 | |
| 1723 | 1723 | $subscriptions = []; |
| 1724 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1724 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 1725 | 1725 | |
| 1726 | 1726 | $subscription = [ |
| 1727 | 1727 | 'id' => $row['id'], |
@@ -1730,10 +1730,10 @@ discard block |
||
| 1730 | 1730 | 'source' => $row['source'], |
| 1731 | 1731 | 'lastmodified' => $row['lastmodified'], |
| 1732 | 1732 | |
| 1733 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
| 1733 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
| 1734 | 1734 | ]; |
| 1735 | 1735 | |
| 1736 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
| 1736 | + foreach ($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
| 1737 | 1737 | if (!is_null($row[$dbName])) { |
| 1738 | 1738 | $subscription[$xmlName] = $row[$dbName]; |
| 1739 | 1739 | } |
@@ -1772,7 +1772,7 @@ discard block |
||
| 1772 | 1772 | |
| 1773 | 1773 | $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
| 1774 | 1774 | |
| 1775 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
| 1775 | + foreach ($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
| 1776 | 1776 | if (array_key_exists($xmlName, $properties)) { |
| 1777 | 1777 | $values[$dbName] = $properties[$xmlName]; |
| 1778 | 1778 | if (in_array($dbName, $propertiesBoolean)) { |
@@ -1823,7 +1823,7 @@ discard block |
||
| 1823 | 1823 | |
| 1824 | 1824 | $newValues = []; |
| 1825 | 1825 | |
| 1826 | - foreach($mutations as $propertyName=>$propertyValue) { |
|
| 1826 | + foreach ($mutations as $propertyName=>$propertyValue) { |
|
| 1827 | 1827 | if ($propertyName === '{http://calendarserver.org/ns/}source') { |
| 1828 | 1828 | $newValues['source'] = $propertyValue->getHref(); |
| 1829 | 1829 | } else { |
@@ -1835,7 +1835,7 @@ discard block |
||
| 1835 | 1835 | $query = $this->db->getQueryBuilder(); |
| 1836 | 1836 | $query->update('calendarsubscriptions') |
| 1837 | 1837 | ->set('lastmodified', $query->createNamedParameter(time())); |
| 1838 | - foreach($newValues as $fieldName=>$value) { |
|
| 1838 | + foreach ($newValues as $fieldName=>$value) { |
|
| 1839 | 1839 | $query->set($fieldName, $query->createNamedParameter($value)); |
| 1840 | 1840 | } |
| 1841 | 1841 | $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
@@ -1885,7 +1885,7 @@ discard block |
||
| 1885 | 1885 | |
| 1886 | 1886 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 1887 | 1887 | |
| 1888 | - if(!$row) { |
|
| 1888 | + if (!$row) { |
|
| 1889 | 1889 | return null; |
| 1890 | 1890 | } |
| 1891 | 1891 | |
@@ -1893,8 +1893,8 @@ discard block |
||
| 1893 | 1893 | 'uri' => $row['uri'], |
| 1894 | 1894 | 'calendardata' => $row['calendardata'], |
| 1895 | 1895 | 'lastmodified' => $row['lastmodified'], |
| 1896 | - 'etag' => '"' . $row['etag'] . '"', |
|
| 1897 | - 'size' => (int)$row['size'], |
|
| 1896 | + 'etag' => '"'.$row['etag'].'"', |
|
| 1897 | + 'size' => (int) $row['size'], |
|
| 1898 | 1898 | ]; |
| 1899 | 1899 | } |
| 1900 | 1900 | |
@@ -1917,13 +1917,13 @@ discard block |
||
| 1917 | 1917 | ->execute(); |
| 1918 | 1918 | |
| 1919 | 1919 | $result = []; |
| 1920 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
| 1920 | + foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
| 1921 | 1921 | $result[] = [ |
| 1922 | 1922 | 'calendardata' => $row['calendardata'], |
| 1923 | 1923 | 'uri' => $row['uri'], |
| 1924 | 1924 | 'lastmodified' => $row['lastmodified'], |
| 1925 | - 'etag' => '"' . $row['etag'] . '"', |
|
| 1926 | - 'size' => (int)$row['size'], |
|
| 1925 | + 'etag' => '"'.$row['etag'].'"', |
|
| 1926 | + 'size' => (int) $row['size'], |
|
| 1927 | 1927 | ]; |
| 1928 | 1928 | } |
| 1929 | 1929 | |
@@ -2015,10 +2015,10 @@ discard block |
||
| 2015 | 2015 | $lastOccurrence = null; |
| 2016 | 2016 | $uid = null; |
| 2017 | 2017 | $classification = self::CLASSIFICATION_PUBLIC; |
| 2018 | - foreach($vObject->getComponents() as $component) { |
|
| 2019 | - if ($component->name!=='VTIMEZONE') { |
|
| 2018 | + foreach ($vObject->getComponents() as $component) { |
|
| 2019 | + if ($component->name !== 'VTIMEZONE') { |
|
| 2020 | 2020 | $componentType = $component->name; |
| 2021 | - $uid = (string)$component->UID; |
|
| 2021 | + $uid = (string) $component->UID; |
|
| 2022 | 2022 | break; |
| 2023 | 2023 | } |
| 2024 | 2024 | } |
@@ -2043,13 +2043,13 @@ discard block |
||
| 2043 | 2043 | $lastOccurrence = $firstOccurrence; |
| 2044 | 2044 | } |
| 2045 | 2045 | } else { |
| 2046 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
| 2046 | + $it = new EventIterator($vObject, (string) $component->UID); |
|
| 2047 | 2047 | $maxDate = new \DateTime(self::MAX_DATE); |
| 2048 | 2048 | if ($it->isInfinite()) { |
| 2049 | 2049 | $lastOccurrence = $maxDate->getTimestamp(); |
| 2050 | 2050 | } else { |
| 2051 | 2051 | $end = $it->getDtEnd(); |
| 2052 | - while($it->valid() && $end < $maxDate) { |
|
| 2052 | + while ($it->valid() && $end < $maxDate) { |
|
| 2053 | 2053 | $end = $it->getDtEnd(); |
| 2054 | 2054 | $it->next(); |
| 2055 | 2055 | |
@@ -2289,10 +2289,10 @@ discard block |
||
| 2289 | 2289 | $result->closeCursor(); |
| 2290 | 2290 | |
| 2291 | 2291 | if (!isset($objectIds['id'])) { |
| 2292 | - throw new \InvalidArgumentException('Calendarobject does not exists: ' . $uri); |
|
| 2292 | + throw new \InvalidArgumentException('Calendarobject does not exists: '.$uri); |
|
| 2293 | 2293 | } |
| 2294 | 2294 | |
| 2295 | - return (int)$objectIds['id']; |
|
| 2295 | + return (int) $objectIds['id']; |
|
| 2296 | 2296 | } |
| 2297 | 2297 | |
| 2298 | 2298 | private function convertPrincipal($principalUri, $toV2) { |
@@ -2307,8 +2307,8 @@ discard block |
||
| 2307 | 2307 | } |
| 2308 | 2308 | |
| 2309 | 2309 | private function addOwnerPrincipal(&$calendarInfo) { |
| 2310 | - $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'; |
|
| 2311 | - $displaynameKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'; |
|
| 2310 | + $ownerPrincipalKey = '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal'; |
|
| 2311 | + $displaynameKey = '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD.'}owner-displayname'; |
|
| 2312 | 2312 | if (isset($calendarInfo[$ownerPrincipalKey])) { |
| 2313 | 2313 | $uri = $calendarInfo[$ownerPrincipalKey]; |
| 2314 | 2314 | } else { |
@@ -28,92 +28,92 @@ |
||
| 28 | 28 | |
| 29 | 29 | class CalendarImpl implements ICalendar { |
| 30 | 30 | |
| 31 | - /** @var CalDavBackend */ |
|
| 32 | - private $backend; |
|
| 31 | + /** @var CalDavBackend */ |
|
| 32 | + private $backend; |
|
| 33 | 33 | |
| 34 | - /** @var Calendar */ |
|
| 35 | - private $calendar; |
|
| 34 | + /** @var Calendar */ |
|
| 35 | + private $calendar; |
|
| 36 | 36 | |
| 37 | - /** @var array */ |
|
| 38 | - private $calendarInfo; |
|
| 37 | + /** @var array */ |
|
| 38 | + private $calendarInfo; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * CalendarImpl constructor. |
|
| 42 | - * |
|
| 43 | - * @param Calendar $calendar |
|
| 44 | - * @param array $calendarInfo |
|
| 45 | - * @param CalDavBackend $backend |
|
| 46 | - */ |
|
| 47 | - public function __construct(Calendar $calendar, array $calendarInfo, |
|
| 48 | - CalDavBackend $backend) { |
|
| 49 | - $this->calendar = $calendar; |
|
| 50 | - $this->calendarInfo = $calendarInfo; |
|
| 51 | - $this->backend = $backend; |
|
| 52 | - } |
|
| 40 | + /** |
|
| 41 | + * CalendarImpl constructor. |
|
| 42 | + * |
|
| 43 | + * @param Calendar $calendar |
|
| 44 | + * @param array $calendarInfo |
|
| 45 | + * @param CalDavBackend $backend |
|
| 46 | + */ |
|
| 47 | + public function __construct(Calendar $calendar, array $calendarInfo, |
|
| 48 | + CalDavBackend $backend) { |
|
| 49 | + $this->calendar = $calendar; |
|
| 50 | + $this->calendarInfo = $calendarInfo; |
|
| 51 | + $this->backend = $backend; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return string defining the technical unique key |
|
| 56 | - * @since 13.0.0 |
|
| 57 | - */ |
|
| 58 | - public function getKey() { |
|
| 59 | - return $this->calendarInfo['id']; |
|
| 60 | - } |
|
| 54 | + /** |
|
| 55 | + * @return string defining the technical unique key |
|
| 56 | + * @since 13.0.0 |
|
| 57 | + */ |
|
| 58 | + public function getKey() { |
|
| 59 | + return $this->calendarInfo['id']; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
| 64 | - * @return null|string |
|
| 65 | - * @since 13.0.0 |
|
| 66 | - */ |
|
| 67 | - public function getDisplayName() { |
|
| 68 | - return $this->calendarInfo['{DAV:}displayname']; |
|
| 69 | - } |
|
| 62 | + /** |
|
| 63 | + * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
| 64 | + * @return null|string |
|
| 65 | + * @since 13.0.0 |
|
| 66 | + */ |
|
| 67 | + public function getDisplayName() { |
|
| 68 | + return $this->calendarInfo['{DAV:}displayname']; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Calendar color |
|
| 73 | - * @return null|string |
|
| 74 | - * @since 13.0.0 |
|
| 75 | - */ |
|
| 76 | - public function getDisplayColor() { |
|
| 77 | - return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color']; |
|
| 78 | - } |
|
| 71 | + /** |
|
| 72 | + * Calendar color |
|
| 73 | + * @return null|string |
|
| 74 | + * @since 13.0.0 |
|
| 75 | + */ |
|
| 76 | + public function getDisplayColor() { |
|
| 77 | + return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color']; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @param string $pattern which should match within the $searchProperties |
|
| 82 | - * @param array $searchProperties defines the properties within the query pattern should match |
|
| 83 | - * @param array $options - optional parameters: |
|
| 84 | - * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]] |
|
| 85 | - * @param integer|null $limit - limit number of search results |
|
| 86 | - * @param integer|null $offset - offset for paging of search results |
|
| 87 | - * @return array an array of events/journals/todos which are arrays of key-value-pairs |
|
| 88 | - * @since 13.0.0 |
|
| 89 | - */ |
|
| 90 | - public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null) { |
|
| 91 | - return $this->backend->search($this->calendarInfo, $pattern, |
|
| 92 | - $searchProperties, $options, $limit, $offset); |
|
| 93 | - } |
|
| 80 | + /** |
|
| 81 | + * @param string $pattern which should match within the $searchProperties |
|
| 82 | + * @param array $searchProperties defines the properties within the query pattern should match |
|
| 83 | + * @param array $options - optional parameters: |
|
| 84 | + * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]] |
|
| 85 | + * @param integer|null $limit - limit number of search results |
|
| 86 | + * @param integer|null $offset - offset for paging of search results |
|
| 87 | + * @return array an array of events/journals/todos which are arrays of key-value-pairs |
|
| 88 | + * @since 13.0.0 |
|
| 89 | + */ |
|
| 90 | + public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null) { |
|
| 91 | + return $this->backend->search($this->calendarInfo, $pattern, |
|
| 92 | + $searchProperties, $options, $limit, $offset); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * @return integer build up using \OCP\Constants |
|
| 97 | - * @since 13.0.0 |
|
| 98 | - */ |
|
| 99 | - public function getPermissions() { |
|
| 100 | - $permissions = $this->calendar->getACL(); |
|
| 101 | - $result = 0; |
|
| 102 | - foreach ($permissions as $permission) { |
|
| 103 | - switch($permission['privilege']) { |
|
| 104 | - case '{DAV:}read': |
|
| 105 | - $result |= Constants::PERMISSION_READ; |
|
| 106 | - break; |
|
| 107 | - case '{DAV:}write': |
|
| 108 | - $result |= Constants::PERMISSION_CREATE; |
|
| 109 | - $result |= Constants::PERMISSION_UPDATE; |
|
| 110 | - break; |
|
| 111 | - case '{DAV:}all': |
|
| 112 | - $result |= Constants::PERMISSION_ALL; |
|
| 113 | - break; |
|
| 114 | - } |
|
| 115 | - } |
|
| 95 | + /** |
|
| 96 | + * @return integer build up using \OCP\Constants |
|
| 97 | + * @since 13.0.0 |
|
| 98 | + */ |
|
| 99 | + public function getPermissions() { |
|
| 100 | + $permissions = $this->calendar->getACL(); |
|
| 101 | + $result = 0; |
|
| 102 | + foreach ($permissions as $permission) { |
|
| 103 | + switch($permission['privilege']) { |
|
| 104 | + case '{DAV:}read': |
|
| 105 | + $result |= Constants::PERMISSION_READ; |
|
| 106 | + break; |
|
| 107 | + case '{DAV:}write': |
|
| 108 | + $result |= Constants::PERMISSION_CREATE; |
|
| 109 | + $result |= Constants::PERMISSION_UPDATE; |
|
| 110 | + break; |
|
| 111 | + case '{DAV:}all': |
|
| 112 | + $result |= Constants::PERMISSION_ALL; |
|
| 113 | + break; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - return $result; |
|
| 118 | - } |
|
| 117 | + return $result; |
|
| 118 | + } |
|
| 119 | 119 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @return array an array of events/journals/todos which are arrays of key-value-pairs |
| 88 | 88 | * @since 13.0.0 |
| 89 | 89 | */ |
| 90 | - public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null) { |
|
| 90 | + public function search($pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null) { |
|
| 91 | 91 | return $this->backend->search($this->calendarInfo, $pattern, |
| 92 | 92 | $searchProperties, $options, $limit, $offset); |
| 93 | 93 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $permissions = $this->calendar->getACL(); |
| 101 | 101 | $result = 0; |
| 102 | 102 | foreach ($permissions as $permission) { |
| 103 | - switch($permission['privilege']) { |
|
| 103 | + switch ($permission['privilege']) { |
|
| 104 | 104 | case '{DAV:}read': |
| 105 | 105 | $result |= Constants::PERMISSION_READ; |
| 106 | 106 | break; |