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 2023-06-04 23:51:11 +07:00 committed by Christof Arnosti
parent 5ad24991d7
commit 73fb2997f4
2 changed files with 22 additions and 4 deletions

@ -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();
}