Author: Derick Rethans (derickr) Date: 2024-08-27T00:50:23+01:00 Commit: https://github.com/php/web-master/commit/c735002be0d25d5c420ba49aa173da2043e83282 Raw diff: https://github.com/php/web-master/commit/c735002be0d25d5c420ba49aa173da2043e83282.diff
Merge branch 'pr/25' 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..5ece697 --- /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 < ? 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"; + +$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 < ? 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");