diff options
author | Christof Arnosti <charno@charno.ch> | 2023-06-04 23:51:11 +0200 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2023-06-21 08:12:52 +0200 |
commit | 8457a227e3b74ab2c7c6740cba7adbcb3e9c5369 (patch) | |
tree | 2618b6e2e5016c426e056466d8eb4a7e1b1f5e63 /apps | |
parent | c7a2ff2baa8d7cfd9f99cdfc9ff45a11d66a8720 (diff) | |
download | nextcloud-server-8457a227e3b74ab2c7c6740cba7adbcb3e9c5369.tar.gz nextcloud-server-8457a227e3b74ab2c7c6740cba7adbcb3e9c5369.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>
Diffstat (limited to 'apps')
-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 1cdb705ac92..94fe9acf356 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.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(); } diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index 4e4d64f6f72..1be1ce3f18f 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -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(); } |