changeset 1032:9fffc9e7e1b6

Add stDeleteCompoEntry() and use it.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 19 Nov 2015 21:57:19 +0200
parents bada991641ba
children ed22a3a3027f
files admajax.php msite.inc.php
diffstat 2 files changed, 19 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/admajax.php	Thu Nov 19 21:08:40 2015 +0200
+++ b/admajax.php	Thu Nov 19 21:57:19 2015 +0200
@@ -1663,32 +1663,14 @@
       else
       if ($type == "entries")
       {
-        // .. as do compo entries
-        $sql = stPrepareSQL("DELETE FROM entries WHERE id=%d", $id);
-        stExecSQLCond($sql, "OK, entry ".$id." deleted.");
-
-        $sql = stPrepareSQL("DELETE FROM votes WHERE entry_id=%d", $id);
-        stExecSQLCond($sql, "OK, entry ".$id." votes deleted.");
-        
-        // Mark files to be deleted
-        $sql = stPrepareSQL("UPDATE files SET deleted=%d WHERE entry_id=%d", 1, $id);
-        stExecSQLCond($sql, "OK, entry ".$id." files marked.");
+        stDeleteCompoEntry($id);
       }
       else
       if ($type == "compo")
       {
-        // Delete votes for compo entry
+        // Delete entries for the compo
         foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$id) as $sentry)
-        {
-          stExecSQLCond(
-            "DELETE FROM votes WHERE entry_id=".$sentry["id"],
-            "OK, entry ".$sentry["id"]." votes deleted.");
-        }
-
-        // Delete entries for the compo
-        stExecSQLCond(
-          "DELETE FROM entries WHERE compo_id=".$id,
-          "OK, compo entries for compo ".$id." deleted.");
+          stDeleteCompoEntry($sentry["id"]);
 
         // Delete the compo itself
         stExecSQLCond(
--- a/msite.inc.php	Thu Nov 19 21:08:40 2015 +0200
+++ b/msite.inc.php	Thu Nov 19 21:57:19 2015 +0200
@@ -1345,4 +1345,20 @@
 }
 
 
+function stDeleteCompoEntry($id)
+{
+  // Delete entry itself
+  $sql = stPrepareSQL("DELETE FROM entries WHERE id=%d", $id);
+  stExecSQLCond($sql, "OK, entry ".$id." deleted.");
+
+  // Delete votes for the entry
+  $sql = stPrepareSQL("DELETE FROM votes WHERE entry_id=%d", $id);
+  stExecSQLCond($sql, "OK, entry ".$id." votes deleted.");
+  
+  // Mark related files to be deleted
+  $sql = stPrepareSQL("UPDATE files SET deleted=%d WHERE entry_id=%d", 1, $id);
+  stExecSQLCond($sql, "OK, entry ".$id." files marked.");
+}
+
+
 ?>
\ No newline at end of file