@@ -213,7 +213,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
213213 protected array $ userDisplayNames ;
214214
215215 private Backend $ calendarSharingBackend ;
216+ private string $ dbObjectsTable = 'calendarobjects ' ;
216217 private string $ dbObjectPropertiesTable = 'calendarobjects_props ' ;
218+ private string $ dbObjectInvitationsTable = 'calendar_invitations ' ;
217219 private array $ cachedObjects = [];
218220
219221 public function __construct (
@@ -901,6 +903,8 @@ public function deleteCalendar($calendarId, bool $forceDeletePermanently = false
901903 $ calendarData = $ this ->getCalendarById ($ calendarId );
902904 $ shares = $ this ->getShares ($ calendarId );
903905
906+ $ this ->purgeCalendarInvitations ($ calendarId );
907+
904908 $ qbDeleteCalendarObjectProps = $ this ->db ->getQueryBuilder ();
905909 $ qbDeleteCalendarObjectProps ->delete ($ this ->dbObjectPropertiesTable )
906910 ->where ($ qbDeleteCalendarObjectProps ->expr ()->eq ('calendarid ' , $ qbDeleteCalendarObjectProps ->createNamedParameter ($ calendarId )))
@@ -1131,7 +1135,7 @@ public function getCalendarObject($calendarId, $objectUri, int $calendarType = s
11311135 return $ this ->cachedObjects [$ key ];
11321136 }
11331137 $ query = $ this ->db ->getQueryBuilder ();
1134- $ query ->select (['id ' , 'uri ' , 'lastmodified ' , 'etag ' , 'calendarid ' , 'size ' , 'calendardata ' , 'componenttype ' , 'classification ' , 'deleted_at ' ])
1138+ $ query ->select (['id ' , 'uri ' , 'uid ' , ' lastmodified ' , 'etag ' , 'calendarid ' , 'size ' , 'calendardata ' , 'componenttype ' , 'classification ' , 'deleted_at ' ])
11351139 ->from ('calendarobjects ' )
11361140 ->where ($ query ->expr ()->eq ('calendarid ' , $ query ->createNamedParameter ($ calendarId )))
11371141 ->andWhere ($ query ->expr ()->eq ('uri ' , $ query ->createNamedParameter ($ objectUri )))
@@ -1153,6 +1157,7 @@ private function rowToCalendarObject(array $row): array {
11531157 return [
11541158 'id ' => $ row ['id ' ],
11551159 'uri ' => $ row ['uri ' ],
1160+ 'uid ' => $ row ['uid ' ],
11561161 'lastmodified ' => $ row ['lastmodified ' ],
11571162 'etag ' => '" ' . $ row ['etag ' ] . '" ' ,
11581163 'calendarid ' => $ row ['calendarid ' ],
@@ -1473,6 +1478,8 @@ public function deleteCalendarObject($calendarId, $objectUri, $calendarType = se
14731478
14741479 $ this ->purgeProperties ($ calendarId , $ data ['id ' ]);
14751480
1481+ $ this ->purgeObjectInvitations ($ data ['uid ' ]);
1482+
14761483 if ($ calendarType === self ::CALENDAR_TYPE_CALENDAR ) {
14771484 $ calendarRow = $ this ->getCalendarById ($ calendarId );
14781485 $ shares = $ this ->getShares ($ calendarId );
@@ -1669,7 +1676,7 @@ public function calendarQuery($calendarId, array $filters, $calendarType = self:
16691676 }
16701677 }
16711678 $ query = $ this ->db ->getQueryBuilder ();
1672- $ query ->select (['id ' , 'uri ' , 'lastmodified ' , 'etag ' , 'calendarid ' , 'size ' , 'calendardata ' , 'componenttype ' , 'classification ' , 'deleted_at ' ])
1679+ $ query ->select (['id ' , 'uri ' , 'uid ' , ' lastmodified ' , 'etag ' , 'calendarid ' , 'size ' , 'calendardata ' , 'componenttype ' , 'classification ' , 'deleted_at ' ])
16731680 ->from ('calendarobjects ' )
16741681 ->where ($ query ->expr ()->eq ('calendarid ' , $ query ->createNamedParameter ($ calendarId )))
16751682 ->andWhere ($ query ->expr ()->eq ('calendartype ' , $ query ->createNamedParameter ($ calendarType )))
@@ -3502,4 +3509,46 @@ private function rowToSubscription($row, array $subscription): array {
35023509 }
35033510 return $ subscription ;
35043511 }
3512+
3513+ /**
3514+ * delete all invitations from a given calendar
3515+ *
3516+ * @since 31.0.0
3517+ *
3518+ * @param int $calendarId
3519+ *
3520+ * @return void
3521+ */
3522+ protected function purgeCalendarInvitations (int $ calendarId ): void {
3523+ // select all calendar object uid's
3524+ $ cmd = $ this ->db ->getQueryBuilder ();
3525+ $ cmd ->select ('uid ' )
3526+ ->from ($ this ->dbObjectsTable )
3527+ ->where ($ cmd ->expr ()->eq ('calendarid ' , $ cmd ->createNamedParameter ($ calendarId )));
3528+ $ allIds = $ cmd ->executeQuery ()->fetchAll (\PDO ::FETCH_COLUMN );
3529+ // delete all links that match object uid's
3530+ $ cmd = $ this ->db ->getQueryBuilder ();
3531+ $ cmd ->delete ($ this ->dbObjectInvitationsTable )
3532+ ->where ($ cmd ->expr ()->in ('uid ' , $ cmd ->createNamedParameter ('uids ' ), IQueryBuilder::PARAM_STR_ARRAY ));
3533+ foreach (array_chunk ($ allIds , 1000 ) as $ chunckIds ) {
3534+ $ cmd ->setParameter ('uids ' , $ chunckIds , IQueryBuilder::PARAM_INT_ARRAY );
3535+ $ cmd ->executeStatement ();
3536+ }
3537+ }
3538+
3539+ /**
3540+ * Delete all invitations from a given calendar event
3541+ *
3542+ * @since 31.0.0
3543+ *
3544+ * @param string $eventId UID of the event
3545+ *
3546+ * @return void
3547+ */
3548+ protected function purgeObjectInvitations (string $ eventId ): void {
3549+ $ cmd = $ this ->db ->getQueryBuilder ();
3550+ $ cmd ->delete ($ this ->dbObjectInvitationsTable )
3551+ ->where ($ cmd ->expr ()->eq ('uid ' , $ cmd ->createNamedParameter ($ eventId )));
3552+ $ cmd ->executeStatement ();
3553+ }
35053554}
0 commit comments