# HG changeset patch # User Matti Hamalainen # Date 1447963039 -7200 # Node ID 9fffc9e7e1b683c9fd4ae7222ba53a00e9d4eed4 # Parent bada991641bac880c31a307f45e1fc0f20b0c071 Add stDeleteCompoEntry() and use it. diff -r bada991641ba -r 9fffc9e7e1b6 admajax.php --- 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( diff -r bada991641ba -r 9fffc9e7e1b6 msite.inc.php --- 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