[web-master] remote-low-quality-notes: Parameterise query

From: Date: Mon, 26 Aug 2024 23:46:51 +0000
Subject: [web-master] remote-low-quality-notes: Parameterise query
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-32021@lists.php.net to get a copy of this message
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("phpdoc@lists.php.net, php-notes@lists.php.net", "Deleted $count old and low rated notes", $body, "From: noreply@php.net", "-fnoreply@php.net");

« previous php.webmaster (#32021) next »