summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2018-11-02 19:37:48 +0100
committerGitHub <noreply@github.com>2018-11-02 19:37:48 +0100
commit9d89f8bbac3d8a31e1f6a4a40d81014ec309c84c (patch)
tree9de3ab04d6cb6a028a60d2d806882df70dcd8677 /apps/dav/lib
parent927130ef344bd5e9f9449504eb6511ca4a2e524d (diff)
parent66624cfe0a56fb4ca14c4d15ce62ddf0a389078d (diff)
downloadnextcloud-server-9d89f8bbac3d8a31e1f6a4a40d81014ec309c84c.tar.gz
nextcloud-server-9d89f8bbac3d8a31e1f6a4a40d81014ec309c84c.zip
Merge pull request #12071 from nextcloud/addressbook-uid-check-migration
Addressbook uid check migration
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php31
-rw-r--r--apps/dav/lib/Migration/Version1008Date20181030113700.php52
2 files changed, 80 insertions, 3 deletions
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php
index a2d3b03147b..a8907f631cd 100644
--- a/apps/dav/lib/CardDAV/CardDavBackend.php
+++ b/apps/dav/lib/CardDAV/CardDavBackend.php
@@ -494,7 +494,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
*/
function getCards($addressBookId) {
$query = $this->db->getQueryBuilder();
- $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata'])
+ $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid'])
->from('cards')
->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)));
@@ -525,7 +525,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
*/
function getCard($addressBookId, $cardUri) {
$query = $this->db->getQueryBuilder();
- $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata'])
+ $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid'])
->from('cards')
->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
->andWhere($query->expr()->eq('uri', $query->createNamedParameter($cardUri)))
@@ -563,7 +563,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
$cards = [];
$query = $this->db->getQueryBuilder();
- $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata'])
+ $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid'])
->from('cards')
->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
->andWhere($query->expr()->in('uri', $query->createParameter('uri')));
@@ -609,6 +609,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
*/
function createCard($addressBookId, $cardUri, $cardData) {
$etag = md5($cardData);
+ $uid = $this->getUID($cardData);
$query = $this->db->getQueryBuilder();
$query->insert('cards')
@@ -619,6 +620,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
'addressbookid' => $query->createNamedParameter($addressBookId),
'size' => $query->createNamedParameter(strlen($cardData)),
'etag' => $query->createNamedParameter($etag),
+ 'uid' => $query->createNamedParameter($uid),
])
->execute();
@@ -661,6 +663,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
*/
function updateCard($addressBookId, $cardUri, $cardData) {
+ $uid = $this->getUID($cardData);
$etag = md5($cardData);
$query = $this->db->getQueryBuilder();
$query->update('cards')
@@ -668,6 +671,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
->set('lastmodified', $query->createNamedParameter(time()))
->set('size', $query->createNamedParameter(strlen($cardData)))
->set('etag', $query->createNamedParameter($etag))
+ ->set('uid', $query->createNamedParameter($uid))
->where($query->expr()->eq('uri', $query->createNamedParameter($cardUri)))
->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
->execute();
@@ -1125,4 +1129,25 @@ class CardDavBackend implements BackendInterface, SyncSupport {
$addressbookInfo[$displaynameKey] = $principalInformation['{DAV:}displayname'];
}
}
+
+ /**
+ * Extract UID from vcard
+ *
+ * @param string $cardData the vcard raw data
+ * @return string the uid
+ * @throws BadRequest if no UID is available
+ */
+ private function getUID($cardData) {
+ if ($cardData != '') {
+ $vCard = Reader::read($cardData);
+ if ($vCard->UID) {
+ $uid = $vCard->UID->getValue();
+ return $uid;
+ }
+ // should already be handled, but just in case
+ throw new BadRequest('vCards on CardDAV servers MUST have a UID property');
+ }
+ // should already be handled, but just in case
+ throw new BadRequest('vCard can not be empty');
+ }
}
diff --git a/apps/dav/lib/Migration/Version1008Date20181030113700.php b/apps/dav/lib/Migration/Version1008Date20181030113700.php
new file mode 100644
index 00000000000..1cc6223a9e9
--- /dev/null
+++ b/apps/dav/lib/Migration/Version1008Date20181030113700.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv@protonmail.com)
+ *
+ * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\DAV\Migration;
+
+use Closure;
+
+use Doctrine\DBAL\Types\Type;
+use OCP\DB\ISchemaWrapper;
+use OCP\Migration\SimpleMigrationStep;
+use OCP\Migration\IOutput;
+
+/**
+ * add column for share notes
+ *
+ * Class Version15000Date20180927120000
+ */
+class Version1008Date20181030113700 extends SimpleMigrationStep {
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
+
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+
+ $table = $schema->getTable('cards');
+ $table->addColumn('uid', Type::STRING, [
+ 'notnull' => false,
+ 'length' => 255
+ ]);
+
+ return $schema;
+ }
+}