aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CalDAV
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/CalDAV')
-rw-r--r--apps/dav/lib/CalDAV/CalDavBackend.php170
1 files changed, 123 insertions, 47 deletions
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php
index 159f5c71673..f369fa40b8e 100644
--- a/apps/dav/lib/CalDAV/CalDavBackend.php
+++ b/apps/dav/lib/CalDAV/CalDavBackend.php
@@ -39,7 +39,23 @@ use DateTime;
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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$this->random = $random;
$this->logger = $logger;
$this->dispatcher = $dispatcher;
+ $this->legacyDispatcher = $legacyDispatcher;
$this->legacyEndpoint = $legacyEndpoint;
}
@@ -764,11 +786,13 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
* @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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
->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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
->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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
->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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId)))
->execute();
- $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateSubscription', new GenericEvent(
+ $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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
* @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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
->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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
*/
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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
*/
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 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
'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;
}