mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-05-14 10:13:52 -04:00
- Adds `cli/purge.php` so the purge policy can be applied from cron, mirroring `cli/db-optimize.php`. - Documents it in `cli/README.md`. Aims to be a small, contained answer to #3636: reuses the same `Feed::cleanOldEntries()` logic the GUI's "Purge now" button calls, packaged as a standard `cli/` script. Mirror the existing db-optimize.php pattern so administrators can run the purge policy on a schedule instead of waiting for the 1/30 random trigger in feedController, or clicking 'Purge now' in the GUI. The script applies the same archiving policy as the GUI button: per-feed attribute, per-category attribute, then user config; with the existing keep_favourites / keep_unreads / keep_labels / keep_min / keep_period / keep_max guards. With no policy configured, it is a no-op. Refs: https://github.com/FreshRSS/FreshRSS/issues/3636 Co-authored-by: Bjørn A. Andersen <polybjorn@users.noreply.github.com>
44 lines
1.0 KiB
PHP
Executable File
44 lines
1.0 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
declare(strict_types=1);
|
|
require __DIR__ . '/_cli.php';
|
|
|
|
performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? '');
|
|
|
|
$cliOptions = new class extends CliOptionsParser {
|
|
public string $user;
|
|
|
|
public function __construct() {
|
|
$this->addRequiredOption('user', (new CliOption('user')));
|
|
parent::__construct();
|
|
}
|
|
};
|
|
|
|
if (!empty($cliOptions->errors)) {
|
|
fail('FreshRSS error: ' . array_shift($cliOptions->errors) . "\n" . $cliOptions->usage);
|
|
}
|
|
|
|
$username = cliInitUser($cliOptions->user);
|
|
|
|
echo 'FreshRSS purging old entries for user “', $username, "”…\n";
|
|
|
|
$databaseDAO = FreshRSS_Factory::createDatabaseDAO();
|
|
$databaseDAO->minorDbMaintenance();
|
|
|
|
$feedDAO = FreshRSS_Factory::createFeedDao();
|
|
$feeds = $feedDAO->listFeeds();
|
|
|
|
$nb_total = 0;
|
|
$feedDAO->beginTransaction();
|
|
foreach ($feeds as $feed) {
|
|
$nb_total += ($feed->cleanOldEntries() ?: 0);
|
|
}
|
|
$feedDAO->updateCachedValues();
|
|
$feedDAO->commit();
|
|
|
|
invalidateHttpCache($username);
|
|
|
|
echo "FreshRSS purged {$nb_total} old entries for {$username}\n";
|
|
|
|
done(true);
|