62 $stmt = $this->pdo->prepare(
'SELECT id, uri, displayname, principaluri, description, synctoken FROM ' . $this->addressBooksTableName .
' WHERE principaluri = ?');
63 $stmt->execute([$principalUri]);
72 'principaluri' =>
$row[
'principaluri'],
73 '{DAV:}displayname' =>
$row[
'displayname'],
75 '{http://calendarserver.org/ns/}getctag' =>
$row[
'synctoken'],
76 '{http://sabredav.org/ns}sync-token' =>
$row[
'synctoken'] ?
$row[
'synctoken'] :
'0',
104 $supportedProperties = [
109 $propPatch->handle($supportedProperties,
function($mutations) use ($addressBookId) {
112 foreach ($mutations as $property => $newValue) {
115 case '{DAV:}displayname' :
116 $updates[
'displayname'] = $newValue;
119 $updates[
'description'] = $newValue;
123 $query =
'UPDATE ' . $this->addressBooksTableName .
' SET ';
125 foreach ($updates as
$key => $value) {
133 $query .=
' WHERE id = :addressbookid';
136 $updates[
'addressbookid'] = $addressBookId;
138 $stmt->execute($updates);
159 'displayname' => null,
160 'description' => null,
161 'principaluri' => $principalUri,
165 foreach ($properties as $property => $newValue) {
168 case '{DAV:}displayname' :
169 $values[
'displayname'] = $newValue;
172 $values[
'description'] = $newValue;
175 throw new DAV\Exception\BadRequest(
'Unknown property: ' . $property);
180 $query =
'INSERT INTO ' . $this->addressBooksTableName .
' (uri, displayname, description, principaluri, synctoken) VALUES (:uri, :displayname, :description, :principaluri, 1)';
183 return $this->pdo->lastInsertId(
184 $this->addressBooksTableName .
'_id_seq' 197 $stmt = $this->pdo->prepare(
'DELETE FROM ' . $this->cardsTableName .
' WHERE addressbookid = ?');
198 $stmt->execute([$addressBookId]);
200 $stmt = $this->pdo->prepare(
'DELETE FROM ' . $this->addressBooksTableName .
' WHERE id = ?');
201 $stmt->execute([$addressBookId]);
203 $stmt = $this->pdo->prepare(
'DELETE FROM ' . $this->addressBookChangesTableName .
' WHERE addressbookid = ?');
204 $stmt->execute([$addressBookId]);
229 $stmt = $this->pdo->prepare(
'SELECT id, uri, lastmodified, etag, size FROM ' . $this->cardsTableName .
' WHERE addressbookid = ?');
230 $stmt->execute([$addressbookId]);
233 while (
$row =
$stmt->fetch(\PDO::FETCH_ASSOC)) {
234 $row[
'etag'] =
'"' .
$row[
'etag'] .
'"';
235 $row[
'lastmodified'] = (int)
$row[
'lastmodified'];
256 $stmt = $this->pdo->prepare(
'SELECT id, carddata, uri, lastmodified, etag, size FROM ' . $this->cardsTableName .
' WHERE addressbookid = ? AND uri = ? LIMIT 1');
257 $stmt->execute([$addressBookId, $cardUri]);
283 $query =
'SELECT id, uri, lastmodified, etag, size, carddata FROM ' . $this->cardsTableName .
' WHERE addressbookid = ? AND uri IN (';
285 $query .= implode(
',', array_fill(0, count($uris),
'?'));
289 $stmt->execute(array_merge([$addressBookId], $uris));
291 while (
$row =
$stmt->fetch(\PDO::FETCH_ASSOC)) {
292 $row[
'etag'] =
'"' .
$row[
'etag'] .
'"';
293 $row[
'lastmodified'] = (int)
$row[
'lastmodified'];
327 $stmt = $this->pdo->prepare(
'INSERT INTO ' . $this->cardsTableName .
' (carddata, uri, lastmodified, addressbookid, size, etag) VALUES (?, ?, ?, ?, ?, ?)');
329 $etag = md5($cardData);
340 $this->
addChange($addressBookId, $cardUri, 1);
342 return '"' . $etag .
'"';
373 $stmt = $this->pdo->prepare(
'UPDATE ' . $this->cardsTableName .
' SET carddata = ?, lastmodified = ?, size = ?, etag = ? WHERE uri = ? AND addressbookid =?');
375 $etag = md5($cardData);
385 $this->
addChange($addressBookId, $cardUri, 2);
387 return '"' . $etag .
'"';
400 $stmt = $this->pdo->prepare(
'DELETE FROM ' . $this->cardsTableName .
' WHERE addressbookid = ? AND uri = ?');
401 $stmt->execute([$addressBookId, $cardUri]);
403 $this->
addChange($addressBookId, $cardUri, 3);
405 return $stmt->rowCount() === 1;
468 $stmt = $this->pdo->prepare(
'SELECT synctoken FROM ' . $this->addressBooksTableName .
' WHERE id = ?');
469 $stmt->execute([$addressBookId]);
470 $currentToken =
$stmt->fetchColumn(0);
472 if (is_null($currentToken))
return null;
475 'syncToken' => $currentToken,
483 $query =
"SELECT uri, operation FROM " . $this->addressBookChangesTableName .
" WHERE synctoken >= ? AND synctoken < ? AND addressbookid = ? ORDER BY synctoken";
484 if ($limit > 0)
$query .=
" LIMIT " . (int)$limit;
488 $stmt->execute([$syncToken, $currentToken, $addressBookId]);
494 while (
$row =
$stmt->fetch(\PDO::FETCH_ASSOC)) {
496 $changes[
$row[
'uri']] = $row[
'operation'];
500 foreach ($changes as $uri => $operation) {
502 switch ($operation) {
517 $query =
"SELECT uri FROM " . $this->cardsTableName .
" WHERE addressbookid = ?";
519 $stmt->execute([$addressBookId]);
535 protected function addChange($addressBookId, $objectUri, $operation) {
537 $stmt = $this->pdo->prepare(
'INSERT INTO ' . $this->addressBookChangesTableName .
' (uri, synctoken, addressbookid, operation) SELECT ?, synctoken, ?, ? FROM ' . $this->addressBooksTableName .
' WHERE id = ?');
544 $stmt = $this->pdo->prepare(
'UPDATE ' . $this->addressBooksTableName .
' SET synctoken = synctoken + 1 WHERE id = ?');
addChange($addressBookId, $objectUri, $operation)
Adds a change record to the addressbookchanges table.
getCards($addressbookId)
Returns all cards for a specific addressbook id.
This class represents a set of properties that are going to be updated.
WebDAV-sync support for CardDAV backends.
const NS_CARDDAV
xml namespace for CardDAV elements
updateCard($addressBookId, $cardUri, $cardData)
Updates a card.
createCard($addressBookId, $cardUri, $cardData)
Creates a new card.
createAddressBook($principalUri, $url, array $properties)
Creates a new address book.
getAddressBooksForUser($principalUri)
Returns the list of addressbooks for a specific user.
getCard($addressBookId, $cardUri)
Returns a specific card.
CardDAV abstract Backend.
getMultipleCards($addressBookId, array $uris)
Returns a list of cards.
$addressBookChangesTableName
$addressBooksTableName
The PDO table name used to store addressbooks.
deleteAddressBook($addressBookId)
Deletes an entire addressbook and all its contents.
__construct(\PDO $pdo)
Sets up the object.
deleteCard($addressBookId, $cardUri)
Deletes a card.
getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit=null)
The getChanges method returns all the changes that have happened, since the specified syncToken in th...
updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch)
Updates properties for an address book.
$cardsTableName
The PDO table name used to store cards.