From 580c3f4ffe9608d2beb56d418c68b3b112420e76 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 10 Nov 2019 12:49:51 +0000 Subject: another bulk of composer updates (cherry picked from commit 6685381fd8db507493c3d7c1793f8c05c681bbce) --- vendor/sabre/dav/lib/CardDAV/Backend/PDO.php | 257 +++++++++++++-------------- 1 file changed, 125 insertions(+), 132 deletions(-) (limited to 'vendor/sabre/dav/lib/CardDAV/Backend/PDO.php') diff --git a/vendor/sabre/dav/lib/CardDAV/Backend/PDO.php b/vendor/sabre/dav/lib/CardDAV/Backend/PDO.php index 13487e9da..0659455e5 100644 --- a/vendor/sabre/dav/lib/CardDAV/Backend/PDO.php +++ b/vendor/sabre/dav/lib/CardDAV/Backend/PDO.php @@ -1,12 +1,14 @@ pdo = $pdo; - } /** * Returns the list of addressbooks for a specific user. * * @param string $principalUri + * * @return array */ - function getAddressBooksForUser($principalUri) { - - $stmt = $this->pdo->prepare('SELECT id, uri, displayname, principaluri, description, synctoken FROM ' . $this->addressBooksTableName . ' WHERE principaluri = ?'); + public function getAddressBooksForUser($principalUri) + { + $stmt = $this->pdo->prepare('SELECT id, uri, displayname, principaluri, description, synctoken FROM '.$this->addressBooksTableName.' WHERE principaluri = ?'); $stmt->execute([$principalUri]); $addressBooks = []; foreach ($stmt->fetchAll() as $row) { - $addressBooks[] = [ - 'id' => $row['id'], - 'uri' => $row['uri'], - 'principaluri' => $row['principaluri'], - '{DAV:}displayname' => $row['displayname'], - '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], - '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], - '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', + 'id' => $row['id'], + 'uri' => $row['uri'], + 'principaluri' => $row['principaluri'], + '{DAV:}displayname' => $row['displayname'], + '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'], + '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', ]; - } return $addressBooks; - } - /** * Updates properties for an address book. * @@ -95,32 +93,29 @@ class PDO extends AbstractBackend implements SyncSupport { * * Read the PropPatch documentation for more info and examples. * - * @param string $addressBookId + * @param string $addressBookId * @param \Sabre\DAV\PropPatch $propPatch - * @return void */ - function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) { - + public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) + { $supportedProperties = [ '{DAV:}displayname', - '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description', + '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description', ]; - $propPatch->handle($supportedProperties, function($mutations) use ($addressBookId) { - + $propPatch->handle($supportedProperties, function ($mutations) use ($addressBookId) { $updates = []; foreach ($mutations as $property => $newValue) { - switch ($property) { - case '{DAV:}displayname' : + case '{DAV:}displayname': $updates['displayname'] = $newValue; break; - case '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' : + case '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description': $updates['description'] = $newValue; break; } } - $query = 'UPDATE ' . $this->addressBooksTableName . ' SET '; + $query = 'UPDATE '.$this->addressBooksTableName.' SET '; $first = true; foreach ($updates as $key => $value) { if ($first) { @@ -128,7 +123,7 @@ class PDO extends AbstractBackend implements SyncSupport { } else { $query .= ', '; } - $query .= ' ' . $key . ' = :' . $key . ' '; + $query .= ' '.$key.' = :'.$key.' '; } $query .= ' WHERE id = :addressbookid'; @@ -137,72 +132,67 @@ class PDO extends AbstractBackend implements SyncSupport { $stmt->execute($updates); - $this->addChange($addressBookId, "", 2); + $this->addChange($addressBookId, '', 2); return true; - }); - } /** - * Creates a new address book + * Creates a new address book. * * @param string $principalUri - * @param string $url Just the 'basename' of the url. - * @param array $properties + * @param string $url just the 'basename' of the url + * @param array $properties + * * @return int Last insert id */ - function createAddressBook($principalUri, $url, array $properties) { - + public function createAddressBook($principalUri, $url, array $properties) + { $values = [ - 'displayname' => null, - 'description' => null, + 'displayname' => null, + 'description' => null, 'principaluri' => $principalUri, - 'uri' => $url, + 'uri' => $url, ]; foreach ($properties as $property => $newValue) { - switch ($property) { - case '{DAV:}displayname' : + case '{DAV:}displayname': $values['displayname'] = $newValue; break; - case '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' : + case '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description': $values['description'] = $newValue; break; - default : - throw new DAV\Exception\BadRequest('Unknown property: ' . $property); + default: + throw new DAV\Exception\BadRequest('Unknown property: '.$property); } - } - $query = 'INSERT INTO ' . $this->addressBooksTableName . ' (uri, displayname, description, principaluri, synctoken) VALUES (:uri, :displayname, :description, :principaluri, 1)'; + $query = 'INSERT INTO '.$this->addressBooksTableName.' (uri, displayname, description, principaluri, synctoken) VALUES (:uri, :displayname, :description, :principaluri, 1)'; $stmt = $this->pdo->prepare($query); $stmt->execute($values); + return $this->pdo->lastInsertId( - $this->addressBooksTableName . '_id_seq' + $this->addressBooksTableName.'_id_seq' ); - } /** - * Deletes an entire addressbook and all its contents + * Deletes an entire addressbook and all its contents. * * @param int $addressBookId - * @return void */ - function deleteAddressBook($addressBookId) { - - $stmt = $this->pdo->prepare('DELETE FROM ' . $this->cardsTableName . ' WHERE addressbookid = ?'); + public function deleteAddressBook($addressBookId) + { + $stmt = $this->pdo->prepare('DELETE FROM '.$this->cardsTableName.' WHERE addressbookid = ?'); $stmt->execute([$addressBookId]); - $stmt = $this->pdo->prepare('DELETE FROM ' . $this->addressBooksTableName . ' WHERE id = ?'); + $stmt = $this->pdo->prepare('DELETE FROM '.$this->addressBooksTableName.' WHERE id = ?'); $stmt->execute([$addressBookId]); - $stmt = $this->pdo->prepare('DELETE FROM ' . $this->addressBookChangesTableName . ' WHERE addressbookid = ?'); + $stmt = $this->pdo->prepare('DELETE FROM '.$this->addressBookChangesTableName.' WHERE addressbookid = ?'); $stmt->execute([$addressBookId]); - } /** @@ -222,21 +212,22 @@ class PDO extends AbstractBackend implements SyncSupport { * This may speed up certain requests, especially with large cards. * * @param mixed $addressbookId + * * @return array */ - function getCards($addressbookId) { - - $stmt = $this->pdo->prepare('SELECT id, uri, lastmodified, etag, size FROM ' . $this->cardsTableName . ' WHERE addressbookid = ?'); + public function getCards($addressbookId) + { + $stmt = $this->pdo->prepare('SELECT id, uri, lastmodified, etag, size FROM '.$this->cardsTableName.' WHERE addressbookid = ?'); $stmt->execute([$addressbookId]); $result = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { - $row['etag'] = '"' . $row['etag'] . '"'; - $row['lastmodified'] = (int)$row['lastmodified']; + $row['etag'] = '"'.$row['etag'].'"'; + $row['lastmodified'] = (int) $row['lastmodified']; $result[] = $row; } - return $result; + return $result; } /** @@ -247,23 +238,26 @@ class PDO extends AbstractBackend implements SyncSupport { * * If the card does not exist, you must return false. * - * @param mixed $addressBookId + * @param mixed $addressBookId * @param string $cardUri + * * @return array */ - function getCard($addressBookId, $cardUri) { - - $stmt = $this->pdo->prepare('SELECT id, carddata, uri, lastmodified, etag, size FROM ' . $this->cardsTableName . ' WHERE addressbookid = ? AND uri = ? LIMIT 1'); + public function getCard($addressBookId, $cardUri) + { + $stmt = $this->pdo->prepare('SELECT id, carddata, uri, lastmodified, etag, size FROM '.$this->cardsTableName.' WHERE addressbookid = ? AND uri = ? LIMIT 1'); $stmt->execute([$addressBookId, $cardUri]); $result = $stmt->fetch(\PDO::FETCH_ASSOC); - if (!$result) return false; + if (!$result) { + return false; + } + + $result['etag'] = '"'.$result['etag'].'"'; + $result['lastmodified'] = (int) $result['lastmodified']; - $result['etag'] = '"' . $result['etag'] . '"'; - $result['lastmodified'] = (int)$result['lastmodified']; return $result; - } /** @@ -276,11 +270,12 @@ class PDO extends AbstractBackend implements SyncSupport { * * @param mixed $addressBookId * @param array $uris + * * @return array */ - function getMultipleCards($addressBookId, array $uris) { - - $query = 'SELECT id, uri, lastmodified, etag, size, carddata FROM ' . $this->cardsTableName . ' WHERE addressbookid = ? AND uri IN ('; + public function getMultipleCards($addressBookId, array $uris) + { + $query = 'SELECT id, uri, lastmodified, etag, size, carddata FROM '.$this->cardsTableName.' WHERE addressbookid = ? AND uri IN ('; // Inserting a whole bunch of question marks $query .= implode(',', array_fill(0, count($uris), '?')); $query .= ')'; @@ -289,12 +284,12 @@ class PDO extends AbstractBackend implements SyncSupport { $stmt->execute(array_merge([$addressBookId], $uris)); $result = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { - $row['etag'] = '"' . $row['etag'] . '"'; - $row['lastmodified'] = (int)$row['lastmodified']; + $row['etag'] = '"'.$row['etag'].'"'; + $row['lastmodified'] = (int) $row['lastmodified']; $result[] = $row; } - return $result; + return $result; } /** @@ -317,14 +312,15 @@ class PDO extends AbstractBackend implements SyncSupport { * * If you don't return an ETag, you can just return null. * - * @param mixed $addressBookId + * @param mixed $addressBookId * @param string $cardUri * @param string $cardData + * * @return string|null */ - function createCard($addressBookId, $cardUri, $cardData) { - - $stmt = $this->pdo->prepare('INSERT INTO ' . $this->cardsTableName . ' (carddata, uri, lastmodified, addressbookid, size, etag) VALUES (?, ?, ?, ?, ?, ?)'); + public function createCard($addressBookId, $cardUri, $cardData) + { + $stmt = $this->pdo->prepare('INSERT INTO '.$this->cardsTableName.' (carddata, uri, lastmodified, addressbookid, size, etag) VALUES (?, ?, ?, ?, ?, ?)'); $etag = md5($cardData); @@ -339,8 +335,7 @@ class PDO extends AbstractBackend implements SyncSupport { $this->addChange($addressBookId, $cardUri, 1); - return '"' . $etag . '"'; - + return '"'.$etag.'"'; } /** @@ -363,14 +358,15 @@ class PDO extends AbstractBackend implements SyncSupport { * * If you don't return an ETag, you can just return null. * - * @param mixed $addressBookId + * @param mixed $addressBookId * @param string $cardUri * @param string $cardData + * * @return string|null */ - function updateCard($addressBookId, $cardUri, $cardData) { - - $stmt = $this->pdo->prepare('UPDATE ' . $this->cardsTableName . ' SET carddata = ?, lastmodified = ?, size = ?, etag = ? WHERE uri = ? AND addressbookid =?'); + public function updateCard($addressBookId, $cardUri, $cardData) + { + $stmt = $this->pdo->prepare('UPDATE '.$this->cardsTableName.' SET carddata = ?, lastmodified = ?, size = ?, etag = ? WHERE uri = ? AND addressbookid =?'); $etag = md5($cardData); $stmt->execute([ @@ -379,31 +375,30 @@ class PDO extends AbstractBackend implements SyncSupport { strlen($cardData), $etag, $cardUri, - $addressBookId + $addressBookId, ]); $this->addChange($addressBookId, $cardUri, 2); - return '"' . $etag . '"'; - + return '"'.$etag.'"'; } /** - * Deletes a card + * Deletes a card. * - * @param mixed $addressBookId + * @param mixed $addressBookId * @param string $cardUri + * * @return bool */ - function deleteCard($addressBookId, $cardUri) { - - $stmt = $this->pdo->prepare('DELETE FROM ' . $this->cardsTableName . ' WHERE addressbookid = ? AND uri = ?'); + public function deleteCard($addressBookId, $cardUri) + { + $stmt = $this->pdo->prepare('DELETE FROM '.$this->cardsTableName.' WHERE addressbookid = ? AND uri = ?'); $stmt->execute([$addressBookId, $cardUri]); $this->addChange($addressBookId, $cardUri, 3); - return $stmt->rowCount() === 1; - + return 1 === $stmt->rowCount(); } /** @@ -458,30 +453,34 @@ class PDO extends AbstractBackend implements SyncSupport { * * @param string $addressBookId * @param string $syncToken - * @param int $syncLevel - * @param int $limit + * @param int $syncLevel + * @param int $limit + * * @return array */ - function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) { - + public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) + { // Current synctoken - $stmt = $this->pdo->prepare('SELECT synctoken FROM ' . $this->addressBooksTableName . ' WHERE id = ?'); + $stmt = $this->pdo->prepare('SELECT synctoken FROM '.$this->addressBooksTableName.' WHERE id = ?'); $stmt->execute([$addressBookId]); $currentToken = $stmt->fetchColumn(0); - if (is_null($currentToken)) return null; + if (is_null($currentToken)) { + return null; + } $result = [ 'syncToken' => $currentToken, - 'added' => [], - 'modified' => [], - 'deleted' => [], + 'added' => [], + 'modified' => [], + 'deleted' => [], ]; if ($syncToken) { - - $query = "SELECT uri, operation FROM " . $this->addressBookChangesTableName . " WHERE synctoken >= ? AND synctoken < ? AND addressbookid = ? ORDER BY synctoken"; - if ($limit > 0) $query .= " LIMIT " . (int)$limit; + $query = 'SELECT uri, operation FROM '.$this->addressBookChangesTableName.' WHERE synctoken >= ? AND synctoken < ? AND addressbookid = ? ORDER BY synctoken'; + if ($limit > 0) { + $query .= ' LIMIT '.(int) $limit; + } // Fetching all changes $stmt = $this->pdo->prepare($query); @@ -492,13 +491,10 @@ class PDO extends AbstractBackend implements SyncSupport { // This loop ensures that any duplicates are overwritten, only the // last change on a node is relevant. while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { - $changes[$row['uri']] = $row['operation']; - } foreach ($changes as $uri => $operation) { - switch ($operation) { case 1: $result['added'][] = $uri; @@ -510,41 +506,38 @@ class PDO extends AbstractBackend implements SyncSupport { $result['deleted'][] = $uri; break; } - } } else { // No synctoken supplied, this is the initial sync. - $query = "SELECT uri FROM " . $this->cardsTableName . " WHERE addressbookid = ?"; + $query = 'SELECT uri FROM '.$this->cardsTableName.' WHERE addressbookid = ?'; $stmt = $this->pdo->prepare($query); $stmt->execute([$addressBookId]); $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); } - return $result; + return $result; } /** * Adds a change record to the addressbookchanges table. * - * @param mixed $addressBookId + * @param mixed $addressBookId * @param string $objectUri - * @param int $operation 1 = add, 2 = modify, 3 = delete - * @return void + * @param int $operation 1 = add, 2 = modify, 3 = delete */ - protected function addChange($addressBookId, $objectUri, $operation) { - - $stmt = $this->pdo->prepare('INSERT INTO ' . $this->addressBookChangesTableName . ' (uri, synctoken, addressbookid, operation) SELECT ?, synctoken, ?, ? FROM ' . $this->addressBooksTableName . ' WHERE id = ?'); + protected function addChange($addressBookId, $objectUri, $operation) + { + $stmt = $this->pdo->prepare('INSERT INTO '.$this->addressBookChangesTableName.' (uri, synctoken, addressbookid, operation) SELECT ?, synctoken, ?, ? FROM '.$this->addressBooksTableName.' WHERE id = ?'); $stmt->execute([ $objectUri, $addressBookId, $operation, - $addressBookId + $addressBookId, ]); - $stmt = $this->pdo->prepare('UPDATE ' . $this->addressBooksTableName . ' SET synctoken = synctoken + 1 WHERE id = ?'); + $stmt = $this->pdo->prepare('UPDATE '.$this->addressBooksTableName.' SET synctoken = synctoken + 1 WHERE id = ?'); $stmt->execute([ - $addressBookId + $addressBookId, ]); - } } -- cgit v1.2.3