summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CardDAV
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2023-07-12 19:50:40 +0200
committerGitHub <noreply@github.com>2023-07-12 19:50:40 +0200
commit592aeec17e766e41ce94846675530e23ebe8cc96 (patch)
tree1128f6e095c44fc21015ef5571cac2e713bac6ca /apps/dav/lib/CardDAV
parente9b582164e008a2648bd2e99078145d3e3b114c5 (diff)
parentf2e90444940d71f075214dcca8c0e69066dce7f4 (diff)
downloadnextcloud-server-592aeec17e766e41ce94846675530e23ebe8cc96.tar.gz
nextcloud-server-592aeec17e766e41ce94846675530e23ebe8cc96.zip
Merge pull request #38919 from nextcloud/backport/38639/stable27
[stable27] pruneOutdatedSyncTokens deletes all entries
Diffstat (limited to 'apps/dav/lib/CardDAV')
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php15
1 files changed, 13 insertions, 2 deletions
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php
index 4e4d64f6f72..045ad4d1385 100644
--- a/apps/dav/lib/CardDAV/CardDavBackend.php
+++ b/apps/dav/lib/CardDAV/CardDavBackend.php
@@ -1399,10 +1399,21 @@ class CardDavBackend implements BackendInterface, SyncSupport {
if ($keep < 0) {
throw new \InvalidArgumentException();
}
+
+ $query = $this->db->getQueryBuilder();
+ $query->select($query->func()->max('id'))
+ ->from('addressbookchanges');
+
+ $result = $query->executeQuery();
+ $maxId = (int) $result->fetchOne();
+ $result->closeCursor();
+ 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();
}