/**
	 * Delete a contact from the address book
	 *
	 * @param string $id
	 * @param array $options
	 * @return bool
	 * @throws \Exception on missing permissions
	 */
	public function deleteChild($id, $options = array()) {
		if (!$this->hasPermission(\OCP\PERMISSION_DELETE)) {
			throw new \Exception(
				self::$l10n->t('You do not have permissions to delete this contact'),
				Http::STATUS_FORBIDDEN
			);
		}

		if (!$this->getBackend()->hasContactMethodFor(\OCP\PERMISSION_DELETE)) {
			throw new \Exception(
				self::$l10n->t('The backend for this address book does not support deleting contacts'),
				Http::STATUS_NOT_IMPLEMENTED
			);
		}

		if ($this->backend->deleteContact($this->getId(), $id, $options)) {
			if (isset($this->objects[$id])) {
				unset($this->objects[$id]);
			}

			/* If count() hasn't been called yet don't _count hasn't been initialized
			* so decrementing it would give a misleading value.
			*/
			if (isset($this->_count)) {
				$this->_count -= 1;
			}

			return true;
		}

		return false;
	}
Exemple #2
0
 public function testDeleteContact()
 {
     $this->assertTrue($this->backend->deleteContact('foo', '123'));
     $this->assertEquals(array(), $this->backend->getContacts('foo'));
 }