diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2021-02-15 16:39:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-15 16:39:46 +0100 |
commit | 9fd72b0d3a4ebfad2291a18aefc51e999fbb0744 (patch) | |
tree | 1ab4e3eea2f2e4cf424eef2b424dd1e5463f9032 /apps/dav | |
parent | b48d53d272b063db8714a1d7d9e12101317e48ee (diff) | |
parent | b0f205f97c37a94c55013ad69eb7c0f746bc58b0 (diff) | |
download | nextcloud-server-9fd72b0d3a4ebfad2291a18aefc51e999fbb0744.tar.gz nextcloud-server-9fd72b0d3a4ebfad2291a18aefc51e999fbb0744.zip |
Merge pull request #25595 from nextcloud/enh/caldavbackend/getChangesForCalendar_querybuilder
Move getChangesForCalendar to QueryBuilder
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/lib/CalDAV/CalDavBackend.php | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index ea1a30c629e..0cceeae12dc 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -1955,17 +1955,22 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @param string $calendarId * @param string $syncToken * @param int $syncLevel - * @param int $limit + * @param int|null $limit * @param int $calendarType * @return array */ public function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null, $calendarType = self::CALENDAR_TYPE_CALENDAR) { // Current synctoken - $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); - $stmt->execute([ $calendarId ]); + $qb = $this->db->getQueryBuilder(); + $qb->select('synctoken') + ->from('calendars') + ->where( + $qb->expr()->eq('id', $qb->createNamedParameter($calendarId)) + ); + $stmt = $qb->execute(); $currentToken = $stmt->fetchOne(); - if (is_null($currentToken)) { + if ($currentToken === false) { return null; } @@ -1977,14 +1982,24 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription ]; if ($syncToken) { - $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? AND `calendartype` = ? ORDER BY `synctoken`"; - if ($limit > 0) { - $query .= " LIMIT " . (int)$limit; + $qb = $this->db->getQueryBuilder(); + + $qb->select('uri', 'operation') + ->from('calendarchanges') + ->where( + $qb->expr()->andX( + $qb->expr()->gte('synctoken', $qb->createNamedParameter($syncToken)), + $qb->expr()->lt('synctoken', $qb->createNamedParameter($currentToken)), + $qb->expr()->eq('calendarid', $qb->createNamedParameter($calendarId)), + $qb->expr()->eq('calendartype', $qb->createNamedParameter($calendarType)) + ) + )->orderBy('synctoken'); + if (is_int($limit) && $limit > 0) { + $qb->setMaxResults($limit); } // Fetching all changes - $stmt = $this->db->prepare($query); - $stmt->execute([$syncToken, $currentToken, $calendarId, $calendarType]); + $stmt = $qb->execute(); $changes = []; @@ -2009,10 +2024,16 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } } else { // No synctoken supplied, this is the initial sync. - $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `calendartype` = ?"; - $stmt = $this->db->prepare($query); - $stmt->execute([$calendarId, $calendarType]); - + $qb = $this->db->getQueryBuilder(); + $qb->select('uri') + ->from('calendarobjects') + ->where( + $qb->expr()->andX( + $qb->expr()->eq('calendarid', $qb->createNamedParameter($calendarId)), + $qb->expr()->eq('calendartype', $qb->createNamedParameter($calendarType)) + ) + ); + $stmt = $qb->execute(); $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); } return $result; |