Esempio n. 1
0
	/**
	* Returns a specific child node, referenced by its id
	*
	* @param string $id
	* @return Contact|null
	* @throws \Exception On not found
	*/
	public function getChild($id) {
		//\OCP\Util::writeLog('contacts', __METHOD__.' id: '.$id, \OCP\Util::DEBUG);
		if (!$this->hasPermission(\OCP\PERMISSION_READ)) {
			throw new \Exception(
				self::$l10n->t('You do not have permissions to see this contact'),
				Http::STATUS_FORBIDDEN
			);
		}

		if (!isset($this->objects[(string)$id])) {
			$contact = $this->backend->getContact($this->getId(), $id);
			if ($contact) {
				$this->objects[(string)$id] = new Contact($this, $this->backend, $contact);
			} else {
				throw new \Exception(
					self::$l10n->t('Contact not found'),
					Http::STATUS_NOT_FOUND
				);
			}
		}

		// When requesting a single contact we preparse it
		if (isset($this->objects[(string)$id])) {
			$this->objects[(string)$id]->retrieve();
			return $this->objects[(string)$id];
		}
	}
Esempio n. 2
0
 public function testUpdateContact()
 {
     $carddata = file_get_contents(__DIR__ . '/../../data/test2.vcf');
     $vcard = Reader::read($carddata);
     $this->assertInstanceOf('OCA\\Contacts\\VObject\\VCard', $vcard);
     $this->assertTrue($this->backend->updateContact('foo', '123', $vcard));
     $contact = $this->backend->getContact('foo', '123');
     $this->assertEquals('John Q. Public', $contact['displayname']);
 }