Author: Derick Rethans (derickr) Date: 2024-08-27T00:41:38+01:00 Commit: https://github.com/php/web-master/commit/b982e83e2cb2d2ea972ba96c7e6131b62d1b994d Raw diff: https://github.com/php/web-master/commit/b982e83e2cb2d2ea972ba96c7e6131b62d1b994d.diff
Add script to remove low rated notes Changed paths: A scripts/remove-low-rated-notes Diff: diff --git a/scripts/remove-low-rated-notes b/scripts/remove-low-rated-notes new file mode 100755 index 0000000..541fddb --- /dev/null +++ b/scripts/remove-low-rated-notes @@ -0,0 +1,38 @@ +#!/usr/local/bin/php -q +<?php + +use App\DB; + +require_once __DIR__ . '/../vendor/autoload.php'; + +define('RATING_THRESHOLD', "-5"); +define('AGE_THRESHOLD', '1 year'); + +$pdo = DB::connect(); + +$query = "SELECT COUNT(*) FROM note"; +$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); + +$table = "Rating | Note\n" + . "-------+---------------------------------------------------------\n"; + +$count = 0; +foreach ($result as $row) { + $table .= sprintf("%5d | https://php.net/manual/en/%s.php#%s\n", $row['weight'], $row['sect'], $row['note_id']); + $count++; +} + +$body = "Following were the {$count} notes with a rating less than " . RATING_THRESHOLD . " and\nare older than " . AGE_THRESHOLD. ".\n\n" + . 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); + +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");