public function setUp() { parent::setUp(); $this->testUser = $this->getUniqueID('user_'); // needed because some parts of code call "getRequest()" and "getSession()" $session = $this->getMockBuilder('\\OC\\Session\\Memory')->disableOriginalConstructor()->getMock(); $session->expects($this->any())->method('get')->with('user_id')->will($this->returnValue($this->testUser)); $userObject = $this->getMock('\\OCP\\IUser'); $userObject->expects($this->any())->method('getUId')->will($this->returnValue($this->testUser)); $userSession = $this->getMockBuilder('\\OC\\User\\Session')->disableOriginalConstructor()->getMock(); $userSession->expects($this->any())->method('getUser')->will($this->returnValue($userObject)); $userSession->expects($this->any())->method('getSession')->will($this->returnValue($session)); \OC::$server->registerService('UserSession', function (\OCP\IServerContainer $c) use($userSession) { return $userSession; }); $this->backend = new Backend\Database($this->testUser); $this->abinfo = array('displayname' => uniqid('display_')); $this->ab = new AddressBook($this->backend, $this->abinfo); $this->provider = new AddressbookProvider($this->ab); $card = new \OCA\Contacts\VObject\VCard(); $uid = substr(md5($this->getUniqueID()), 0, 10); $card->add('UID', $uid); $card->add('FN', 'Max Mustermann'); $id = $this->ab->addChild($card); Utils\Properties::updateIndex($id, $card); $this->contactIds[] = $id; // Add extra contact $card = new \OCA\Contacts\VObject\VCard(); $uid = substr(md5(rand() . time()), 0, 10); $card->add('UID', $uid); $card->add('FN', 'Jan Janssens'); $id = $this->ab->addChild($card); Utils\Properties::updateIndex($id, $card); $this->contactIds[] = $id; }
/** * 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; } } }