From eb9d4b98afb2622caa1677d889ad11e5be88f452 Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Thu, 30 Mar 2006 09:18:07 +0000 Subject: [PATCH] Fix decreasing comment count when tracbkack is deleted --- docs/NEWS | 3 +++ include/functions_comments.inc.php | 27 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/docs/NEWS b/docs/NEWS index 63cefb4..280e0a3 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,9 @@ Version 1.0 () ------------------------------------------------------------------------ + * Fix messing up comment count when deleting a trackback from admin + panel (garvinhicking) + * Fix missing UTF-8 encoding of date locales on Windows setups (garvinhicking) diff --git a/include/functions_comments.inc.php b/include/functions_comments.inc.php index 3003d3c..bf4d608 100644 --- a/include/functions_comments.inc.php +++ b/include/functions_comments.inc.php @@ -296,6 +296,12 @@ function serendipity_printComments($comments, $parentid = 0, $depth = 0, $trace function serendipity_deleteComment($id, $entry_id, $type='comments') { global $serendipity; + $id = (int)$id; + $entry_id = (int)$entry_id; + if ($id < 1 OR $entry_id < 1) { + return false; + } + if ($_SESSION['serendipityAuthedUser'] === true) { $admin = ''; if (!serendipity_checkPermission('adminEntriesMaintainOthers')) { @@ -304,21 +310,24 @@ function serendipity_deleteComment($id, $entry_id, $type='comments') { /* We have to figure out if the comment we are about to delete, is awaiting approval, if so - we should *not* subtract it from the entries table */ - $sql = serendipity_db_query("SELECT status, parent_id FROM {$serendipity['dbPrefix']}comments - WHERE entry_id = '". (int)$entry_id ."' - AND id = '". (int)$id ."' - $admin", true); + $sql = serendipity_db_query("SELECT type, status, parent_id FROM {$serendipity['dbPrefix']}comments + WHERE entry_id = ". $entry_id ." + AND id = ". $id , true); serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}comments - WHERE entry_id = '". (int)$entry_id ."' - AND id = '". (int)$id ."' - $admin"); + WHERE entry_id = ". $entry_id ." + AND id = ". $id ); if ($sql['status'] !== 'pending') { - serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries SET $type = $type-1 WHERE id = '". (int)$entry_id ."' $admin"); + if (!empty($sql['type']) && $sql['type'] != 'NORMAL') { + $type = 'trackbacks'; + } else { + $type = 'comments'; + } + serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries SET $type = $type-1 WHERE id = ". $entry_id); } - serendipity_db_query("UPDATE {$serendipity['dbPrefix']}comments SET parent_id = " . (int)$sql['parent_id'] . " WHERE parent_id = '" . (int)$id . "'"); + serendipity_db_query("UPDATE {$serendipity['dbPrefix']}comments SET parent_id = " . (int)$sql['parent_id'] . " WHERE parent_id = " . $id); return true; } else { -- 2.39.5