From 15e8ee3471cd0cc9ab507caa8a602d75f9f6c7ba Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 29 Sep 2020 12:46:55 +0300 Subject: [PATCH] housekeeping: add task to cleanup orphan feed icons --- classes/rssutils.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/classes/rssutils.php b/classes/rssutils.php index 6b0ae2c32..54113360a 100755 --- a/classes/rssutils.php +++ b/classes/rssutils.php @@ -29,6 +29,28 @@ class RSSUtils { $pdo->query("DELETE FROM ttrss_feedbrowser_cache"); } + static function cleanup_feed_icons() { + $pdo = Db::pdo(); + $sth = $pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ?"); + + // check icon files once every CACHE_MAX_DAYS days + $icon_files = array_filter(glob(ICONS_DIR . "/*.ico"), + function($f) { return filemtime($f) < time() - 86400*CACHE_MAX_DAYS; }); + + foreach ($icon_files as $icon) { + $feed_id = basename($icon, ".ico"); + + $sth->execute([$feed_id]); + + if ($sth->fetch()) { + @touch($icon); + } else { + Debug::log("Removing orphaned feed icon: $icon"); + unlink($icon); + } + } + } + static function update_daemon_common($limit = DAEMON_FEED_LIMIT, $options = []) { $schema_version = get_schema_version(); @@ -1564,6 +1586,7 @@ class RSSUtils { self::expire_error_log(); self::expire_feed_archive(); self::cleanup_feed_browser(); + self::cleanup_feed_icons(); Article::purge_orphans(); self::cleanup_counters_cache();