示例#1
0
 /**
  * @param string $principal
  * @param string $id
  * @param array $properties
  * @return array|null
  * @throws \Sabre\DAV\Exception\BadRequest
  */
 protected function ensureSystemAddressBookExists($principal, $id, $properties)
 {
     $book = $this->backend->getAddressBooksByUri($id);
     if (!is_null($book)) {
         return $book;
     }
     $this->backend->createAddressBook($principal, $id, $properties);
     return $this->backend->getAddressBooksByUri($id);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $user = $input->getArgument('user');
     if (!$this->userManager->userExists($user)) {
         throw new \InvalidArgumentException("User <{$user}> in unknown.");
     }
     $name = $input->getArgument('name');
     $this->cardDavBackend->createAddressBook("principals/users/{$user}", $name, []);
 }
示例#3
0
 protected function ensureSystemAddressBookExists()
 {
     $book = $this->backend->getAddressBooksByUri('system');
     if (!is_null($book)) {
         return $book;
     }
     $systemPrincipal = "principals/system/system";
     $this->backend->createAddressBook($systemPrincipal, 'system', ['{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance']);
     return $this->backend->getAddressBooksByUri('system');
 }
示例#4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $user = $input->getArgument('user');
     if (!$this->userManager->userExists($user)) {
         throw new \InvalidArgumentException("User <{$user}> in unknown.");
     }
     $principalBackend = new Principal($this->userManager, $this->groupManager);
     $name = $input->getArgument('name');
     $carddav = new CardDavBackend($this->dbConnection, $principalBackend, $this->logger);
     $carddav->createAddressBook("principals/users/{$user}", $name, []);
 }
 public function testCollectCardProperties()
 {
     $query = $this->db->getQueryBuilder();
     $query->insert($this->dbCardsPropertiesTable)->values(['addressbookid' => $query->createNamedParameter(666), 'cardid' => $query->createNamedParameter(777), 'name' => $query->createNamedParameter('FN'), 'value' => $query->createNamedParameter('John Doe'), 'preferred' => $query->createNamedParameter(0)])->execute();
     $result = $this->backend->collectCardProperties(666, 'FN');
     $this->assertEquals(['John Doe'], $result);
 }
示例#6
0
 /**
  * create UID for contact
  *
  * @return string
  */
 protected function createUid()
 {
     do {
         $uid = $this->getUid();
     } while (!empty($this->backend->getContact($uid . '.vcf')));
     return $uid;
 }
示例#7
0
 public function updateCard($addressBookId, $uid)
 {
     /**
      * @param \Sabre\VObject\Component\VCard $vCard
      * @param \OC\User\User $user
      */
     $user = $this->userManager->get($uid);
     $userId = $user->getUID();
     $cardId = md5($userId) . ".vcf";
     $card = $this->cardDavBackend->getCard($addressBookId, $cardId);
     if (!$card) {
         $this->insertCard($addressBookId, $uid);
     } else {
         $vCard = Reader::read($card['carddata']);
         $needsUpdate = $this->converterUser->updateCard($vCard, $user);
         if ($needsUpdate) {
             $groups = \OC::$server->getGroupManager()->getUserGroups($user);
             if ($groups) {
                 foreach ($groups as $groupName => $groupInfo) {
                     $vCard->add(new Text($vCard, 'CATEGORIES', $groupName));
                 }
             }
             $this->cardDavBackend->updateCard($addressBookId, $cardId, $vCard->serialize());
             //                $this->cardDavBackend->deleteCard($addressBookId, $cardId);
             //                $this->insertCard($addressBookId, $uid);
         }
     }
 }
示例#8
0
 /**
  * @param int $addressBookId
  * @param int $newAddressBookId
  */
 private function migrateShares($addressBookId, $newAddressBookId)
 {
     $shares = $this->adapter->getShares($addressBookId);
     if (empty($shares)) {
         return;
     }
     $add = array_map(function ($s) {
         $prefix = 'principal:principals/users/';
         if ($s['share_type'] === 1) {
             $prefix = 'principal:principals/groups/';
         }
         return ['href' => $prefix . $s['share_with']];
     }, $shares);
     $newAddressBook = $this->backend->getAddressBookById($newAddressBookId);
     $book = new AddressBook($this->backend, $newAddressBook);
     $this->backend->updateShares($book, $add, []);
 }
