@@ -178,7 +178,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
178178 */
179179 protected array $ userDisplayNames ;
180180
181+ private string $ dbObjectsTable = 'calendarobjects ' ;
181182 private string $ dbObjectPropertiesTable = 'calendarobjects_props ' ;
183+ private string $ dbObjectInvitationsTable = 'calendar_invitations ' ;
182184 private array $ cachedObjects = [];
183185
184186 public function __construct (
@@ -876,6 +878,8 @@ public function deleteCalendar($calendarId, bool $forceDeletePermanently = false
876878 $ calendarData = $ this ->getCalendarById ($ calendarId );
877879 $ shares = $ this ->getShares ($ calendarId );
878880
881+ $ this ->purgeCalendarInvitations ($ calendarId );
882+
879883 $ qbDeleteCalendarObjectProps = $ this ->db ->getQueryBuilder ();
880884 $ qbDeleteCalendarObjectProps ->delete ($ this ->dbObjectPropertiesTable )
881885 ->where ($ qbDeleteCalendarObjectProps ->expr ()->eq ('calendarid ' , $ qbDeleteCalendarObjectProps ->createNamedParameter ($ calendarId )))
@@ -1143,7 +1147,7 @@ public function getCalendarObject($calendarId, $objectUri, int $calendarType = s
11431147 return $ this ->cachedObjects [$ key ];
11441148 }
11451149 $ query = $ this ->db ->getQueryBuilder ();
1146- $ query ->select (['id ' , 'uri ' , 'lastmodified ' , 'etag ' , 'calendarid ' , 'size ' , 'calendardata ' , 'componenttype ' , 'classification ' , 'deleted_at ' ])
1150+ $ query ->select (['id ' , 'uri ' , 'uid ' , ' lastmodified ' , 'etag ' , 'calendarid ' , 'size ' , 'calendardata ' , 'componenttype ' , 'classification ' , 'deleted_at ' ])
11471151 ->from ('calendarobjects ' )
11481152 ->where ($ query ->expr ()->eq ('calendarid ' , $ query ->createNamedParameter ($ calendarId )))
11491153 ->andWhere ($ query ->expr ()->eq ('uri ' , $ query ->createNamedParameter ($ objectUri )))
@@ -1165,6 +1169,7 @@ private function rowToCalendarObject(array $row): array {
11651169 return [
11661170 'id ' => $ row ['id ' ],
11671171 'uri ' => $ row ['uri ' ],
1172+ 'uid ' => $ row ['uid ' ],
11681173 'lastmodified ' => $ row ['lastmodified ' ],
11691174 'etag ' => '" ' . $ row ['etag ' ] . '" ' ,
11701175 'calendarid ' => $ row ['calendarid ' ],
@@ -1485,6 +1490,8 @@ public function deleteCalendarObject($calendarId, $objectUri, $calendarType = se
14851490
14861491 $ this ->purgeProperties ($ calendarId , $ data ['id ' ]);
14871492
1493+ $ this ->purgeObjectInvitations ($ data ['uid ' ]);
1494+
14881495 if ($ calendarType === self ::CALENDAR_TYPE_CALENDAR ) {
14891496 $ calendarRow = $ this ->getCalendarById ($ calendarId );
14901497 $ shares = $ this ->getShares ($ calendarId );
@@ -1681,7 +1688,7 @@ public function calendarQuery($calendarId, array $filters, $calendarType = self:
16811688 }
16821689 }
16831690 $ query = $ this ->db ->getQueryBuilder ();
1684- $ query ->select (['id ' , 'uri ' , 'lastmodified ' , 'etag ' , 'calendarid ' , 'size ' , 'calendardata ' , 'componenttype ' , 'classification ' , 'deleted_at ' ])
1691+ $ query ->select (['id ' , 'uri ' , 'uid ' , ' lastmodified ' , 'etag ' , 'calendarid ' , 'size ' , 'calendardata ' , 'componenttype ' , 'classification ' , 'deleted_at ' ])
16851692 ->from ('calendarobjects ' )
16861693 ->where ($ query ->expr ()->eq ('calendarid ' , $ query ->createNamedParameter ($ calendarId )))
16871694 ->andWhere ($ query ->expr ()->eq ('calendartype ' , $ query ->createNamedParameter ($ calendarType )))
@@ -3542,4 +3549,46 @@ private function rowToSubscription($row, array $subscription): array {
35423549 }
35433550 return $ subscription ;
35443551 }
3552+
3553+ /**
3554+ * delete all invitations from a given calendar
3555+ *
3556+ * @since 31.0.0
3557+ *
3558+ * @param int $calendarId
3559+ *
3560+ * @return void
3561+ */
3562+ protected function purgeCalendarInvitations (int $ calendarId ): void {
3563+ // select all calendar object uid's
3564+ $ cmd = $ this ->db ->getQueryBuilder ();
3565+ $ cmd ->select ('uid ' )
3566+ ->from ($ this ->dbObjectsTable )
3567+ ->where ($ cmd ->expr ()->eq ('calendarid ' , $ cmd ->createNamedParameter ($ calendarId )));
3568+ $ allIds = $ cmd ->executeQuery ()->fetchAll (\PDO ::FETCH_COLUMN );
3569+ // delete all links that match object uid's
3570+ $ cmd = $ this ->db ->getQueryBuilder ();
3571+ $ cmd ->delete ($ this ->dbObjectInvitationsTable )
3572+ ->where ($ cmd ->expr ()->in ('uid ' , $ cmd ->createNamedParameter ('uids ' ), IQueryBuilder::PARAM_STR_ARRAY ));
3573+ foreach (array_chunk ($ allIds , 1000 ) as $ chunckIds ) {
3574+ $ cmd ->setParameter ('uids ' , $ chunckIds , IQueryBuilder::PARAM_INT_ARRAY );
3575+ $ cmd ->executeStatement ();
3576+ }
3577+ }
3578+
3579+ /**
3580+ * Delete all invitations from a given calendar event
3581+ *
3582+ * @since 31.0.0
3583+ *
3584+ * @param string $eventId UID of the event
3585+ *
3586+ * @return void
3587+ */
3588+ protected function purgeObjectInvitations (string $ eventId ): void {
3589+ $ cmd = $ this ->db ->getQueryBuilder ();
3590+ $ cmd ->delete ($ this ->dbObjectInvitationsTable )
3591+ ->where ($ cmd ->expr ()->eq ('uid ' , $ cmd ->createNamedParameter ($ eventId )));
3592+ $ cmd ->executeStatement ();
3593+ }
35453594}
0 commit comments