Issue #36644: Fix pruneOutdatedSyncTokens for CalDAV

pruneOutdatedSyncTokens accidentally deletes all entries of the calendarchanges table
instead of leaving $limit elements in the table

Signed-off-by: Christof Arnosti <charno@charno.ch>
pull/38639/head
Christof Arnosti 2 years ago committed by Christof Arnosti
parent 5ad24991d7
commit 73fb2997f4
  1. 13
      apps/dav/lib/CalDAV/CalDavBackend.php
  2. 13
      apps/dav/lib/CardDAV/CardDavBackend.php

@ -3134,10 +3134,19 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
if ($keep < 0) {
throw new \InvalidArgumentException();
}
$query = $this->db->getQueryBuilder();
$query->select($query->func()->max('id'))
->from('calendarchanges');
$maxId = $query->executeQuery()->fetchOne();
if (!$maxId || $maxId < $keep) {
return 0;
}
$query = $this->db->getQueryBuilder();
$query->delete('calendarchanges')
->orderBy('id', 'DESC')
->setFirstResult($keep);
->where($query->expr()->lte('id', $query->createNamedParameter($maxId - $keep, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT));
return $query->executeStatement();
}

@ -1399,10 +1399,19 @@ class CardDavBackend implements BackendInterface, SyncSupport {
if ($keep < 0) {
throw new \InvalidArgumentException();
}
$query = $this->db->getQueryBuilder();
$query->select($query->func()->max('id'))
->from('addressbookchanges');
$maxId = $query->executeQuery()->fetchOne();
if (!$maxId || $maxId < $keep) {
return 0;
}
$query = $this->db->getQueryBuilder();
$query->delete('addressbookchanges')
->orderBy('id', 'DESC')
->setFirstResult($keep);
->where($query->expr()->lte('id', $query->createNamedParameter($maxId - $keep, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT));
return $query->executeStatement();
}

Loading…
Cancel
Save