/** * @brief Get a unique name of the item for the specified user * @param string Item * @param string|false User the item is being shared with * @param array|null List of similar item names already existing as shared items * @return string Target name * * This function needs to verify that the user does not already have an item with this name. * If it does generate a new name e.g. name_# */ public function generateTarget($itemSource, $shareWith, $exclude = null) { // Get app for the sharee $app = new App($shareWith); $backend = $app->getBackend('local'); // Get address book for the owner $addressBook = $this->app->getBackend('local')->getAddressBook($itemSource); $userAddressBooks = array(); foreach ($backend->getAddressBooksForUser() as $userAddressBook) { $userAddressBooks[] = $userAddressBook['displayname']; } $name = $addressBook['displayname'] . '(' . $addressBook['owner'] . ')'; $suffix = ''; while (in_array($name . $suffix, $userAddressBooks)) { $suffix++; } $suffix = $suffix ? ' ' . $suffix : ''; return $name . $suffix; }
/** * Get the backend for an address book * * @param mixed $addressbookid * @return array(string, \OCA\Contacts\Backend\AbstractBackend) */ public function getBackendForAddressBook($addressbookid) { list($backendName, $id) = explode('::', $addressbookid); $app = new Contacts\App(); $backend = $app->getBackend($backendName); if ($backend->name === $backendName && $backend->hasAddressBook($id)) { return array($id, $backend); } throw new \Sabre\DAV\Exception\NotFound('Backend not found: ' . $addressbookid); }
/** * Scan vCards for properties. */ public static function indexProperties() { $offset = 0; $limit = 10; $app = new App(); $backend = $app->getBackend('local'); $addressBookInfos = $backend->getAddressBooksForUser(); foreach ($addressBookInfos as $addressBookInfo) { $addressBook = new AddressBook($backend, $addressBookInfo); $contacts = $addressBook->getChildren($limit, $offset, false); \OCP\Util::writeLog('contacts', __METHOD__ . ', indexing: ' . $limit . ' starting from ' . $offset, \OCP\Util::DEBUG); foreach ($contacts as $contact) { if (!$contact->retrieve()) { \OCP\Util::writeLog('contacts', __METHOD__ . ', Error loading contact ' . print_r($contact, true), \OCP\Util::DEBUG); } Utils\Properties::updateIndex($contact->getId(), $contact); } $offset += $limit; } $stmt = \OCP\DB::prepare('DELETE FROM `*PREFIX*contacts_cards_properties` WHERE NOT EXISTS(SELECT NULL FROM `*PREFIX*contacts_cards` WHERE `*PREFIX*contacts_cards`.id = `*PREFIX*contacts_cards_properties`.contactid)'); $result = $stmt->execute(array()); }
/** * Scan vCards for properties. */ public static function indexProperties() { $offset = 0; $limit = 10; $app = new App(); $backend = $app->getBackend('local'); $addressBookInfos = $backend->getAddressBooksForUser(); foreach ($addressBookInfos as $addressBookInfo) { $addressBook = new AddressBook($backend, $addressBookInfo); while ($contacts = $addressBook->getChildren($limit, $offset, false)) { foreach ($contacts as $contact) { $contact->retrieve(); } \OCP\Util::writeLog('contacts', __CLASS__ . '::' . __METHOD__ . ', indexing: ' . $limit . ' starting from ' . $offset, \OCP\Util::DEBUG); Utils\Properties::updateIndex($contact->getId(), $contact); $offset += $limit; } } }