Skip to content

Commit

Permalink
Issue #36644: Fix pruneOutdatedSyncTokens for CalDAV
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
charno authored and st3iny committed Jul 4, 2023
1 parent e36c9d6 commit 46ceb0d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -3092,10 +3092,19 @@ public function pruneOutdatedSyncTokens(int $keep = 10_000): int {
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();
}

Expand Down
13 changes: 11 additions & 2 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1323,10 +1323,19 @@ public function pruneOutdatedSyncTokens(int $keep = 10_000): int {
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();
}

Expand Down

0 comments on commit 46ceb0d

Please sign in to comment.