예제 #1
0
 /**
  * @brief deletes a card
  * @param integer $id id of card
  * @return boolean true on success, otherwise an exception will be thrown
  */
 public static function delete($id)
 {
     $contact = self::find($id);
     if (!$contact) {
         \OCP\Util::writeLog('contacts', __METHOD__ . ', id: ' . $id . ' not found.', \OCP\Util::DEBUG);
         throw new \Exception(App::$l10n->t('Could not find the vCard with ID: ' . $id, 404));
     }
     $addressbook = Addressbook::find($contact['addressbookid']);
     if (!$addressbook) {
         throw new \Exception(App::$l10n->t('Could not find the Addressbook with ID: ' . $contact['addressbookid'], 404));
     }
     if ($addressbook['userid'] != \OCP\User::getUser() && !\OC_Group::inGroup(\OCP\User::getUser(), 'admin')) {
         \OCP\Util::writeLog('contacts', __METHOD__ . ', ' . $addressbook['userid'] . ' != ' . \OCP\User::getUser(), \OCP\Util::DEBUG);
         $sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $contact['addressbookid'], \OCP\Share::FORMAT_NONE, null, true);
         $sharedContact = \OCP\Share::getItemSharedWithBySource('contact', $id, \OCP\Share::FORMAT_NONE, null, true);
         $addressbook_permissions = 0;
         $contact_permissions = 0;
         if ($sharedAddressbook) {
             $addressbook_permissions = $sharedAddressbook['permissions'];
         }
         if ($sharedContact) {
             $contact_permissions = $sharedEvent['permissions'];
         }
         $permissions = max($addressbook_permissions, $contact_permissions);
         if (!($permissions & \OCP\PERMISSION_DELETE)) {
             throw new \Exception(App::$l10n->t('You do not have the permissions to delete this contact.', 403));
         }
     }
     $aid = $contact['addressbookid'];
     \OC_Hook::emit('\\OCA\\Contacts\\VCard', 'pre_deleteVCard', array('aid' => null, 'id' => $id, 'uri' => null));
     $stmt = \OCP\DB::prepare('DELETE FROM `*PREFIX*contacts_cards` WHERE `id` = ?');
     try {
         $stmt->execute(array($id));
     } catch (\Exception $e) {
         \OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
         \OCP\Util::writeLog('contacts', __METHOD__ . ', id: ' . $id, \OCP\Util::DEBUG);
         throw new \Exception(App::$l10n->t('There was an error deleting this contact.'));
     }
     App::updateDBProperties($id);
     App::getVCategories()->purgeObject($id);
     Addressbook::touch($addressbook['id']);
     \OCP\Share::unshareAll('contact', $id);
     return true;
 }
예제 #2
0
파일: vcard.php 프로젝트: noldmess/apps
 /**
  * @brief deletes a card with the data provided by sabredav
  * @param integer $aid Addressbook id
  * @param string $uri the uri of the card
  * @return boolean
  */
 public static function deleteFromDAVData($aid, $uri)
 {
     $id = null;
     $addressbook = Addressbook::find($aid);
     if ($addressbook['userid'] != \OCP\User::getUser()) {
         $query = \OCP\DB::prepare('SELECT `id` FROM `*PREFIX*contacts_cards` WHERE `addressbookid` = ? AND `uri` = ?');
         $id = $query->execute(array($aid, $uri))->fetchOne();
         if (!$id) {
             return false;
         }
         $sharedContact = \OCP\Share::getItemSharedWithBySource('contact', $id, \OCP\Share::FORMAT_NONE, null, true);
         if (!$sharedContact || !($sharedContact['permissions'] & \OCP\PERMISSION_DELETE)) {
             return false;
         }
     }
     \OC_Hook::emit('\\OCA\\Contacts\\VCard', 'pre_deleteVCard', array('aid' => $aid, 'id' => null, 'uri' => $uri));
     $stmt = \OCP\DB::prepare('DELETE FROM `*PREFIX*contacts_cards` WHERE `addressbookid` = ? AND `uri`=?');
     try {
         $stmt->execute(array($aid, $uri));
     } catch (\Exception $e) {
         \OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
         \OCP\Util::writeLog('contacts', __METHOD__ . ', aid: ' . $aid . ' uri: ' . $uri, \OCP\Util::DEBUG);
         return false;
     }
     Addressbook::touch($aid);
     if (!is_null($id)) {
         App::getVCategories()->purgeObject($id);
         App::updateDBProperties($id);
         \OCP\Share::unshareAll('contact', $id);
     } else {
         \OCP\Util::writeLog('contacts', __METHOD__ . ', Could not find id for ' . $uri, \OCP\Util::DEBUG);
     }
     return true;
 }