]> source.dussan.org Git - nextcloud-server.git/commitdiff
Address book data lost when any user receiving a share is deleted backport 3499/head
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Wed, 15 Feb 2017 15:09:00 +0000 (16:09 +0100)
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Wed, 15 Feb 2017 15:09:00 +0000 (16:09 +0100)
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
apps/dav/lib/CardDAV/CardDavBackend.php
apps/dav/lib/HookManager.php
apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
apps/dav/tests/unit/DAV/HookManagerTest.php

index a320984c1fe534fad84ed05d2da3eadec38525aa..a6d057452e63f8d1b510d0ff9973e9039ee1b41d 100644 (file)
@@ -195,6 +195,33 @@ class CardDavBackend implements BackendInterface, SyncSupport {
                return array_values($addressBooks);
        }
 
+       public function getUsersOwnAddressBooks($principalUri) {
+               $principalUriOriginal = $principalUri;
+               $principalUri = $this->convertPrincipal($principalUri, true);
+               $query = $this->db->getQueryBuilder();
+               $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken'])
+                         ->from('addressbooks')
+                         ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
+
+               $addressBooks = [];
+
+               $result = $query->execute();
+               while($row = $result->fetch()) {
+                       $addressBooks[$row['id']] = [
+                               'id'  => $row['id'],
+                               'uri' => $row['uri'],
+                               'principaluri' => $this->convertPrincipal($row['principaluri'], false),
+                               '{DAV:}displayname' => $row['displayname'],
+                               '{' . 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',
+                       ];
+               }
+               $result->closeCursor();
+
+               return array_values($addressBooks);
+       }
+
        private function getUserDisplayName($uid) {
                if (!isset($this->userDisplayNames[$uid])) {
                        $user = $this->userManager->get($uid);
index 26f3895a4598688d55eabb4117dbfc3679134516..8148df2d37b45514bb83b1776e4606d8763ed558 100644 (file)
@@ -96,7 +96,7 @@ class HookManager {
                $uid = $params['uid'];
                $this->usersToDelete[$uid] = $this->userManager->get($uid);
                $this->calendarsToDelete = $this->calDav->getUsersOwnCalendars('principals/users/' . $uid);
-               $this->addressBooksToDelete = $this->cardDav->getAddressBooksForUser('principals/users/' . $uid);
+               $this->addressBooksToDelete = $this->cardDav->getUsersOwnAddressBooks('principals/users/' . $uid);
        }
 
        public function postDeleteUser($params) {
index f4c321fa6d0e77c1b517a483fe3a13ad4472f175..a4445217469d89e76065b6951b95dc24d419db15 100644 (file)
@@ -273,7 +273,7 @@ class CardDavBackendTest extends TestCase {
 
                // create a new address book
                $this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
-               $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
+               $books = $this->backend->getUsersOwnAddressBooks(self::UNIT_TEST_USER);
                $this->assertEquals(1, count($books));
 
                $bookId = $books[0]['id'];
index 9579ce1c6d3f0af2aa5dae6828d673670d2f09c5..375bda9f3c219dd55e3b92f43ecb77567e5a468a 100644 (file)
@@ -195,7 +195,7 @@ class HookManagerTest extends TestCase {
                $card = $this->getMockBuilder(CardDavBackend::class)
                        ->disableOriginalConstructor()
                        ->getMock();
-               $card->expects($this->once())->method('getAddressBooksForUser')->willReturn([
+               $card->expects($this->once())->method('getUsersOwnAddressBooks')->willReturn([
                        ['id' => 'personal']
                ]);
                $card->expects($this->once())->method('deleteAddressBook');