* License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ // Init owncloud require_once '../../../lib/base.php'; $id = $_GET['id']; $l10n = new OC_L10N('contacts'); // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); $card = OC_Contacts_VCard::find($id); if ($card === false) { OC_JSON::error(array('data' => array('message' => $l10n->t('Contact could not be found.')))); exit; } $addressbook = OC_Contacts_Addressbook::find($card['addressbookid']); if ($addressbook === false || $addressbook['userid'] != OC_USER::getUser()) { OC_JSON::error(array('data' => array('message' => $l10n->t('This is not your contact.')))); exit; } OC_Contacts_VCard::delete($id); OC_JSON::success(array('data' => array('id' => $id)));
/** * @brief removes an address book * @param integer $id * @return boolean */ public static function delete($id) { // FIXME: There's no error checking at all. self::setActive($id, false); $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?'); $stmt->execute(array($id)); $cards = OC_Contacts_VCard::all($id); foreach ($cards as $card) { OC_Contacts_VCard::delete($card['id']); } return true; }
/** * @brief removes an address book * @param integer $id * @return boolean */ public static function delete($id) { $stmt = OC_DB::prepare('DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?'); $stmt->execute(array($id)); $cards = OC_Contacts_VCard::all($id); foreach ($cards as $card) { OC_Contacts_VCard::delete($card['id']); } return true; }
/** * @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()) { $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $id); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_DELETE)) { throw new Exception(OC_Contacts_App::$l10n->t('You do not have the permissions to delete this addressbook.')); } } // First delete cards belonging to this addressbook. $cards = OC_Contacts_VCard::all($id); foreach ($cards as $card) { try { OC_Contacts_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(OC_Contacts_App::$l10n->t('There was an error deleting this addressbook.')); } // TODO: Unshare all when that method is created //OCP\Share::unshare('addressbook', $id); if (count(self::all(OCP\User::getUser())) == 0) { self::addDefault(); } return true; }