From 692d0e92cea817e362290e8ac1b2e2fb1f52a622 Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Wed, 16 Oct 2024 18:56:06 -0400 Subject: [PATCH] fixup! fix: (CalDav) Delete invitation when deleting Calendars or Events Signed-off-by: SebastianKrupinski --- apps/dav/lib/CalDAV/CalDavBackend.php | 30 ++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index b4d147cd29617..36c36eef5e3a7 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -9,7 +9,6 @@ use DateTime; use DateTimeImmutable; use DateTimeInterface; -use OC\DB\QueryBuilder\Literal; use OCA\DAV\AppInfo\Application; use OCA\DAV\CalDAV\Sharing\Backend; use OCA\DAV\Connector\Sabre\Principal; @@ -3560,17 +3559,20 @@ private function rowToSubscription($row, array $subscription): array { */ protected function purgeCalendarInvitations(int $calendarId) { // select all calendar object uid's - $cmd1 = $this->db->getQueryBuilder(); - $cmd1->select('uid') + $cmd = $this->db->getQueryBuilder(); + $cmd->select('uid') ->from($this->dbObjectsTable) - ->where('calendarid = :cid'); + ->where($cmd->expr()->eq('calendarid', $cmd->createNamedParameter($calendarId))); + // execute command + $allIds = $cmd->executeQuery()->fetchAll(\PDO::FETCH_COLUMN); + $allIds = array_chunk($allIds, 1000); // delete all links that match object uid's - $cmd2 = $this->db->getQueryBuilder(); - $cmd2->delete($this->dbObjectInvitationsTable) - ->where($cmd2->expr()->in('uid', new Literal($cmd1->getSQL()))) - ->setParameter('cid', $calendarId); - - $cmd2->executeStatement(); + foreach ($allIds as $chunckIds) { + $cmd = $this->db->getQueryBuilder(); + $cmd->delete($this->dbObjectInvitationsTable) + ->where($cmd->expr()->in('uid', $cmd->createNamedParameter($chunckIds, IQueryBuilder::PARAM_STR_ARRAY), IQueryBuilder::PARAM_STR_ARRAY)); + $cmd->executeStatement(); + } } /** @@ -3581,9 +3583,9 @@ protected function purgeCalendarInvitations(int $calendarId) { * @param string $eventId UID of the event */ protected function purgeObjectInvitations(string $eventId) { - $query = $this->db->getQueryBuilder(); - $query->delete($this->dbObjectInvitationsTable) - ->where($query->expr()->eq('uid', $query->createNamedParameter($eventId))); - $query->executeStatement(); + $cmd = $this->db->getQueryBuilder(); + $cmd->delete($this->dbObjectInvitationsTable) + ->where($cmd->expr()->eq('uid', $cmd->createNamedParameter($eventId))); + $cmd->executeStatement(); } }