]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
delete votes when deleting bookmark
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Sun, 25 Oct 2009 15:24:35 +0000 (15:24 +0000)
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Sun, 25 Oct 2009 15:24:35 +0000 (15:24 +0000)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@408 b3834d28-1941-0410-a4f8-b48e95affb8f

src/SemanticScuttle/Service/Bookmark.php

index 9cf5c702dac5ef4bd2d80de471cc0d9eb8f87044..3e5e79fa46a40783d703238de6523b28a1a5fbb2 100644 (file)
@@ -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 = '. $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 tags for bookmark',
+                '', __LINE__, __FILE__, $query, $this->db
+            );
+            return false;
+        }
 
-
-        $query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'bookmarks2tags WHERE bId = '. intval($bookmarkid);
+        $query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'votes 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 votes for bookmark',
+                '', __LINE__, __FILE__, $query, $this->db
+            );
             return false;
         }
 
         $this->db->sql_transaction('commit');
+
         return true;
     }