Merge pull request #16994 from nextcloud/backport/16835/stable16

[stable16] Remove orphaned calendar data from deleted subscriptions
This commit is contained in:
Roeland Jago Douma 2019-09-19 10:26:17 +02:00 committed by GitHub
commit 4e8aae50a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -55,6 +55,11 @@ class RemoveOrphanEventsAndContacts implements IRepairStep {
$orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendars', 'calendarid');
$output->info(sprintf('%d changes without a calendar have been cleaned up', $orphanItems));
$orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendarsubscriptions', 'calendarid');
$output->info(sprintf('%d cached events without a calendar subscription have been cleaned up', $orphanItems));
$orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendarsubscriptions', 'calendarid');
$output->info(sprintf('%d changes without a calendar subscription have been cleaned up', $orphanItems));
$orphanItems = $this->removeOrphanChildren('cards', 'addressbooks', 'addressbookid');
$output->info(sprintf('%d contacts without an addressbook have been cleaned up', $orphanItems));
$orphanItems = $this->removeOrphanChildren('cards_properties', 'cards', 'cardid');
@ -70,6 +75,12 @@ class RemoveOrphanEventsAndContacts implements IRepairStep {
->from($childTable, 'c')
->leftJoin('c', $parentTable, 'p', $qb->expr()->eq('c.' . $parentId, 'p.id'))
->where($qb->expr()->isNull('p.id'));
if (\in_array($parentTable, ['calendars', 'calendarsubscriptions'], true)) {
$calendarType = $parentTable === 'calendarsubscriptions' ? CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION : CalDavBackend::CALENDAR_TYPE_CALENDAR;
$qb->andWhere($qb->expr()->eq('c.calendartype', $qb->createNamedParameter($calendarType, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT));
}
$result = $qb->execute();
$orphanItems = array();