Move getChangesForCalendar to QueryBuilder
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
19f1cc6dde
commit
b0f205f97c
|
@ -1955,17 +1955,22 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
||||||
* @param string $calendarId
|
* @param string $calendarId
|
||||||
* @param string $syncToken
|
* @param string $syncToken
|
||||||
* @param int $syncLevel
|
* @param int $syncLevel
|
||||||
* @param int $limit
|
* @param int|null $limit
|
||||||
* @param int $calendarType
|
* @param int $calendarType
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null, $calendarType = self::CALENDAR_TYPE_CALENDAR) {
|
public function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null, $calendarType = self::CALENDAR_TYPE_CALENDAR) {
|
||||||
// Current synctoken
|
// Current synctoken
|
||||||
$stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?');
|
$qb = $this->db->getQueryBuilder();
|
||||||
$stmt->execute([ $calendarId ]);
|
$qb->select('synctoken')
|
||||||
|
->from('calendars')
|
||||||
|
->where(
|
||||||
|
$qb->expr()->eq('id', $qb->createNamedParameter($calendarId))
|
||||||
|
);
|
||||||
|
$stmt = $qb->execute();
|
||||||
$currentToken = $stmt->fetchOne();
|
$currentToken = $stmt->fetchOne();
|
||||||
|
|
||||||
if (is_null($currentToken)) {
|
if ($currentToken === false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1977,14 +1982,24 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($syncToken) {
|
if ($syncToken) {
|
||||||
$query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? AND `calendartype` = ? ORDER BY `synctoken`";
|
$qb = $this->db->getQueryBuilder();
|
||||||
if ($limit > 0) {
|
|
||||||
$query .= " LIMIT " . (int)$limit;
|
$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
|
// Fetching all changes
|
||||||
$stmt = $this->db->prepare($query);
|
$stmt = $qb->execute();
|
||||||
$stmt->execute([$syncToken, $currentToken, $calendarId, $calendarType]);
|
|
||||||
|
|
||||||
$changes = [];
|
$changes = [];
|
||||||
|
|
||||||
|
@ -2009,10 +2024,16 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No synctoken supplied, this is the initial sync.
|
// No synctoken supplied, this is the initial sync.
|
||||||
$query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `calendartype` = ?";
|
$qb = $this->db->getQueryBuilder();
|
||||||
$stmt = $this->db->prepare($query);
|
$qb->select('uri')
|
||||||
$stmt->execute([$calendarId, $calendarType]);
|
->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);
|
$result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|
Loading…
Reference in New Issue