diff options
Diffstat (limited to 'apps/dav/lib')
-rw-r--r-- | apps/dav/lib/CardDAV/CardDavBackend.php | 31 | ||||
-rw-r--r-- | apps/dav/lib/Migration/Version1008Date20181030113700.php | 52 |
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; + } +} |