aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CardDAV
diff options
context:
space:
mode:
authorChristof Arnosti <charno@charno.ch>2023-06-04 23:51:11 +0200
committerChristof Arnosti <charno@users.noreply.github.com>2023-06-12 08:35:35 +0000
commit73fb2997f4b4e4855ef457aae8fde9cda0839e22 (patch)
tree0436b08a98c2aa0be5edc1958432f22dca409261 /apps/dav/lib/CardDAV
parent5ad24991d7cc33b979e121f109583e186a9640d5 (diff)
downloadnextcloud-server-73fb2997f4b4e4855ef457aae8fde9cda0839e22.tar.gz
nextcloud-server-73fb2997f4b4e4855ef457aae8fde9cda0839e22.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/dav/lib/CardDAV')
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php13
1 files changed, 11 insertions, 2 deletions
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();
}