/**
  * @param $id
  * @return mixed
  */
 public function delete($id)
 {
     VCard::delete($id);
 }
Esempio n. 2
0
 public function import()
 {
     if (is_null($this->userid)) {
         throw new \Exception('No user id set');
     }
     if (!$this->isValid()) {
         return false;
     }
     $this->numofcomponents = count($this->vcardobject);
     if ($this->overwrite) {
         foreach (VCard::all($this->id) as $obj) {
             VCard::delete($obj['id']);
         }
     }
     foreach ($this->vcardobject as $object) {
         if (!$object instanceof \Sabre\VObject\Component\VCard) {
             //continue;
         }
         $vcard = \Sabre\VObject\Reader::read($object, \Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES);
         $importVCard = VCard::structureContact($vcard);
         if ($importVCard !== false) {
             $newVcard = $this->parseVCard($importVCard, $vcard);
             $insertid = VCard::add($this->id, $newVcard);
             $this->abscount++;
         } else {
             $this->errorCount++;
         }
         if ($this->isDuplicate($insertid)) {
             VCard::delete($insertid);
             $this->abscount--;
         }
         $this->updateProgress(intval($this->abscount / $this->numofcomponents * 100));
     }
     \OC::$server->getCache()->remove($this->progresskey);
     return true;
 }
Esempio n. 3
0
 /**
  * @brief removes an address book
  * @param integer $id
  * @return boolean true on success, otherwise an exception will be thrown
  */
 public static function delete($id)
 {
     $addressbook = self::find($id);
     if ($addressbook['userid'] !== \OCP\User::getUser() && !\OC_Group::inGroup(\OCP\User::getUser(), 'admin')) {
         $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $id);
         if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE)) {
             throw new \Exception(App::$l10n->t('You do not have the permissions to delete this addressbook.'));
         }
     }
     // First delete cards belonging to this addressbook.
     $cards = VCard::all($id);
     foreach ($cards as $card) {
         try {
             VCard::delete($card['id']);
         } catch (\Exception $e) {
             \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception deleting vCard ' . $card['id'] . ': ' . $e->getMessage(), \OCP\Util::ERROR);
         }
     }
     try {
         $stmt = \OCP\DB::prepare('DELETE FROM `' . App::AddrBookTable . '` WHERE `id` = ?');
         $stmt->execute(array($id));
     } catch (\Exception $e) {
         \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception for ' . $id . ': ' . $e->getMessage(), \OCP\Util::ERROR);
         throw new \Exception(App::$l10n->t('There was an error deleting this addressbook.'));
     }
     \OCP\Share::unshareAll(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $id);
     \OCP\Util::emitHook('\\OCA\\ContactsPlus', 'deleteAddressbook', $id);
     return true;
 }
Esempio n. 4
0
 /**
  * @brief removes an address book
  * @param integer $id
  * @return boolean true on success, otherwise an exception will be thrown
  */
 public static function delete($id)
 {
     $addressbook = self::find($id);
     if ($addressbook['userid'] != \OCP\User::getUser() && !\OC_Group::inGroup(OCP\User::getUser(), 'admin')) {
         $sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id);
         if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE)) {
             throw new Exception(App::$l10n->t('You do not have the permissions to delete this addressbook.'));
         }
     }
     // First delete cards belonging to this addressbook.
     $cards = VCard::all($id);
     foreach ($cards as $card) {
         try {
             VCard::delete($card['id']);
         } catch (Exception $e) {
             \OCP\Util::writeLog('contacts', __METHOD__ . ', exception deleting vCard ' . $card['id'] . ': ' . $e->getMessage(), \OCP\Util::ERROR);
         }
     }
     try {
         $stmt = \OCP\DB::prepare('DELETE FROM `*PREFIX*contacts_addressbooks` WHERE `id` = ?');
         $stmt->execute(array($id));
     } catch (\Exception $e) {
         \OCP\Util::writeLog('contacts', __METHOD__ . ', exception for ' . $id . ': ' . $e->getMessage(), \OCP\Util::ERROR);
         throw new Exception(App::$l10n->t('There was an error deleting this addressbook.'));
     }
     \OCP\Share::unshareAll('addressbook', $id);
     if (count(self::all(\OCP\User::getUser())) == 0) {
         self::addDefault();
     }
     return true;
 }
 /**
  * @param $id
  * @return mixed
  */
 public function delete($id)
 {
     try {
         $query = 'SELECT * FROM `*PREFIX*contacts_cards` WHERE `id` = ? AND `addressbookid` = ?';
         $stmt = \OCP\DB::prepare($query);
         $result = $stmt->execute(array($id, $this->id));
         if (\OC_DB::isError($result)) {
             \OC_Log::write('contacts', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
             return false;
         }
         if ($result->numRows() === 0) {
             \OC_Log::write('contacts', __METHOD__ . 'Contact with id ' . $id . 'doesn\'t belong to addressbook with id ' . $this->id, \OCP\Util::ERROR);
             return false;
         }
     } catch (\Exception $e) {
         \OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
         return false;
     }
     return VCard::delete($id);
 }