diff options
author | Christof Arnosti <charno@charno.ch> | 2023-06-04 23:51:11 +0200 |
---|---|---|
committer | Richard Steinmetz <richard@steinmetz.cloud> | 2023-07-04 10:34:39 +0200 |
commit | 46ceb0d5c18abc696369329b5e0b327884795010 (patch) | |
tree | 7881d3e480fbe9a8ba51d92c97491216fe66241c | |
parent | e36c9d606278968f53f26c11f21deda4fd5512af (diff) | |
download | nextcloud-server-46ceb0d5c18abc696369329b5e0b327884795010.tar.gz nextcloud-server-46ceb0d5c18abc696369329b5e0b327884795010.zip |
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>
-rw-r--r-- | apps/dav/lib/CalDAV/CalDavBackend.php | 13 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/CardDavBackend.php | 13 |
2 files changed, 22 insertions, 4 deletions
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 00dd60ed17c..d11453afd62 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -3092,10 +3092,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(); } diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index ab21af1ce10..b6a24652016 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -1323,10 +1323,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(); } |