1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-03 15:24:09 +01:00

Contacts: Use own delete() method in deleteFromDAVData()

This commit is contained in:
Thomas Tanghus 2012-11-26 20:38:59 +01:00
parent 0b27c3a82c
commit e7ab74053f

View File

@ -628,39 +628,40 @@ class VCard {
* @return boolean * @return boolean
*/ */
public static function deleteFromDAVData($aid, $uri) { public static function deleteFromDAVData($aid, $uri) {
$id = null; $contact = self::findWhereDAVDataIs($aid, $uri);
$addressbook = Addressbook::find($aid); if(!$contact) {
if ($addressbook['userid'] != \OCP\User::getUser()) { \OCP\Util::writeLog('contacts', __METHOD__.', couldn\'t find contact'
$query = \OCP\DB::prepare( 'SELECT `id` FROM `*PREFIX*contacts_cards` WHERE `addressbookid` = ? AND `uri` = ?' ); . $uri, \OCP\Util::DEBUG);
$id = $query->execute(array($aid, $uri))->fetchOne(); throw new \Sabre_DAV_Exception_NotFound(
if (!$id) { App::$l10n->t(
return false; 'Contact not found.'
)
);
} }
$id = $contact['id'];
$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 { try {
$stmt->execute(array($aid,$uri)); return self::delete($id);
} catch(\Exception $e) { } catch (Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__.', exception: '.$e->getMessage(), \OCP\Util::ERROR); switch($e->getCode()) {
\OCP\Util::writeLog('contacts', __METHOD__.', aid: '.$aid.' uri: '.$uri, \OCP\Util::DEBUG); case 403:
return false; throw new \Sabre_DAV_Exception_Forbidden(
App::$l10n->t(
$e->getMessage()
)
);
break;
case 404:
throw new \Sabre_DAV_Exception_NotFound(
App::$l10n->t(
$e->getMessage()
)
);
break;
default:
throw $e;
break;
} }
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; return true;
} }