Author: Derick Rethans (derickr) Date: 2024-08-27T00:45:41+01:00 Commit: https://github.com/php/web-master/commit/ca918e8bb2be71ab95dbb049b67bd3a78731d5ec Raw diff: https://github.com/php/web-master/commit/ca918e8bb2be71ab95dbb049b67bd3a78731d5ec.diff
Parameterise query Changed paths: M scripts/remove-low-rated-notes Diff: diff --git a/scripts/remove-low-rated-notes b/scripts/remove-low-rated-notes index 541fddb..5ece697 100755 --- a/scripts/remove-low-rated-notes +++ b/scripts/remove-low-rated-notes @@ -16,8 +16,8 @@ $total = $pdo->single($query); /** --[ the lowest rated notes ]------------------- **/ $date = date('Y-m-d', strtotime(AGE_THRESHOLD . ' ago')); -$query = "SELECT sect, note.ts, note_id, SUM(if (vote = 0, -1, 1)) AS weight FROM note, votes WHERE note.ts < '{$date}' AND note.id = votes.note_id GROUP by note_id HAVING weight < " . RATING_THRESHOLD . " ORDER BY weight"; -$result = $pdo->safeQuery($query); +$query = "SELECT sect, note.ts, note_id, SUM(if (vote = 0, -1, 1)) AS weight FROM note, votes WHERE note.ts < ? AND note.id = votes.note_id GROUP by note_id HAVING weight < ? ORDER BY weight"; +$result = $pdo->safeQuery($query, [ $date, RATING_THRESHOLD ] ); $table = "Rating | Note\n" . "-------+---------------------------------------------------------\n"; @@ -32,7 +32,7 @@ $body = "Following were the {$count} notes with a rating less than " . RATING_TH . sprintf("These notes represented %.1f%% of the %d total user notes,\nand have now been removed.\n\n", ($count / $total) * 100, $total) . $table; -$query = "DELETE FROM note WHERE id IN (SELECT note.id FROM note, votes WHERE note.ts < '{$date}' AND note.id = votes.note_id GROUP BY note_id HAVING SUM(if (vote = 0, -1, 1)) < " . RATING_THRESHOLD . ")"; -$result = $pdo->safeQuery($query); +$query = "DELETE FROM note WHERE id IN (SELECT note.id FROM note, votes WHERE note.ts < ? AND note.id = votes.note_id GROUP BY note_id HAVING SUM(if (vote = 0, -1, 1)) < ?)"; +$result = $pdo->safeQuery($query, [ $date, RATING_THRESHOLD ]); mail("php...@lists.php.net, php-no...@lists.php.net", "Deleted $count old and low rated notes", $body, "From: nore...@php.net", "-fnore...@php.net");