-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[stable29] fix: (CalDav) Delete invitation link when deleting Calendars or Events #49428
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,7 +211,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription | |
*/ | ||
protected array $userDisplayNames; | ||
|
||
private string $dbObjectsTable = 'calendarobjects'; | ||
private string $dbObjectPropertiesTable = 'calendarobjects_props'; | ||
private string $dbObjectInvitationsTable = 'calendar_invitations'; | ||
private array $cachedObjects = []; | ||
|
||
public function __construct( | ||
|
@@ -909,6 +911,8 @@ public function deleteCalendar($calendarId, bool $forceDeletePermanently = false | |
$calendarData = $this->getCalendarById($calendarId); | ||
$shares = $this->getShares($calendarId); | ||
|
||
$this->purgeCalendarInvitations($calendarId); | ||
|
||
$qbDeleteCalendarObjectProps = $this->db->getQueryBuilder(); | ||
$qbDeleteCalendarObjectProps->delete($this->dbObjectPropertiesTable) | ||
->where($qbDeleteCalendarObjectProps->expr()->eq('calendarid', $qbDeleteCalendarObjectProps->createNamedParameter($calendarId))) | ||
|
@@ -1139,7 +1143,7 @@ public function getCalendarObject($calendarId, $objectUri, int $calendarType = s | |
return $this->cachedObjects[$key]; | ||
} | ||
$query = $this->db->getQueryBuilder(); | ||
$query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification', 'deleted_at']) | ||
$query->select(['id', 'uri', 'uid', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification', 'deleted_at']) | ||
->from('calendarobjects') | ||
->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) | ||
->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) | ||
|
@@ -1161,6 +1165,7 @@ private function rowToCalendarObject(array $row): array { | |
return [ | ||
'id' => $row['id'], | ||
'uri' => $row['uri'], | ||
'uid' => $row['uid'], | ||
'lastmodified' => $row['lastmodified'], | ||
'etag' => '"' . $row['etag'] . '"', | ||
'calendarid' => $row['calendarid'], | ||
|
@@ -1481,6 +1486,8 @@ public function deleteCalendarObject($calendarId, $objectUri, $calendarType = se | |
|
||
$this->purgeProperties($calendarId, $data['id']); | ||
|
||
$this->purgeObjectInvitations($data['uid']); | ||
|
||
if ($calendarType === self::CALENDAR_TYPE_CALENDAR) { | ||
$calendarRow = $this->getCalendarById($calendarId); | ||
$shares = $this->getShares($calendarId); | ||
|
@@ -1677,7 +1684,7 @@ public function calendarQuery($calendarId, array $filters, $calendarType = self: | |
} | ||
} | ||
$query = $this->db->getQueryBuilder(); | ||
$query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification', 'deleted_at']) | ||
$query->select(['id', 'uri', 'uid', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification', 'deleted_at']) | ||
->from('calendarobjects') | ||
->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) | ||
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType))) | ||
|
@@ -3512,4 +3519,46 @@ private function rowToSubscription($row, array $subscription): array { | |
} | ||
return $subscription; | ||
} | ||
|
||
/** | ||
* delete all invitations from a given calendar | ||
* | ||
* @since 31.0.0 | ||
* | ||
* @param int $calendarId | ||
* | ||
* @return void | ||
*/ | ||
protected function purgeCalendarInvitations(int $calendarId): void { | ||
// select all calendar object uid's | ||
$cmd = $this->db->getQueryBuilder(); | ||
$cmd->select('uid') | ||
->from($this->dbObjectsTable) | ||
->where($cmd->expr()->eq('calendarid', $cmd->createNamedParameter($calendarId))); | ||
$allIds = $cmd->executeQuery()->fetchAll(\PDO::FETCH_COLUMN); | ||
// delete all links that match object uid's | ||
$cmd = $this->db->getQueryBuilder(); | ||
$cmd->delete($this->dbObjectInvitationsTable) | ||
->where($cmd->expr()->in('uid', $cmd->createNamedParameter('uids'), IQueryBuilder::PARAM_STR_ARRAY)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #49454 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, I step through tested this, it executes without any errors, but does not actual do what its supposed to do. |
||
foreach (array_chunk($allIds, 1000) as $chunckIds) { | ||
$cmd->setParameter('uids', $chunckIds, IQueryBuilder::PARAM_INT_ARRAY); | ||
$cmd->executeStatement(); | ||
} | ||
} | ||
|
||
/** | ||
* Delete all invitations from a given calendar event | ||
* | ||
* @since 31.0.0 | ||
* | ||
* @param string $eventId UID of the event | ||
* | ||
* @return void | ||
*/ | ||
protected function purgeObjectInvitations(string $eventId): void { | ||
$cmd = $this->db->getQueryBuilder(); | ||
$cmd->delete($this->dbObjectInvitationsTable) | ||
->where($cmd->expr()->eq('uid', $cmd->createNamedParameter($eventId))); | ||
$cmd->executeStatement(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought one had to use
\OCP\DB\QueryBuilder\IQueryBuilder::createParameter
for a parameter, andcreateNamedParameter
was to set a value directly.Fine by me if the current code works