diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2021-02-15 22:13:03 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2021-02-17 09:06:00 +0100 |
commit | ff1c5c4e25871894103dd8d93005ba4c8b03c513 (patch) | |
tree | e3634a544978591978e3b8c5bc7bc6bb27d5c31d /apps | |
parent | 644e6df02ee6fba6e396d88c89ad5d4c8b7483e0 (diff) | |
download | nextcloud-server-ff1c5c4e25871894103dd8d93005ba4c8b03c513.tar.gz nextcloud-server-ff1c5c4e25871894103dd8d93005ba4c8b03c513.zip |
Move getChangesForAddressBook to QueryBuilder
Makes psalm happy, and makes me happy.
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/lib/CardDAV/CardDavBackend.php | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index d5c36096956..a26c6c24a8e 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -857,14 +857,20 @@ class CardDavBackend implements BackendInterface, SyncSupport { * @param string $addressBookId * @param string $syncToken * @param int $syncLevel - * @param int $limit + * @param int|null $limit * @return array */ public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) { // Current synctoken - $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*addressbooks` WHERE `id` = ?'); - $stmt->execute([$addressBookId]); + $qb = $this->db->getQueryBuilder(); + $qb->select('synctoken') + ->from('addressbooks') + ->where( + $qb->expr()->eq('id', $qb->createNamedParameter($addressBookId)) + ); + $stmt = $qb->execute(); $currentToken = $stmt->fetchOne(); + $stmt->closeCursor(); if (is_null($currentToken)) { return null; @@ -878,14 +884,23 @@ class CardDavBackend implements BackendInterface, SyncSupport { ]; if ($syncToken) { - $query = "SELECT `uri`, `operation` FROM `*PREFIX*addressbookchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `addressbookid` = ? ORDER BY `synctoken`"; - if ($limit > 0) { - $query .= " LIMIT " . (int)$limit; + $qb = $this->db->getQueryBuilder(); + $qb->select('uri', 'operation') + ->from('addressbookchanges') + ->where( + $qb->expr()->andX( + $qb->expr()->gte('synctoken', $qb->createNamedParameter($syncToken)), + $qb->expr()->lt('synctoken', $qb->createNamedParameter($currentToken)), + $qb->expr()->eq('addressbookid', $qb->createNamedParameter($addressBookId)) + ) + )->orderBy('synctoken'); + + if (is_int($limit) && $limit > 0) { + $qb->setMaxResults($limit); } // Fetching all changes - $stmt = $this->db->prepare($query); - $stmt->execute([$syncToken, $currentToken, $addressBookId]); + $stmt = $qb->execute(); $changes = []; @@ -894,6 +909,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $changes[$row['uri']] = $row['operation']; } + $stmt->closeCursor(); foreach ($changes as $uri => $operation) { switch ($operation) { @@ -909,12 +925,16 @@ class CardDavBackend implements BackendInterface, SyncSupport { } } } else { + $qb = $this->db->getQueryBuilder(); + $qb->select('uri') + ->from('cards') + ->where( + $qb->expr()->eq('addressbookid', $qb->createNamedParameter($addressBookId)) + ); // No synctoken supplied, this is the initial sync. - $query = "SELECT `uri` FROM `*PREFIX*cards` WHERE `addressbookid` = ?"; - $stmt = $this->db->prepare($query); - $stmt->execute([$addressBookId]); - + $stmt = $qb->execute(); $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); + $stmt->closeCursor(); } return $result; } |