From da3c422d65973bde257aea24bf05fc55e5e7e63e Mon Sep 17 00:00:00 2001 From: cweiske Date: Sun, 25 Oct 2009 15:24:35 +0000 Subject: [PATCH] delete votes when deleting bookmark git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@408 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 44 +++++++++++++++++++----- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 9cf5c70..3e5e79f 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -613,27 +613,53 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService - public function deleteBookmark($bookmarkid) + /** + * Delete the bookmark with the given id. + * Also deletes tags and votes for the given bookmark. + * + * @param integer $bookmark Bookmark ID + * + * @return boolean True if all went well, false if not + */ + public function deleteBookmark($bookmark) { - $query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'bookmarks WHERE bId = '. intval($bookmarkid); + $bookmark = (int)$bookmark; + + $query = 'DELETE FROM ' . $GLOBALS['tableprefix'] . 'bookmarks WHERE bId = '. $bookmark; $this->db->sql_transaction('begin'); - if (!($dbresult = & $this->db->sql_query($query))) { + if (!($dbres = $this->db->sql_query($query))) { $this->db->sql_transaction('rollback'); - message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db); + message_die( + GENERAL_ERROR, 'Could not delete bookmark', + '', __LINE__, __FILE__, $query, $this->db + ); return false; } - - - $query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'bookmarks2tags WHERE bId = '. intval($bookmarkid); + $query = 'DELETE FROM ' . $GLOBALS['tableprefix'] . 'bookmarks2tags WHERE bId = '. $bookmark; $this->db->sql_transaction('begin'); - if (!($dbresult = & $this->db->sql_query($query))) { + if (!($dbres = $this->db->sql_query($query))) { $this->db->sql_transaction('rollback'); - message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db); + message_die( + GENERAL_ERROR, 'Could not delete tags for bookmark', + '', __LINE__, __FILE__, $query, $this->db + ); + return false; + } + + $query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'votes WHERE bid = '. $bookmark; + $this->db->sql_transaction('begin'); + if (!($dbres = $this->db->sql_query($query))) { + $this->db->sql_transaction('rollback'); + message_die( + GENERAL_ERROR, 'Could not delete votes for bookmark', + '', __LINE__, __FILE__, $query, $this->db + ); return false; } $this->db->sql_transaction('commit'); + return true; }