aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CardDAV
diff options
context:
space:
mode:
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();
}