]> source.dussan.org Git - nextcloud-server.git/commitdiff
Properly set uid and create and update
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Sat, 27 Oct 2018 09:54:57 +0000 (11:54 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Thu, 1 Nov 2018 14:00:49 +0000 (15:00 +0100)
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
apps/dav/lib/CardDAV/CardDavBackend.php

index a2d3b03147b645dbfef09897599dc04264ea48fc..a9d65f2f0f9cd39601a6245ec54f1beb2b9a2121 100644 (file)
@@ -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,10 @@ class CardDavBackend implements BackendInterface, SyncSupport {
                        $addressbookInfo[$displaynameKey] = $principalInformation['{DAV:}displayname'];
                }
        }
+
+       private function getUID($cardData) {
+               $vCard = Reader::read($cardData);
+               $uid = $vCard->UID->getValue();
+               return $uid;
+       }
 }