示例#9
0
 /**
  * Retrieves a single contact from the ContactsManager and parse
  * them to a usable format
  * TODO Could be a problem if too many contacts.
  * @return array 
  */
 public function getContact($id)
 {
     $activeAddressbooks = $this->getAddressBooksIDsForUser();
     foreach ($activeAddressbooks as $activeAddressbook) {
         $contact = $this->backend->getCard($activeAddressbook, $this->backend->getCardUri($id));
         if ($contact != null) {
             return new Contact($this->fbController, $this->backend, $contact['id'], $contact['uri'], $contact['lastmodified'], $contact['etag'], $activeAddressbook, VObject\Reader::read($contact["carddata"]));
         }
     }
     return false;
 }
示例#10
0
 public function testSyncSupport()
 {
     // create a new address book
     $this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
     $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
     $this->assertEquals(1, count($books));
     $bookId = $books[0]['id'];
     // fist call without synctoken
     $changes = $this->backend->getChangesForAddressBook($bookId, '', 1);
     $syncToken = $changes['syncToken'];
     // add a change
     $uri0 = $this->getUniqueID('card');
     $this->backend->createCard($bookId, $uri0, '');
     // look for changes
     $changes = $this->backend->getChangesForAddressBook($bookId, $syncToken, 1);
     $this->assertEquals($uri0, $changes['added'][0]);
 }
示例#11
0
 public function syncInstance(\Closure $progressCallback)
 {
     $systemAddressBook = $this->getLocalSystemAddressBook();
     $this->userManager->callForAllUsers(function ($user) use($systemAddressBook, $progressCallback) {
         $this->updateUser($user);
         $progressCallback();
     });
     // remove no longer existing
     $allCards = $this->backend->getCards($systemAddressBook['id']);
     foreach ($allCards as $card) {
         $vCard = Reader::read($card['carddata']);
         $uid = $vCard->UID->getValue();
         // load backend and see if user exists
         if (!$this->userManager->userExists($uid)) {
             $this->deleteUser($card['uri']);
         }
     }
 }
 public function testSharing()
 {
     $this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
     $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
     $this->assertEquals(1, count($books));
     $this->backend->updateShares('Example', [['href' => 'principal:principals/best-friend']], []);
     $shares = $this->backend->getShares('Example');
     $this->assertEquals(1, count($shares));
     // adding the same sharee again has no effect
     $this->backend->updateShares('Example', [['href' => 'principal:principals/best-friend']], []);
     $shares = $this->backend->getShares('Example');
     $this->assertEquals(1, count($shares));
     $books = $this->backend->getAddressBooksForUser('principals/best-friend');
     $this->assertEquals(1, count($books));
     $this->backend->updateShares('Example', [], [['href' => 'principal:principals/best-friend']]);
     $shares = $this->backend->getShares('Example');
     $this->assertEquals(0, count($shares));
     $books = $this->backend->getAddressBooksForUser('principals/best-friend');
     $this->assertEquals(0, count($books));
 }
示例#13
0
 public function postLogin($params)
 {
     $user = $this->userManager->get($params['uid']);
     $principal = 'principals/users/' . $user->getUID();
     $calendars = $this->calDav->getCalendarsForUser($principal);
     if (empty($calendars)) {
         try {
             $this->calDav->createCalendar($principal, 'default', []);
         } catch (\Exception $ex) {
             \OC::$server->getLogger()->logException($ex);
         }
     }
     $books = $this->cardDav->getAddressBooksForUser($principal);
     if (empty($books)) {
         try {
             $this->cardDav->createAddressBook($principal, 'default', []);
         } catch (\Exception $ex) {
             \OC::$server->getLogger()->logException($ex);
         }
     }
 }
示例#14
0
 public function postLogin($params)
 {
     $user = $this->userManager->get($params['uid']);
     if (!is_null($user)) {
         $principal = 'principals/users/' . $user->getUID();
         $calendars = $this->calDav->getCalendarsForUser($principal);
         if (empty($calendars) || count($calendars) === 1 && $calendars[0]['uri'] === BirthdayService::BIRTHDAY_CALENDAR_URI) {
             try {
                 $this->calDav->createCalendar($principal, 'personal', ['{DAV:}displayname' => 'Personal']);
             } catch (\Exception $ex) {
                 \OC::$server->getLogger()->logException($ex);
             }
         }
         $books = $this->cardDav->getAddressBooksForUser($principal);
         if (empty($books)) {
             try {
                 $this->cardDav->createAddressBook($principal, 'contacts', ['{DAV:}displayname' => 'Contacts']);
             } catch (\Exception $ex) {
                 \OC::$server->getLogger()->logException($ex);
             }
         }
     }
 }
示例#15
0
 public function testGetContactFail()
 {
     $this->assertEmpty($this->backend->getContact('uri'));
 }