diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php index 8fffe3855dff1..e04653ddea1ec 100644 --- a/apps/dav/appinfo/v1/caldav.php +++ b/apps/dav/appinfo/v1/caldav.php @@ -57,8 +57,10 @@ $userManager = \OC::$server->getUserManager(); $random = \OC::$server->getSecureRandom(); $logger = \OC::$server->getLogger(); -$dispatcher = \OC::$server->getEventDispatcher(); -$calDavBackend = new CalDavBackend($db, $principalBackend, $userManager, \OC::$server->getGroupManager(), $random, $logger, $dispatcher, true); +$dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class); +$legacyDispatcher = \OC::$server->getEventDispatcher(); + +$calDavBackend = new CalDavBackend($db, $principalBackend, $userManager, \OC::$server->getGroupManager(), $random, $logger, $dispatcher, $legacyDispatcher, true); $debugging = \OC::$server->getConfig()->getSystemValue('debug', false); $sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes'; diff --git a/apps/dav/appinfo/v1/carddav.php b/apps/dav/appinfo/v1/carddav.php index cef3b6cec0692..dbab1ae9681a0 100644 --- a/apps/dav/appinfo/v1/carddav.php +++ b/apps/dav/appinfo/v1/carddav.php @@ -57,7 +57,7 @@ 'principals/' ); $db = \OC::$server->getDatabaseConnection(); -$cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->getEventDispatcher()); +$cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), \OC::$server->getEventDispatcher()); $debugging = \OC::$server->getConfig()->getSystemValue('debug', false); diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php index b1b01885eef72..0e465971a5eed 100644 --- a/apps/dav/composer/composer/autoload_classmap.php +++ b/apps/dav/composer/composer/autoload_classmap.php @@ -170,7 +170,29 @@ 'OCA\\DAV\\Direct\\DirectHome' => $baseDir . '/../lib/Direct/DirectHome.php', 'OCA\\DAV\\Direct\\Server' => $baseDir . '/../lib/Direct/Server.php', 'OCA\\DAV\\Direct\\ServerFactory' => $baseDir . '/../lib/Direct/ServerFactory.php', + 'OCA\\DAV\\Events\\AddressBookCreatedEvent' => $baseDir . '/../lib/Events/AddressBookCreatedEvent.php', + 'OCA\\DAV\\Events\\AddressBookDeletedEvent' => $baseDir . '/../lib/Events/AddressBookDeletedEvent.php', + 'OCA\\DAV\\Events\\AddressBookShareUpdatedEvent' => $baseDir . '/../lib/Events/AddressBookShareUpdatedEvent.php', + 'OCA\\DAV\\Events\\AddressBookUpdatedEvent' => $baseDir . '/../lib/Events/AddressBookUpdatedEvent.php', + 'OCA\\DAV\\Events\\CachedCalendarObjectCreatedEvent' => $baseDir . '/../lib/Events/CachedCalendarObjectCreatedEvent.php', + 'OCA\\DAV\\Events\\CachedCalendarObjectDeletedEvent' => $baseDir . '/../lib/Events/CachedCalendarObjectDeletedEvent.php', + 'OCA\\DAV\\Events\\CachedCalendarObjectUpdatedEvent' => $baseDir . '/../lib/Events/CachedCalendarObjectUpdatedEvent.php', + 'OCA\\DAV\\Events\\CalendarCreatedEvent' => $baseDir . '/../lib/Events/CalendarCreatedEvent.php', + 'OCA\\DAV\\Events\\CalendarDeletedEvent' => $baseDir . '/../lib/Events/CalendarDeletedEvent.php', + 'OCA\\DAV\\Events\\CalendarObjectCreatedEvent' => $baseDir . '/../lib/Events/CalendarObjectCreatedEvent.php', + 'OCA\\DAV\\Events\\CalendarObjectDeletedEvent' => $baseDir . '/../lib/Events/CalendarObjectDeletedEvent.php', + 'OCA\\DAV\\Events\\CalendarObjectUpdatedEvent' => $baseDir . '/../lib/Events/CalendarObjectUpdatedEvent.php', + 'OCA\\DAV\\Events\\CalendarPublishedEvent' => $baseDir . '/../lib/Events/CalendarPublishedEvent.php', + 'OCA\\DAV\\Events\\CalendarShareUpdatedEvent' => $baseDir . '/../lib/Events/CalendarShareUpdatedEvent.php', + 'OCA\\DAV\\Events\\CalendarUnpublishedEvent' => $baseDir . '/../lib/Events/CalendarUnpublishedEvent.php', + 'OCA\\DAV\\Events\\CalendarUpdatedEvent' => $baseDir . '/../lib/Events/CalendarUpdatedEvent.php', + 'OCA\\DAV\\Events\\CardCreatedEvent' => $baseDir . '/../lib/Events/CardCreatedEvent.php', + 'OCA\\DAV\\Events\\CardDeletedEvent' => $baseDir . '/../lib/Events/CardDeletedEvent.php', + 'OCA\\DAV\\Events\\CardUpdatedEvent' => $baseDir . '/../lib/Events/CardUpdatedEvent.php', 'OCA\\DAV\\Events\\SabrePluginAuthInitEvent' => $baseDir . '/../lib/Events/SabrePluginAuthInitEvent.php', + 'OCA\\DAV\\Events\\SubscriptionCreatedEvent' => $baseDir . '/../lib/Events/SubscriptionCreatedEvent.php', + 'OCA\\DAV\\Events\\SubscriptionDeletedEvent' => $baseDir . '/../lib/Events/SubscriptionDeletedEvent.php', + 'OCA\\DAV\\Events\\SubscriptionUpdatedEvent' => $baseDir . '/../lib/Events/SubscriptionUpdatedEvent.php', 'OCA\\DAV\\Exception\\UnsupportedLimitOnInitialSyncException' => $baseDir . '/../lib/Exception/UnsupportedLimitOnInitialSyncException.php', 'OCA\\DAV\\Files\\BrowserErrorPagePlugin' => $baseDir . '/../lib/Files/BrowserErrorPagePlugin.php', 'OCA\\DAV\\Files\\FileSearchBackend' => $baseDir . '/../lib/Files/FileSearchBackend.php', diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php index ccd0d41d68baa..4788a41ef0092 100644 --- a/apps/dav/composer/composer/autoload_static.php +++ b/apps/dav/composer/composer/autoload_static.php @@ -185,7 +185,29 @@ class ComposerStaticInitDAV 'OCA\\DAV\\Direct\\DirectHome' => __DIR__ . '/..' . '/../lib/Direct/DirectHome.php', 'OCA\\DAV\\Direct\\Server' => __DIR__ . '/..' . '/../lib/Direct/Server.php', 'OCA\\DAV\\Direct\\ServerFactory' => __DIR__ . '/..' . '/../lib/Direct/ServerFactory.php', + 'OCA\\DAV\\Events\\AddressBookCreatedEvent' => __DIR__ . '/..' . '/../lib/Events/AddressBookCreatedEvent.php', + 'OCA\\DAV\\Events\\AddressBookDeletedEvent' => __DIR__ . '/..' . '/../lib/Events/AddressBookDeletedEvent.php', + 'OCA\\DAV\\Events\\AddressBookShareUpdatedEvent' => __DIR__ . '/..' . '/../lib/Events/AddressBookShareUpdatedEvent.php', + 'OCA\\DAV\\Events\\AddressBookUpdatedEvent' => __DIR__ . '/..' . '/../lib/Events/AddressBookUpdatedEvent.php', + 'OCA\\DAV\\Events\\CachedCalendarObjectCreatedEvent' => __DIR__ . '/..' . '/../lib/Events/CachedCalendarObjectCreatedEvent.php', + 'OCA\\DAV\\Events\\CachedCalendarObjectDeletedEvent' => __DIR__ . '/..' . '/../lib/Events/CachedCalendarObjectDeletedEvent.php', + 'OCA\\DAV\\Events\\CachedCalendarObjectUpdatedEvent' => __DIR__ . '/..' . '/../lib/Events/CachedCalendarObjectUpdatedEvent.php', + 'OCA\\DAV\\Events\\CalendarCreatedEvent' => __DIR__ . '/..' . '/../lib/Events/CalendarCreatedEvent.php', + 'OCA\\DAV\\Events\\CalendarDeletedEvent' => __DIR__ . '/..' . '/../lib/Events/CalendarDeletedEvent.php', + 'OCA\\DAV\\Events\\CalendarObjectCreatedEvent' => __DIR__ . '/..' . '/../lib/Events/CalendarObjectCreatedEvent.php', + 'OCA\\DAV\\Events\\CalendarObjectDeletedEvent' => __DIR__ . '/..' . '/../lib/Events/CalendarObjectDeletedEvent.php', + 'OCA\\DAV\\Events\\CalendarObjectUpdatedEvent' => __DIR__ . '/..' . '/../lib/Events/CalendarObjectUpdatedEvent.php', + 'OCA\\DAV\\Events\\CalendarPublishedEvent' => __DIR__ . '/..' . '/../lib/Events/CalendarPublishedEvent.php', + 'OCA\\DAV\\Events\\CalendarShareUpdatedEvent' => __DIR__ . '/..' . '/../lib/Events/CalendarShareUpdatedEvent.php', + 'OCA\\DAV\\Events\\CalendarUnpublishedEvent' => __DIR__ . '/..' . '/../lib/Events/CalendarUnpublishedEvent.php', + 'OCA\\DAV\\Events\\CalendarUpdatedEvent' => __DIR__ . '/..' . '/../lib/Events/CalendarUpdatedEvent.php', + 'OCA\\DAV\\Events\\CardCreatedEvent' => __DIR__ . '/..' . '/../lib/Events/CardCreatedEvent.php', + 'OCA\\DAV\\Events\\CardDeletedEvent' => __DIR__ . '/..' . '/../lib/Events/CardDeletedEvent.php', + 'OCA\\DAV\\Events\\CardUpdatedEvent' => __DIR__ . '/..' . '/../lib/Events/CardUpdatedEvent.php', 'OCA\\DAV\\Events\\SabrePluginAuthInitEvent' => __DIR__ . '/..' . '/../lib/Events/SabrePluginAuthInitEvent.php', + 'OCA\\DAV\\Events\\SubscriptionCreatedEvent' => __DIR__ . '/..' . '/../lib/Events/SubscriptionCreatedEvent.php', + 'OCA\\DAV\\Events\\SubscriptionDeletedEvent' => __DIR__ . '/..' . '/../lib/Events/SubscriptionDeletedEvent.php', + 'OCA\\DAV\\Events\\SubscriptionUpdatedEvent' => __DIR__ . '/..' . '/../lib/Events/SubscriptionUpdatedEvent.php', 'OCA\\DAV\\Exception\\UnsupportedLimitOnInitialSyncException' => __DIR__ . '/..' . '/../lib/Exception/UnsupportedLimitOnInitialSyncException.php', 'OCA\\DAV\\Files\\BrowserErrorPagePlugin' => __DIR__ . '/..' . '/../lib/Files/BrowserErrorPagePlugin.php', 'OCA\\DAV\\Files\\FileSearchBackend' => __DIR__ . '/..' . '/../lib/Files/FileSearchBackend.php', diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 159f5c7167355..f369fa40b8eff 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -39,7 +39,23 @@ use OCA\DAV\Connector\Sabre\Principal; use OCA\DAV\DAV\Sharing\Backend; use OCA\DAV\DAV\Sharing\IShareable; +use OCA\DAV\Events\CachedCalendarObjectCreatedEvent; +use OCA\DAV\Events\CachedCalendarObjectDeletedEvent; +use OCA\DAV\Events\CachedCalendarObjectUpdatedEvent; +use OCA\DAV\Events\CalendarCreatedEvent; +use OCA\DAV\Events\CalendarDeletedEvent; +use OCA\DAV\Events\CalendarObjectCreatedEvent; +use OCA\DAV\Events\CalendarObjectDeletedEvent; +use OCA\DAV\Events\CalendarObjectUpdatedEvent; +use OCA\DAV\Events\CalendarPublishedEvent; +use OCA\DAV\Events\CalendarShareUpdatedEvent; +use OCA\DAV\Events\CalendarUnpublishedEvent; +use OCA\DAV\Events\CalendarUpdatedEvent; +use OCA\DAV\Events\SubscriptionCreatedEvent; +use OCA\DAV\Events\SubscriptionDeletedEvent; +use OCA\DAV\Events\SubscriptionUpdatedEvent; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IDBConnection; use OCP\IGroupManager; use OCP\ILogger; @@ -166,9 +182,12 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription /** @var ILogger */ private $logger; - /** @var EventDispatcherInterface */ + /** @var IEventDispatcher */ private $dispatcher; + /** @var EventDispatcherInterface */ + private $legacyDispatcher; + /** @var bool */ private $legacyEndpoint; @@ -184,7 +203,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @param IGroupManager $groupManager * @param ISecureRandom $random * @param ILogger $logger - * @param EventDispatcherInterface $dispatcher + * @param IEventDispatcher $dispatcher + * @param EventDispatcherInterface $legacyDispatcher * @param bool $legacyEndpoint */ public function __construct(IDBConnection $db, @@ -193,7 +213,8 @@ public function __construct(IDBConnection $db, IGroupManager $groupManager, ISecureRandom $random, ILogger $logger, - EventDispatcherInterface $dispatcher, + IEventDispatcher $dispatcher, + EventDispatcherInterface $legacyDispatcher, bool $legacyEndpoint = false) { $this->db = $db; $this->principalBackend = $principalBackend; @@ -202,6 +223,7 @@ public function __construct(IDBConnection $db, $this->random = $random; $this->logger = $logger; $this->dispatcher = $dispatcher; + $this->legacyDispatcher = $legacyDispatcher; $this->legacyEndpoint = $legacyEndpoint; } @@ -764,11 +786,13 @@ public function createCalendar($principalUri, $calendarUri, array $properties) { $query->execute(); $calendarId = $query->getLastInsertId(); - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent( + $calendarData = $this->getCalendarById($calendarId); + $this->dispatcher->dispatchTyped(new CalendarCreatedEvent((int)$calendarId, $calendarData)); + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::createCalendar', [ 'calendarId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), + 'calendarData' => $calendarData, ])); return $calendarId; @@ -821,12 +845,15 @@ public function updateCalendar($calendarId, PropPatch $propPatch) { $this->addChange($calendarId, "", 2); - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent( + $calendarData = $this->getCalendarById($calendarId); + $shares = $this->getShares($calendarId); + $this->dispatcher->dispatchTyped(new CalendarUpdatedEvent((int)$calendarId, $calendarData, $shares, $mutations)); + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', [ 'calendarId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), - 'shares' => $this->getShares($calendarId), + 'calendarData' => $calendarData, + 'shares' => $shares, 'propertyMutations' => $mutations, ])); @@ -841,12 +868,15 @@ public function updateCalendar($calendarId, PropPatch $propPatch) { * @return void */ public function deleteCalendar($calendarId) { - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', new GenericEvent( + $calendarData = $this->getCalendarById($calendarId); + $shares = $this->getShares($calendarId); + + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', [ 'calendarId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), - 'shares' => $this->getShares($calendarId), + 'calendarData' => $calendarData, + 'shares' => $shares, ])); $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `calendartype` = ?'); @@ -865,6 +895,10 @@ public function deleteCalendar($calendarId) { ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_CALENDAR))) ->execute(); + + if ($calendarData) { + $this->dispatcher->dispatchTyped(new CalendarDeletedEvent((int)$calendarId, $calendarData, $shares)); + } } /** @@ -1085,29 +1119,37 @@ public function createCalendarObject($calendarId, $objectUri, $calendarData, $ca ->execute(); $this->updateProperties($calendarId, $objectUri, $calendarData, $calendarType); + $this->addChange($calendarId, $objectUri, 1, $calendarType); + $objectRow = $this->getCalendarObject($calendarId, $objectUri, $calendarType); if ($calendarType === self::CALENDAR_TYPE_CALENDAR) { - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( + $calendarRow = $this->getCalendarById($calendarId); + $shares = $this->getShares($calendarId); + + $this->dispatcher->dispatchTyped(new CalendarObjectCreatedEvent((int)$calendarId, $calendarRow, $shares, $objectRow)); + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', [ 'calendarId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), - 'shares' => $this->getShares($calendarId), - 'objectData' => $this->getCalendarObject($calendarId, $objectUri), + 'calendarData' => $calendarRow, + 'shares' => $shares, + 'objectData' => $objectRow, ] )); } else { - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCachedCalendarObject', new GenericEvent( + $subscriptionRow = $this->getSubscriptionById($calendarId); + + $this->dispatcher->dispatchTyped(new CachedCalendarObjectCreatedEvent((int)$calendarId, $subscriptionRow, [], $objectRow)); + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCachedCalendarObject', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::createCachedCalendarObject', [ 'subscriptionId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), - 'shares' => $this->getShares($calendarId), - 'objectData' => $this->getCalendarObject($calendarId, $objectUri), + 'calendarData' => $subscriptionRow, + 'shares' => [], + 'objectData' => $objectRow, ] )); } - $this->addChange($calendarId, $objectUri, 1, $calendarType); return '"' . $extraData['etag'] . '"'; } @@ -1150,32 +1192,39 @@ public function updateCalendarObject($calendarId, $objectUri, $calendarData, $ca ->execute(); $this->updateProperties($calendarId, $objectUri, $calendarData, $calendarType); + $this->addChange($calendarId, $objectUri, 2, $calendarType); - $data = $this->getCalendarObject($calendarId, $objectUri); - if (is_array($data)) { + $objectRow = $this->getCalendarObject($calendarId, $objectUri, $calendarType); + if (is_array($objectRow)) { if ($calendarType === self::CALENDAR_TYPE_CALENDAR) { - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( + $calendarRow = $this->getCalendarById($calendarId); + $shares = $this->getShares($calendarId); + + $this->dispatcher->dispatchTyped(new CalendarObjectUpdatedEvent((int)$calendarId, $calendarRow, $shares, $objectRow)); + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', [ 'calendarId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), - 'shares' => $this->getShares($calendarId), - 'objectData' => $data, + 'calendarData' => $calendarRow, + 'shares' => $shares, + 'objectData' => $objectRow, ] )); } else { - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCachedCalendarObject', new GenericEvent( + $subscriptionRow = $this->getSubscriptionById($calendarId); + + $this->dispatcher->dispatchTyped(new CachedCalendarObjectUpdatedEvent((int)$calendarId, $subscriptionRow, [], $objectRow)); + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCachedCalendarObject', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::updateCachedCalendarObject', [ 'subscriptionId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), - 'shares' => $this->getShares($calendarId), - 'objectData' => $data, + 'calendarData' => $subscriptionRow, + 'shares' => [], + 'objectData' => $objectRow, ] )); } } - $this->addChange($calendarId, $objectUri, 2, $calendarType); return '"' . $extraData['etag'] . '"'; } @@ -1211,22 +1260,29 @@ public function deleteCalendarObject($calendarId, $objectUri, $calendarType=self $data = $this->getCalendarObject($calendarId, $objectUri, $calendarType); if (is_array($data)) { if ($calendarType === self::CALENDAR_TYPE_CALENDAR) { - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( + $calendarRow = $this->getCalendarById($calendarId); + $shares = $this->getShares($calendarId); + + $this->dispatcher->dispatchTyped(new CalendarObjectDeletedEvent((int)$calendarId, $calendarRow, $shares, $data)); + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', [ 'calendarId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), - 'shares' => $this->getShares($calendarId), + 'calendarData' => $calendarRow, + 'shares' => $shares, 'objectData' => $data, ] )); } else { - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCachedCalendarObject', new GenericEvent( + $subscriptionRow = $this->getSubscriptionById($calendarId); + + $this->dispatcher->dispatchTyped(new CachedCalendarObjectDeletedEvent((int)$calendarId, $subscriptionRow, [], $data)); + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCachedCalendarObject', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::deleteCachedCalendarObject', [ 'subscriptionId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), - 'shares' => $this->getShares($calendarId), + 'calendarData' => $subscriptionRow, + 'shares' => [], 'objectData' => $data, ] )); @@ -2060,11 +2116,13 @@ public function createSubscription($principalUri, $uri, array $properties) { $subscriptionId = $this->db->lastInsertId('*PREFIX*calendarsubscriptions'); - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createSubscription', new GenericEvent( + $subscriptionRow = $this->getSubscriptionById($subscriptionId); + $this->dispatcher->dispatchTyped(new SubscriptionCreatedEvent((int)$subscriptionId, $subscriptionRow)); + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createSubscription', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::createSubscription', [ 'subscriptionId' => $subscriptionId, - 'subscriptionData' => $this->getSubscriptionById($subscriptionId), + 'subscriptionData' => $subscriptionRow, ])); return $subscriptionId; @@ -2114,11 +2172,13 @@ public function updateSubscription($subscriptionId, PropPatch $propPatch) { $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) ->execute(); - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateSubscription', new GenericEvent( + $subscriptionRow = $this->getSubscriptionById($subscriptionId); + $this->dispatcher->dispatchTyped(new SubscriptionUpdatedEvent((int)$subscriptionId, $subscriptionRow, [], $mutations)); + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateSubscription', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::updateSubscription', [ 'subscriptionId' => $subscriptionId, - 'subscriptionData' => $this->getSubscriptionById($subscriptionId), + 'subscriptionData' => $subscriptionRow, 'propertyMutations' => $mutations, ])); @@ -2133,7 +2193,9 @@ public function updateSubscription($subscriptionId, PropPatch $propPatch) { * @return void */ public function deleteSubscription($subscriptionId) { - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription', new GenericEvent( + $subscriptionRow = $this->getSubscriptionById($subscriptionId); + + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription', [ 'subscriptionId' => $subscriptionId, @@ -2160,6 +2222,10 @@ public function deleteSubscription($subscriptionId) { ->where($query->expr()->eq('calendarid', $query->createNamedParameter($subscriptionId))) ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION))) ->execute(); + + if ($subscriptionRow) { + $this->dispatcher->dispatchTyped(new SubscriptionDeletedEvent((int)$subscriptionId, $subscriptionRow, [])); + } } /** @@ -2412,16 +2478,21 @@ private function readBlob($cardData) { */ public function updateShares($shareable, $add, $remove) { $calendarId = $shareable->getResourceId(); - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent( + $calendarRow = $this->getCalendarById($calendarId); + $oldShares = $this->getShares($calendarId); + + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::updateShares', [ 'calendarId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), - 'shares' => $this->getShares($calendarId), + 'calendarData' => $calendarRow, + 'shares' => $oldShares, 'add' => $add, 'remove' => $remove, ])); $this->calendarSharingBackend->updateShares($shareable, $add, $remove); + + $this->dispatcher->dispatchTyped(new CalendarShareUpdatedEvent((int)$calendarId, $calendarRow, $oldShares, $add, $remove)); } /** @@ -2440,11 +2511,12 @@ public function getShares($resourceId, $calendarType=self::CALENDAR_TYPE_CALENDA */ public function setPublishStatus($value, $calendar) { $calendarId = $calendar->getResourceId(); - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', new GenericEvent( + $calendarData = $this->getCalendarById($calendarId); + $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', new GenericEvent( '\OCA\DAV\CalDAV\CalDavBackend::updateShares', [ 'calendarId' => $calendarId, - 'calendarData' => $this->getCalendarById($calendarId), + 'calendarData' => $calendarData, 'public' => $value, ])); @@ -2460,12 +2532,16 @@ public function setPublishStatus($value, $calendar) { 'publicuri' => $query->createNamedParameter($publicUri) ]); $query->execute(); + + $this->dispatcher->dispatchTyped(new CalendarPublishedEvent((int)$calendarId, $calendarData, $publicUri)); return $publicUri; } $query->delete('dav_shares') ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); $query->execute(); + + $this->dispatcher->dispatchTyped(new CalendarUnpublishedEvent((int)$calendarId, $calendarData)); return null; } diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index d819c42d286cf..f20b197b9efe9 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -40,7 +40,15 @@ use OCA\DAV\Connector\Sabre\Principal; use OCA\DAV\DAV\Sharing\Backend; use OCA\DAV\DAV\Sharing\IShareable; +use OCA\DAV\Events\AddressBookCreatedEvent; +use OCA\DAV\Events\AddressBookDeletedEvent; +use OCA\DAV\Events\AddressBookShareUpdatedEvent; +use OCA\DAV\Events\AddressBookUpdatedEvent; +use OCA\DAV\Events\CardCreatedEvent; +use OCA\DAV\Events\CardDeletedEvent; +use OCA\DAV\Events\CardUpdatedEvent; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUser; @@ -87,9 +95,12 @@ class CardDavBackend implements BackendInterface, SyncSupport { /** @var IUserManager */ private $userManager; - /** @var EventDispatcherInterface */ + /** @var IEventDispatcher */ private $dispatcher; + /** @var EventDispatcherInterface */ + private $legacyDispatcher; + private $etagCache = []; /** @@ -99,17 +110,20 @@ class CardDavBackend implements BackendInterface, SyncSupport { * @param Principal $principalBackend * @param IUserManager $userManager * @param IGroupManager $groupManager - * @param EventDispatcherInterface $dispatcher + * @param IEventDispatcher $dispatcher + * @param EventDispatcherInterface $legacyDispatcher */ public function __construct(IDBConnection $db, Principal $principalBackend, IUserManager $userManager, IGroupManager $groupManager, - EventDispatcherInterface $dispatcher) { + IEventDispatcher $dispatcher, + EventDispatcherInterface $legacyDispatcher) { $this->db = $db; $this->principalBackend = $principalBackend; $this->userManager = $userManager; $this->dispatcher = $dispatcher; + $this->legacyDispatcher = $legacyDispatcher; $this->sharingBackend = new Backend($this->db, $this->userManager, $groupManager, $principalBackend, 'addressbook'); } @@ -388,6 +402,10 @@ public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatc $this->addChange($addressBookId, "", 2); + $addressBookRow = $this->getAddressBookById($addressBookId); + $shares = $this->getShares($addressBookId); + $this->dispatcher->dispatchTyped(new AddressBookUpdatedEvent((int)$addressBookId, $addressBookRow, $shares, $mutations)); + return true; }); } @@ -441,7 +459,11 @@ public function createAddressBook($principalUri, $url, array $properties) { ->setParameters($values) ->execute(); - return $query->getLastInsertId(); + $addressBookId = $query->getLastInsertId(); + $addressBookRow = $this->getAddressBookById($addressBookId); + $this->dispatcher->dispatchTyped(new AddressBookCreatedEvent((int)$addressBookId, $addressBookRow)); + + return $addressBookId; } /** @@ -451,6 +473,9 @@ public function createAddressBook($principalUri, $url, array $properties) { * @return void */ public function deleteAddressBook($addressBookId) { + $addressBookData = $this->getAddressBookById($addressBookId); + $shares = $this->getShares($addressBookId); + $query = $this->db->getQueryBuilder(); $query->delete($this->dbCardsTable) ->where($query->expr()->eq('addressbookid', $query->createParameter('addressbookid'))) @@ -472,6 +497,10 @@ public function deleteAddressBook($addressBookId) { $query->delete($this->dbCardsPropertiesTable) ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) ->execute(); + + if ($addressBookData) { + $this->dispatcher->dispatchTyped(new AddressBookDeletedEvent((int) $addressBookId, $addressBookData, $shares)); + } } /** @@ -661,7 +690,11 @@ public function createCard($addressBookId, $cardUri, $cardData) { $this->addChange($addressBookId, $cardUri, 1); $this->updateProperties($addressBookId, $cardUri, $cardData); - $this->dispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::createCard', + $addressBookData = $this->getAddressBookById($addressBookId); + $shares = $this->getShares($addressBookId); + $objectRow = $this->getCard($addressBookId, $cardUri); + $this->dispatcher->dispatchTyped(new CardCreatedEvent((int)$addressBookId, $addressBookData, $shares, $objectRow)); + $this->legacyDispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::createCard', new GenericEvent(null, [ 'addressBookId' => $addressBookId, 'cardUri' => $cardUri, @@ -721,7 +754,11 @@ public function updateCard($addressBookId, $cardUri, $cardData) { $this->addChange($addressBookId, $cardUri, 2); $this->updateProperties($addressBookId, $cardUri, $cardData); - $this->dispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::updateCard', + $addressBookData = $this->getAddressBookById($addressBookId); + $shares = $this->getShares($addressBookId); + $objectRow = $this->getCard($addressBookId, $cardUri); + $this->dispatcher->dispatchTyped(new CardUpdatedEvent((int)$addressBookId, $addressBookData, $shares, $objectRow)); + $this->legacyDispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::updateCard', new GenericEvent(null, [ 'addressBookId' => $addressBookId, 'cardUri' => $cardUri, @@ -738,6 +775,10 @@ public function updateCard($addressBookId, $cardUri, $cardData) { * @return bool */ public function deleteCard($addressBookId, $cardUri) { + $addressBookData = $this->getAddressBookById($addressBookId); + $shares = $this->getShares($addressBookId); + $objectRow = $this->getCard($addressBookId, $cardUri); + try { $cardId = $this->getCardId($addressBookId, $cardUri); } catch (\InvalidArgumentException $e) { @@ -751,13 +792,14 @@ public function deleteCard($addressBookId, $cardUri) { $this->addChange($addressBookId, $cardUri, 3); - $this->dispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', - new GenericEvent(null, [ - 'addressBookId' => $addressBookId, - 'cardUri' => $cardUri])); - if ($ret === 1) { if ($cardId !== null) { + $this->dispatcher->dispatchTyped(new CardDeletedEvent((int)$addressBookId, $addressBookData, $shares, $objectRow)); + $this->legacyDispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', + new GenericEvent(null, [ + 'addressBookId' => $addressBookId, + 'cardUri' => $cardUri])); + $this->purgeProperties($addressBookId, $cardId); } return true; @@ -947,7 +989,13 @@ private function readBlob($cardData, &$modified = false) { * @param string[] $remove */ public function updateShares(IShareable $shareable, $add, $remove) { + $addressBookId = $shareable->getResourceId(); + $addressBookData = $this->getAddressBookById($addressBookId); + $oldShares = $this->getShares($addressBookId); + $this->sharingBackend->updateShares($shareable, $add, $remove); + + $this->dispatcher->dispatchTyped(new AddressBookShareUpdatedEvent($addressBookId, $addressBookData, $oldShares, $add, $remove)); } /** diff --git a/apps/dav/lib/Command/CreateCalendar.php b/apps/dav/lib/Command/CreateCalendar.php index d03b573e4abe0..58c6a8c63fb03 100644 --- a/apps/dav/lib/Command/CreateCalendar.php +++ b/apps/dav/lib/Command/CreateCalendar.php @@ -30,6 +30,7 @@ use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\Proxy\ProxyMapper; use OCA\DAV\Connector\Sabre\Principal; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUserManager; @@ -89,10 +90,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int ); $random = \OC::$server->getSecureRandom(); $logger = \OC::$server->getLogger(); - $dispatcher = \OC::$server->getEventDispatcher(); + $dispatcher = \OC::$server->get(IEventDispatcher::class); + $legacyDispatcher = \OC::$server->getEventDispatcher(); $name = $input->getArgument('name'); - $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $this->groupManager, $random, $logger, $dispatcher); + $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $this->groupManager, $random, $logger, $dispatcher, $legacyDispatcher); $caldav->createCalendar("principals/users/$user", $name, []); return 0; } diff --git a/apps/dav/lib/Events/AddressBookCreatedEvent.php b/apps/dav/lib/Events/AddressBookCreatedEvent.php new file mode 100644 index 0000000000000..c0e9b2370f262 --- /dev/null +++ b/apps/dav/lib/Events/AddressBookCreatedEvent.php @@ -0,0 +1,72 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class AddressBookCreatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class AddressBookCreatedEvent extends Event { + + /** @var int */ + private $addressBookId; + + /** @var array */ + private $addressBookData; + + /** + * AddressBookCreatedEvent constructor. + * + * @param int $addressBookId + * @param array $addressBookData + * @since 20.0.0 + */ + public function __construct(int $addressBookId, + array $addressBookData) { + parent::__construct(); + $this->addressBookId = $addressBookId; + $this->addressBookData = $addressBookData; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getAddressBookId(): int { + return $this->addressBookId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getAddressBookData(): array { + return $this->addressBookData; + } +} diff --git a/apps/dav/lib/Events/AddressBookDeletedEvent.php b/apps/dav/lib/Events/AddressBookDeletedEvent.php new file mode 100644 index 0000000000000..39ae3bd2799cd --- /dev/null +++ b/apps/dav/lib/Events/AddressBookDeletedEvent.php @@ -0,0 +1,86 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class AddressBookDeletedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class AddressBookDeletedEvent extends Event { + + /** @var int */ + private $addressBookId; + + /** @var array */ + private $addressBookData; + + /** @var array */ + private $shares; + + /** + * AddressBookDeletedEvent constructor. + * + * @param int $addressBookId + * @param array $addressBookData + * @param array $shares + * @since 20.0.0 + */ + public function __construct(int $addressBookId, + array $addressBookData, + array $shares) { + parent::__construct(); + $this->addressBookId = $addressBookId; + $this->addressBookData = $addressBookData; + $this->shares = $shares; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getAddressBookId():int { + return $this->addressBookId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getAddressBookData(): array { + return $this->addressBookData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } +} diff --git a/apps/dav/lib/Events/AddressBookShareUpdatedEvent.php b/apps/dav/lib/Events/AddressBookShareUpdatedEvent.php new file mode 100644 index 0000000000000..343fb2c6b6b93 --- /dev/null +++ b/apps/dav/lib/Events/AddressBookShareUpdatedEvent.php @@ -0,0 +1,114 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class AddressBookShareUpdatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class AddressBookShareUpdatedEvent extends Event { + + /** @var int */ + private $addressBookId; + + /** @var array */ + private $addressBookData; + + /** @var array */ + private $oldShares; + + /** @var array */ + private $added; + + /** @var array */ + private $removed; + + /** + * AddressBookShareUpdatedEvent constructor. + * + * @param int $addressBookId + * @param array $addressBookData + * @param array $oldShares + * @param array $added + * @param array $removed + * @since 20.0.0 + */ + public function __construct(int $addressBookId, + array $addressBookData, + array $oldShares, + array $added, + array $removed) { + parent::__construct(); + $this->addressBookId = $addressBookId; + $this->addressBookData = $addressBookData; + $this->oldShares = $oldShares; + $this->added = $added; + $this->removed = $removed; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getAddressBookId(): int { + return $this->addressBookId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getAddressBookData(): array { + return $this->addressBookData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getOldShares(): array { + return $this->oldShares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getAdded(): array { + return $this->added; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getRemoved(): array { + return $this->removed; + } +} diff --git a/apps/dav/lib/Events/AddressBookUpdatedEvent.php b/apps/dav/lib/Events/AddressBookUpdatedEvent.php new file mode 100644 index 0000000000000..59fe0b7b28aa5 --- /dev/null +++ b/apps/dav/lib/Events/AddressBookUpdatedEvent.php @@ -0,0 +1,100 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class AddressBookUpdatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class AddressBookUpdatedEvent extends Event { + + /** @var int */ + private $addressBookId; + + /** @var array */ + private $addressBookData; + + /** @var array */ + private $shares; + + /** @var array */ + private $mutations; + + /** + * AddressBookUpdatedEvent constructor. + * + * @param int $addressBookId + * @param array $addressBookData + * @param array $shares + * @param array $mutations + * @since 20.0.0 + */ + public function __construct(int $addressBookId, + array $addressBookData, + array $shares, + array $mutations) { + parent::__construct(); + $this->addressBookId = $addressBookId; + $this->addressBookData = $addressBookData; + $this->shares = $shares; + $this->mutations = $mutations; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getAddressBookId(): int { + return $this->addressBookId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getAddressBookData(): array { + return $this->addressBookData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getMutations(): array { + return $this->mutations; + } +} diff --git a/apps/dav/lib/Events/CachedCalendarObjectCreatedEvent.php b/apps/dav/lib/Events/CachedCalendarObjectCreatedEvent.php new file mode 100644 index 0000000000000..466009ea3682e --- /dev/null +++ b/apps/dav/lib/Events/CachedCalendarObjectCreatedEvent.php @@ -0,0 +1,100 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CachedCalendarObjectCreatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CachedCalendarObjectCreatedEvent extends Event { + + /** @var int */ + private $subscriptionId; + + /** @var array */ + private $subscriptionData; + + /** @var array */ + private $shares; + + /** @var array */ + private $objectData; + + /** + * CachedCalendarObjectCreatedEvent constructor. + * + * @param int $subscriptionId + * @param array $subscriptionData + * @param array $shares + * @param array $objectData + * @since 20.0.0 + */ + public function __construct(int $subscriptionId, + array $subscriptionData, + array $shares, + array $objectData) { + parent::__construct(); + $this->subscriptionId = $subscriptionId; + $this->subscriptionData = $subscriptionData; + $this->shares = $shares; + $this->objectData = $objectData; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getSubscriptionId(): int { + return $this->subscriptionId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getSubscriptionData(): array { + return $this->subscriptionData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getObjectData(): array { + return $this->objectData; + } +} diff --git a/apps/dav/lib/Events/CachedCalendarObjectDeletedEvent.php b/apps/dav/lib/Events/CachedCalendarObjectDeletedEvent.php new file mode 100644 index 0000000000000..fbb2a9cab0bd6 --- /dev/null +++ b/apps/dav/lib/Events/CachedCalendarObjectDeletedEvent.php @@ -0,0 +1,100 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CachedCalendarObjectDeletedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CachedCalendarObjectDeletedEvent extends Event { + + /** @var int */ + private $subscriptionId; + + /** @var array */ + private $subscriptionData; + + /** @var array */ + private $shares; + + /** @var array */ + private $objectData; + + /** + * CachedCalendarObjectDeletedEvent constructor. + * + * @param int $subscriptionId + * @param array $subscriptionData + * @param array $shares + * @param array $objectData + * @since 20.0.0 + */ + public function __construct(int $subscriptionId, + array $subscriptionData, + array $shares, + array $objectData) { + parent::__construct(); + $this->subscriptionId = $subscriptionId; + $this->subscriptionData = $subscriptionData; + $this->shares = $shares; + $this->objectData = $objectData; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getSubscriptionId(): int { + return $this->subscriptionId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getSubscriptionData(): array { + return $this->subscriptionData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getObjectData(): array { + return $this->objectData; + } +} diff --git a/apps/dav/lib/Events/CachedCalendarObjectUpdatedEvent.php b/apps/dav/lib/Events/CachedCalendarObjectUpdatedEvent.php new file mode 100644 index 0000000000000..c2a50c42efee6 --- /dev/null +++ b/apps/dav/lib/Events/CachedCalendarObjectUpdatedEvent.php @@ -0,0 +1,100 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CachedCalendarObjectUpdatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CachedCalendarObjectUpdatedEvent extends Event { + + /** @var int */ + private $subscriptionId; + + /** @var array */ + private $subscriptionData; + + /** @var array */ + private $shares; + + /** @var array */ + private $objectData; + + /** + * CachedCalendarObjectUpdatedEvent constructor. + * + * @param int $subscriptionId + * @param array $subscriptionData + * @param array $shares + * @param array $objectData + * @since 20.0.0 + */ + public function __construct(int $subscriptionId, + array $subscriptionData, + array $shares, + array $objectData) { + parent::__construct(); + $this->subscriptionId = $subscriptionId; + $this->subscriptionData = $subscriptionData; + $this->shares = $shares; + $this->objectData = $objectData; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getSubscriptionId(): int { + return $this->subscriptionId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getSubscriptionData(): array { + return $this->subscriptionData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getObjectData(): array { + return $this->objectData; + } +} diff --git a/apps/dav/lib/Events/CalendarCreatedEvent.php b/apps/dav/lib/Events/CalendarCreatedEvent.php new file mode 100644 index 0000000000000..7f4aa4ac03ec5 --- /dev/null +++ b/apps/dav/lib/Events/CalendarCreatedEvent.php @@ -0,0 +1,72 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CalendarCreatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CalendarCreatedEvent extends Event { + + /** @var int */ + private $calendarId; + + /** @var array */ + private $calendarData; + + /** + * CalendarCreatedEvent constructor. + * + * @param int $calendarId + * @param array $calendarData + * @since 20.0.0 + */ + public function __construct(int $calendarId, + array $calendarData) { + parent::__construct(); + $this->calendarId = $calendarId; + $this->calendarData = $calendarData; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getCalendarId(): int { + return $this->calendarId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getCalendarData(): array { + return $this->calendarData; + } +} diff --git a/apps/dav/lib/Events/CalendarDeletedEvent.php b/apps/dav/lib/Events/CalendarDeletedEvent.php new file mode 100644 index 0000000000000..f26e1a7fb6ab8 --- /dev/null +++ b/apps/dav/lib/Events/CalendarDeletedEvent.php @@ -0,0 +1,86 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CalendarDeletedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CalendarDeletedEvent extends Event { + + /** @var int */ + private $calendarId; + + /** @var array */ + private $calendarData; + + /** @var array */ + private $shares; + + /** + * CalendarDeletedEvent constructor. + * + * @param int $calendarId + * @param array $calendarData + * @param array $shares + * @since 20.0.0 + */ + public function __construct(int $calendarId, + array $calendarData, + array $shares) { + parent::__construct(); + $this->calendarId = $calendarId; + $this->calendarData = $calendarData; + $this->shares = $shares; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getCalendarId(): int { + return $this->calendarId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getCalendarData(): array { + return $this->calendarData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } +} diff --git a/apps/dav/lib/Events/CalendarObjectCreatedEvent.php b/apps/dav/lib/Events/CalendarObjectCreatedEvent.php new file mode 100644 index 0000000000000..dcd68e4cd0a0a --- /dev/null +++ b/apps/dav/lib/Events/CalendarObjectCreatedEvent.php @@ -0,0 +1,100 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CalendarObjectCreatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CalendarObjectCreatedEvent extends Event { + + /** @var int */ + private $calendarId; + + /** @var array */ + private $calendarData; + + /** @var array */ + private $shares; + + /** @var array */ + private $objectData; + + /** + * CalendarObjectCreatedEvent constructor. + * + * @param int $calendarId + * @param array $calendarData + * @param array $shares + * @param array $objectData + * @since 20.0.0 + */ + public function __construct(int $calendarId, + array $calendarData, + array $shares, + array $objectData) { + parent::__construct(); + $this->calendarId = $calendarId; + $this->calendarData = $calendarData; + $this->shares = $shares; + $this->objectData = $objectData; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getCalendarId(): int { + return $this->calendarId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getCalendarData(): array { + return $this->calendarData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getObjectData(): array { + return $this->objectData; + } +} diff --git a/apps/dav/lib/Events/CalendarObjectDeletedEvent.php b/apps/dav/lib/Events/CalendarObjectDeletedEvent.php new file mode 100644 index 0000000000000..357e9ede11f39 --- /dev/null +++ b/apps/dav/lib/Events/CalendarObjectDeletedEvent.php @@ -0,0 +1,100 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CalendarObjectDeletedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CalendarObjectDeletedEvent extends Event { + + /** @var int */ + private $calendarId; + + /** @var array */ + private $calendarData; + + /** @var array */ + private $shares; + + /** @var array */ + private $objectData; + + /** + * CalendarObjectDeletedEvent constructor. + * + * @param int $calendarId + * @param array $calendarData + * @param array $shares + * @param array $objectData + * @since 20.0.0 + */ + public function __construct(int $calendarId, + array $calendarData, + array $shares, + array $objectData) { + parent::__construct(); + $this->calendarId = $calendarId; + $this->calendarData = $calendarData; + $this->shares = $shares; + $this->objectData = $objectData; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getCalendarId(): int { + return $this->calendarId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getCalendarData(): array { + return $this->calendarData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getObjectData(): array { + return $this->objectData; + } +} diff --git a/apps/dav/lib/Events/CalendarObjectUpdatedEvent.php b/apps/dav/lib/Events/CalendarObjectUpdatedEvent.php new file mode 100644 index 0000000000000..2837800504247 --- /dev/null +++ b/apps/dav/lib/Events/CalendarObjectUpdatedEvent.php @@ -0,0 +1,100 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CalendarObjectUpdatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CalendarObjectUpdatedEvent extends Event { + + /** @var int */ + private $calendarId; + + /** @var array */ + private $calendarData; + + /** @var array */ + private $shares; + + /** @var array */ + private $objectData; + + /** + * CalendarObjectUpdatedEvent constructor. + * + * @param int $calendarId + * @param array $calendarData + * @param array $shares + * @param array $objectData + * @since 20.0.0 + */ + public function __construct(int $calendarId, + array $calendarData, + array $shares, + array $objectData) { + parent::__construct(); + $this->calendarId = $calendarId; + $this->calendarData = $calendarData; + $this->shares = $shares; + $this->objectData = $objectData; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getCalendarId(): int { + return $this->calendarId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getCalendarData(): array { + return $this->calendarData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getObjectData(): array { + return $this->objectData; + } +} diff --git a/apps/dav/lib/Events/CalendarPublishedEvent.php b/apps/dav/lib/Events/CalendarPublishedEvent.php new file mode 100644 index 0000000000000..63a2937d0cf6c --- /dev/null +++ b/apps/dav/lib/Events/CalendarPublishedEvent.php @@ -0,0 +1,86 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CalendarPublishedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CalendarPublishedEvent extends Event { + + /** @var int */ + private $calendarId; + + /** @var array */ + private $calendarData; + + /** @var string */ + private $publicUri; + + /** + * CalendarPublishedEvent constructor. + * + * @param int $calendarId + * @param array $calendarData + * @param string $publicUri + * @since 20.0.0 + */ + public function __construct(int $calendarId, + array $calendarData, + string $publicUri) { + parent::__construct(); + $this->calendarId = $calendarId; + $this->calendarData = $calendarData; + $this->publicUri = $publicUri; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getCalendarId(): int { + return $this->calendarId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getCalendarData(): array { + return $this->calendarData; + } + + /** + * @return string + * @since 20.0.0 + */ + public function getPublicUri(): string { + return $this->publicUri; + } +} diff --git a/apps/dav/lib/Events/CalendarShareUpdatedEvent.php b/apps/dav/lib/Events/CalendarShareUpdatedEvent.php new file mode 100644 index 0000000000000..18b579540f193 --- /dev/null +++ b/apps/dav/lib/Events/CalendarShareUpdatedEvent.php @@ -0,0 +1,114 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CalendarShareUpdatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CalendarShareUpdatedEvent extends Event { + + /** @var int */ + private $calendarId; + + /** @var array */ + private $calendarData; + + /** @var array */ + private $oldShares; + + /** @var array */ + private $added; + + /** @var array */ + private $removed; + + /** + * CalendarShareUpdatedEvent constructor. + * + * @param int $calendarId + * @param array $calendarData + * @param array $oldShares + * @param array $added + * @param array $removed + * @since 20.0.0 + */ + public function __construct(int $calendarId, + array $calendarData, + array $oldShares, + array $added, + array $removed) { + parent::__construct(); + $this->calendarId = $calendarId; + $this->calendarData = $calendarData; + $this->oldShares = $oldShares; + $this->added = $added; + $this->removed = $removed; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getCalendarId(): int { + return $this->calendarId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getCalendarData(): array { + return $this->calendarData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getOldShares(): array { + return $this->oldShares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getAdded(): array { + return $this->added; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getRemoved(): array { + return $this->removed; + } +} diff --git a/apps/dav/lib/Events/CalendarUnpublishedEvent.php b/apps/dav/lib/Events/CalendarUnpublishedEvent.php new file mode 100644 index 0000000000000..dd927d808ac64 --- /dev/null +++ b/apps/dav/lib/Events/CalendarUnpublishedEvent.php @@ -0,0 +1,72 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CalendarPublishedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CalendarUnpublishedEvent extends Event { + + /** @var int */ + private $calendarId; + + /** @var array */ + private $calendarData; + + /** + * CalendarUnpublishedEvent constructor. + * + * @param int $calendarId + * @param array $calendarData + * @since 20.0.0 + */ + public function __construct(int $calendarId, + array $calendarData) { + parent::__construct(); + $this->calendarId = $calendarId; + $this->calendarData = $calendarData; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getCalendarId(): int { + return $this->calendarId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getCalendarData(): array { + return $this->calendarData; + } +} diff --git a/apps/dav/lib/Events/CalendarUpdatedEvent.php b/apps/dav/lib/Events/CalendarUpdatedEvent.php new file mode 100644 index 0000000000000..644a29d97fa86 --- /dev/null +++ b/apps/dav/lib/Events/CalendarUpdatedEvent.php @@ -0,0 +1,100 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CalendarUpdatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CalendarUpdatedEvent extends Event { + + /** @var int */ + private $calendarId; + + /** @var array */ + private $calendarData; + + /** @var array */ + private $shares; + + /** @var array */ + private $mutations; + + /** + * CalendarUpdatedEvent constructor. + * + * @param int $calendarId + * @param array $calendarData + * @param array $shares + * @param array $mutations + * @since 20.0.0 + */ + public function __construct(int $calendarId, + array $calendarData, + array $shares, + array $mutations) { + parent::__construct(); + $this->calendarId = $calendarId; + $this->calendarData = $calendarData; + $this->shares = $shares; + $this->mutations = $mutations; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getCalendarId(): int { + return $this->calendarId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getCalendarData(): array { + return $this->calendarData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getMutations(): array { + return $this->mutations; + } +} diff --git a/apps/dav/lib/Events/CardCreatedEvent.php b/apps/dav/lib/Events/CardCreatedEvent.php new file mode 100644 index 0000000000000..e885a05f91ead --- /dev/null +++ b/apps/dav/lib/Events/CardCreatedEvent.php @@ -0,0 +1,100 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CardCreatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CardCreatedEvent extends Event { + + /** @var int */ + private $addressBookId; + + /** @var array */ + private $addressBookData; + + /** @var array */ + private $shares; + + /** @var array */ + private $cardData; + + /** + * CardCreatedEvent constructor. + * + * @param int $addressBookId + * @param array $addressBookData + * @param array $shares + * @param array $cardData + * @since 20.0.0 + */ + public function __construct(int $addressBookId, + array $addressBookData, + array $shares, + array $cardData) { + parent::__construct(); + $this->addressBookId = $addressBookId; + $this->addressBookData = $addressBookData; + $this->shares = $shares; + $this->cardData = $cardData; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getAddressBookId(): int { + return $this->addressBookId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getAddressBookData(): array { + return $this->addressBookData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getCardData(): array { + return $this->cardData; + } +} diff --git a/apps/dav/lib/Events/CardDeletedEvent.php b/apps/dav/lib/Events/CardDeletedEvent.php new file mode 100644 index 0000000000000..27e8ccf48e67f --- /dev/null +++ b/apps/dav/lib/Events/CardDeletedEvent.php @@ -0,0 +1,100 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CardDeletedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CardDeletedEvent extends Event { + + /** @var int */ + private $addressBookId; + + /** @var array */ + private $addressBookData; + + /** @var array */ + private $shares; + + /** @var array */ + private $cardData; + + /** + * CardDeletedEvent constructor. + * + * @param int $addressBookId + * @param array $addressBookData + * @param array $shares + * @param array $cardData + * @since 20.0.0 + */ + public function __construct(int $addressBookId, + array $addressBookData, + array $shares, + array $cardData) { + parent::__construct(); + $this->addressBookId = $addressBookId; + $this->addressBookData = $addressBookData; + $this->shares = $shares; + $this->cardData = $cardData; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getAddressBookId(): int { + return $this->addressBookId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getAddressBookData(): array { + return $this->addressBookData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getCardData(): array { + return $this->cardData; + } +} diff --git a/apps/dav/lib/Events/CardUpdatedEvent.php b/apps/dav/lib/Events/CardUpdatedEvent.php new file mode 100644 index 0000000000000..ff8b66d4c9fab --- /dev/null +++ b/apps/dav/lib/Events/CardUpdatedEvent.php @@ -0,0 +1,100 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class CardUpdatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class CardUpdatedEvent extends Event { + + /** @var int */ + private $addressBookId; + + /** @var array */ + private $addressBookData; + + /** @var array */ + private $shares; + + /** @var array */ + private $cardData; + + /** + * CardUpdatedEvent constructor. + * + * @param int $addressBookId + * @param array $addressBookData + * @param array $shares + * @param array $cardData + * @since 20.0.0 + */ + public function __construct(int $addressBookId, + array $addressBookData, + array $shares, + array $cardData) { + parent::__construct(); + $this->addressBookId = $addressBookId; + $this->addressBookData = $addressBookData; + $this->shares = $shares; + $this->cardData = $cardData; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getAddressBookId(): int { + return $this->addressBookId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getAddressBookData(): array { + return $this->addressBookData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getCardData(): array { + return $this->cardData; + } +} diff --git a/apps/dav/lib/Events/SubscriptionCreatedEvent.php b/apps/dav/lib/Events/SubscriptionCreatedEvent.php new file mode 100644 index 0000000000000..36cff537a6fa5 --- /dev/null +++ b/apps/dav/lib/Events/SubscriptionCreatedEvent.php @@ -0,0 +1,72 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class SubscriptionCreatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class SubscriptionCreatedEvent extends Event { + + /** @var int */ + private $subscriptionId; + + /** @var array */ + private $subscriptionData; + + /** + * SubscriptionCreatedEvent constructor. + * + * @param int $subscriptionId + * @param array $subscriptionData + * @since 20.0.0 + */ + public function __construct(int $subscriptionId, + array $subscriptionData) { + parent::__construct(); + $this->subscriptionId = $subscriptionId; + $this->subscriptionData = $subscriptionData; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getSubscriptionId(): int { + return $this->subscriptionId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getSubscriptionData(): array { + return $this->subscriptionData; + } +} diff --git a/apps/dav/lib/Events/SubscriptionDeletedEvent.php b/apps/dav/lib/Events/SubscriptionDeletedEvent.php new file mode 100644 index 0000000000000..d21102bf1acef --- /dev/null +++ b/apps/dav/lib/Events/SubscriptionDeletedEvent.php @@ -0,0 +1,86 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class SubscriptionDeletedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class SubscriptionDeletedEvent extends Event { + + /** @var int */ + private $subscriptionId; + + /** @var array */ + private $subscriptionData; + + /** @var array */ + private $shares; + + /** + * SubscriptionDeletedEvent constructor. + * + * @param int $subscriptionId + * @param array $subscriptionData + * @param array $shares + * @since 20.0.0 + */ + public function __construct(int $subscriptionId, + array $subscriptionData, + array $shares) { + parent::__construct(); + $this->subscriptionId = $subscriptionId; + $this->subscriptionData = $subscriptionData; + $this->shares = $shares; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getSubscriptionId(): int { + return $this->subscriptionId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getSubscriptionData(): array { + return $this->subscriptionData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } +} diff --git a/apps/dav/lib/Events/SubscriptionUpdatedEvent.php b/apps/dav/lib/Events/SubscriptionUpdatedEvent.php new file mode 100644 index 0000000000000..ec74ce863a36c --- /dev/null +++ b/apps/dav/lib/Events/SubscriptionUpdatedEvent.php @@ -0,0 +1,100 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Events; + +use OCP\EventDispatcher\Event; + +/** + * Class SubscriptionUpdatedEvent + * + * @package OCA\DAV\Events + * @since 20.0.0 + */ +class SubscriptionUpdatedEvent extends Event { + + /** @var int */ + private $subscriptionId; + + /** @var array */ + private $subscriptionData; + + /** @var array */ + private $shares; + + /** @var array */ + private $mutations; + + /** + * SubscriptionUpdatedEvent constructor. + * + * @param int $subscriptionId + * @param array $subscriptionData + * @param array $shares + * @param array $mutations + * @since 20.0.0 + */ + public function __construct(int $subscriptionId, + array $subscriptionData, + array $shares, + array $mutations) { + parent::__construct(); + $this->subscriptionId = $subscriptionId; + $this->subscriptionData = $subscriptionData; + $this->shares = $shares; + $this->mutations = $mutations; + } + + /** + * @return int + * @since 20.0.0 + */ + public function getSubscriptionId(): int { + return $this->subscriptionId; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getSubscriptionData(): array { + return $this->subscriptionData; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getShares(): array { + return $this->shares; + } + + /** + * @return array + * @since 20.0.0 + */ + public function getMutations(): array { + return $this->mutations; + } +} diff --git a/apps/dav/lib/RootCollection.php b/apps/dav/lib/RootCollection.php index 53cba3eefa033..83f3691959ba7 100644 --- a/apps/dav/lib/RootCollection.php +++ b/apps/dav/lib/RootCollection.php @@ -45,6 +45,7 @@ use OCA\DAV\Upload\CleanupService; use OCP\App\IAppManager; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\EventDispatcher\IEventDispatcher; use Sabre\DAV\SimpleCollection; class RootCollection extends SimpleCollection { @@ -58,7 +59,8 @@ public function __construct() { $groupManager = \OC::$server->getGroupManager(); $shareManager = \OC::$server->getShareManager(); $db = \OC::$server->getDatabaseConnection(); - $dispatcher = \OC::$server->getEventDispatcher(); + $dispatcher = \OC::$server->get(IEventDispatcher::class); + $legacyDispatcher = \OC::$server->getEventDispatcher(); $proxyMapper = \OC::$server->query(ProxyMapper::class); $userPrincipalBackend = new Principal( @@ -91,14 +93,14 @@ public function __construct() { $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); $filesCollection->disableListing = $disableListing; - $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); + $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher, $legacyDispatcher); $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); $userCalendarRoot->disableListing = $disableListing; - $resourceCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); + $resourceCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher, $legacyDispatcher); $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources'); $resourceCalendarRoot->disableListing = $disableListing; - $roomCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); + $roomCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher, $legacyDispatcher); $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $roomCalendarCaldavBackend, 'principals/calendar-rooms'); $roomCalendarRoot->disableListing = $disableListing; @@ -126,11 +128,11 @@ public function __construct() { ); $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class)); - $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); + $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher); $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, 'principals/users'); $usersAddressBookRoot->disableListing = $disableListing; - $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); + $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher); $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, 'principals/system'); $systemAddressBookRoot->disableListing = $disableListing; diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php index c7371761266ca..85efd0fd3699e 100644 --- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php +++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php @@ -31,6 +31,7 @@ use OCA\DAV\CalDAV\Proxy\ProxyMapper; use OCA\DAV\Connector\Sabre\Principal; use OCP\App\IAppManager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IGroupManager; use OCP\ILogger; @@ -63,6 +64,8 @@ abstract class AbstractCalDavBackend extends TestCase { protected $groupManager; /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $dispatcher; + /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ + protected $legacyDispatcher; /** @var ISecureRandom */ private $random; @@ -79,7 +82,8 @@ protected function setUp(): void { $this->userManager = $this->createMock(IUserManager::class); $this->groupManager = $this->createMock(IGroupManager::class); - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->dispatcher = $this->createMock(IEventDispatcher::class); + $this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class); $this->principal = $this->getMockBuilder(Principal::class) ->setConstructorArgs([ $this->userManager, @@ -104,7 +108,7 @@ protected function setUp(): void { $db = \OC::$server->getDatabaseConnection(); $this->random = \OC::$server->getSecureRandom(); $this->logger = $this->createMock(ILogger::class); - $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->groupManager, $this->random, $this->logger, $this->dispatcher); + $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->groupManager, $this->random, $this->logger, $this->dispatcher, $this->legacyDispatcher); $this->cleanUpBackend(); } @@ -128,7 +132,7 @@ public function cleanUpBackend() { private function cleanupForPrincipal($principal): void { $calendars = $this->backend->getCalendarsForUser($principal); foreach ($calendars as $calendar) { - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar'); @@ -141,7 +145,7 @@ private function cleanupForPrincipal($principal): void { } protected function createTestCalendar() { - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendar'); @@ -198,7 +202,7 @@ protected function createEvent($calendarId, $start = '20130912T130000Z', $end = EOD; $uri0 = $this->getUniqueID('event'); - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject'); diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php index ee08719f9bc13..bb6e1b2bad71d 100644 --- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php @@ -57,7 +57,7 @@ public function testCalendarOperations() { '{DAV:}displayname' => 'Unit test', '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar used for unit testing' ]); - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar'); $this->backend->updateCalendar($calendarId, $patch); @@ -70,7 +70,7 @@ public function testCalendarOperations() { $this->assertEquals('User\'s displayname', $calendars[0]['{http://nextcloud.com/ns}owner-displayname']); // delete the address book - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar'); $this->backend->deleteCalendar($calendars[0]['id']); @@ -148,7 +148,7 @@ public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); $this->assertCount(1, $calendars); $calendar = new Calendar($this->backend, $calendars[0], $l10n, $config); - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::updateShares'); $this->backend->updateShares($calendar, $add, []); @@ -181,7 +181,7 @@ public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, END:VCALENDAR EOD; - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject'); $this->backend->createCalendarObject($calendarId, $uri, $calData); @@ -195,7 +195,7 @@ public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, $this->assertAccess($userCanWrite, self::UNIT_TEST_USER1, '{DAV:}write', $acl); // delete the address book - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar'); $this->backend->deleteCalendar($calendars[0]['id']); @@ -225,7 +225,7 @@ public function testCalendarObjectsOperations() { END:VCALENDAR EOD; - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject'); $this->backend->createCalendarObject($calendarId, $uri, $calData); @@ -263,7 +263,7 @@ public function testCalendarObjectsOperations() { END:VEVENT END:VCALENDAR EOD; - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject'); $this->backend->updateCalendarObject($calendarId, $uri, $calData); @@ -271,7 +271,7 @@ public function testCalendarObjectsOperations() { $this->assertEquals($calData, $calendarObject['calendardata']); // delete the card - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject'); $this->backend->deleteCalendarObject($calendarId, $uri); @@ -366,17 +366,17 @@ public function testMultiCalendarObjects() { EOD; $uri0 = static::getUniqueID('card'); - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject'); $this->backend->createCalendarObject($calendarId, $uri0, $calData[0]); $uri1 = static::getUniqueID('card'); - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject'); $this->backend->createCalendarObject($calendarId, $uri1, $calData[1]); $uri2 = static::getUniqueID('card'); - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject'); $this->backend->createCalendarObject($calendarId, $uri2, $calData[2]); @@ -405,15 +405,15 @@ public function testMultiCalendarObjects() { $this->assertEquals($calData[2], $calendarObjects[1]['calendardata']); // delete the card - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject'); $this->backend->deleteCalendarObject($calendarId, $uri0); - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject'); $this->backend->deleteCalendarObject($calendarId, $uri1); - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject'); $this->backend->deleteCalendarObject($calendarId, $uri2); @@ -498,7 +498,7 @@ public function testSyncSupport() { } public function testPublications() { - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendar'); diff --git a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php index 985da38133c6d..5200d201f5058 100644 --- a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php +++ b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php @@ -36,6 +36,7 @@ use OCA\DAV\CalDAV\PublicCalendar; use OCA\DAV\CalDAV\PublicCalendarRoot; use OCA\DAV\Connector\Sabre\Principal; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IGroupManager; use OCP\IL10N; @@ -83,7 +84,8 @@ protected function setUp(): void { $this->groupManager = $this->createMock(IGroupManager::class); $this->random = \OC::$server->getSecureRandom(); $this->logger = $this->createMock(ILogger::class); - $dispatcher = $this->createMock(EventDispatcherInterface::class); + $dispatcher = $this->createMock(IEventDispatcher::class); + $legacyDispatcher = $this->createMock(EventDispatcherInterface::class); $this->principal->expects($this->any())->method('getGroupMembership') ->withAnyParameters() @@ -100,7 +102,8 @@ protected function setUp(): void { $this->groupManager, $this->random, $this->logger, - $dispatcher + $dispatcher, + $legacyDispatcher ); $this->l10n = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor()->getMock(); diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php index 6b90096c57f7d..95617001b3188 100644 --- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php +++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php @@ -39,6 +39,7 @@ use OCA\DAV\Connector\Sabre\Principal; use OCP\App\IAppManager; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroupManager; @@ -76,6 +77,9 @@ class CardDavBackendTest extends TestCase { private $groupManager; /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */ + private $legacyDispatcher; + + /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ private $dispatcher; /** @var IDBConnection */ @@ -147,11 +151,12 @@ protected function setUp(): void { $this->principal->method('getGroupMembership') ->withAnyParameters() ->willReturn([self::UNIT_TEST_GROUP]); - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->dispatcher = $this->createMock(IEventDispatcher::class); + $this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class); $this->db = \OC::$server->getDatabaseConnection(); - $this->backend = new CardDavBackend($this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher); + $this->backend = new CardDavBackend($this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher); // start every test with a empty cards_properties and cards table $query = $this->db->getQueryBuilder(); $query->delete('cards_properties')->execute(); @@ -241,7 +246,7 @@ public function testCardOperations() { /** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $backend */ $backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher]) ->setMethods(['updateProperties', 'purgeProperties'])->getMock(); // create a new address book @@ -256,7 +261,7 @@ public function testCardOperations() { $backend->expects($this->at(1))->method('updateProperties')->with($bookId, $uri, $this->vcardTest1); // Expect event - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CardDAV\CardDavBackend::createCard', $this->callback(function (GenericEvent $e) use ($bookId, $uri) { return $e->getArgument('addressBookId') === $bookId && @@ -283,7 +288,7 @@ public function testCardOperations() { $this->assertEquals($this->vcardTest0, $card['carddata']); // Expect event - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $this->callback(function (GenericEvent $e) use ($bookId, $uri) { return $e->getArgument('addressBookId') === $bookId && @@ -297,7 +302,7 @@ public function testCardOperations() { $this->assertEquals($this->vcardTest1, $card['carddata']); // Expect event - $this->dispatcher->expects($this->at(0)) + $this->legacyDispatcher->expects($this->at(0)) ->method('dispatch') ->with('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $this->callback(function (GenericEvent $e) use ($bookId, $uri) { return $e->getArgument('addressBookId') === $bookId && @@ -313,7 +318,7 @@ public function testCardOperations() { public function testMultiCard() { $this->backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher]) ->setMethods(['updateProperties'])->getMock(); // create a new address book @@ -366,7 +371,7 @@ public function testMultiCard() { public function testMultipleUIDOnDifferentAddressbooks() { $this->backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher]) ->setMethods(['updateProperties'])->getMock(); // create 2 new address books @@ -388,7 +393,7 @@ public function testMultipleUIDOnDifferentAddressbooks() { public function testMultipleUIDDenied() { $this->backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher]) ->setMethods(['updateProperties'])->getMock(); // create a new address book @@ -409,7 +414,7 @@ public function testMultipleUIDDenied() { public function testNoValidUID() { $this->backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher]) ->setMethods(['updateProperties'])->getMock(); // create a new address book @@ -426,7 +431,7 @@ public function testNoValidUID() { public function testDeleteWithoutCard() { $this->backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher]) ->setMethods([ 'getCardId', 'addChange', @@ -466,7 +471,7 @@ public function testDeleteWithoutCard() { public function testSyncSupport() { $this->backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher]) ->setMethods(['updateProperties'])->getMock(); // create a new address book @@ -532,7 +537,7 @@ public function testUpdateProperties() { $cardId = 2; $backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher, $this->legacyDispatcher]) ->setMethods(['getCardId'])->getMock(); $backend->expects($this->any())->method('getCardId')->willReturn($cardId);