/** * Add a contact to the address book * This takes an array or a VCard|Contact and return * the ID or false. * * @param array|VObject\VCard $data * @return int|bool * @throws \Exception on missing permissions */ public function addChild($data = null) { if (!$this->hasPermission(\OCP\PERMISSION_CREATE)) { throw new \Exception(self::$l10n->t('You do not have permissions add contacts to the address book'), Http::STATUS_FORBIDDEN); } if (!$this->getBackend()->hasContactMethodFor(\OCP\PERMISSION_CREATE)) { throw new \Exception(self::$l10n->t('The backend for this address book does not support adding contacts'), Http::STATUS_NOT_IMPLEMENTED); } $contact = new Contact($this, $this->backend, $data); if (is_null($data)) { // A new Contact, don't try to load from backend $contact->setRetrieved(true); } if ($contact->save() === false) { return false; } $id = $contact->getId(); // If this method is called directly the index isn't set. if (!isset($this->objects[$id])) { $this->objects[$id] = $contact; } /* If count() hasn't been called yet don't _count hasn't been initialized * so incrementing it would give a misleading value. */ if (isset($this->_count)) { $this->_count += 1; } //\OCP\Util::writeLog('contacts', __METHOD__.' id: ' . $id, \OCP\Util::DEBUG); return $id; }
public function testSave() { $this->contact->FN = 'Don Quixote'; $this->assertTrue($this->contact->save()); $this->assertTrue($this->contact->isSaved()); }