From fefa6ca3afec86c405b8df13386ed0cc43668a0a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 18 Nov 2005 13:21:16 +0100 Subject: [PATCH] globalPurge rpc call --- backend.php | 10 ++++++++- functions.php | 57 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/backend.php b/backend.php index f7318ff4..a2f6a0da 100644 --- a/backend.php +++ b/backend.php @@ -398,6 +398,15 @@ print ""; } + + if ($subop == "globalPurge") { + + print ""; + global_purge_old_posts($link, true); + print ""; + + } + } if ($op == "feeds") { @@ -2023,7 +2032,6 @@ } - db_close($link); ?> diff --git a/functions.php b/functions.php index 730b1fed..355226e8 100644 --- a/functions.php +++ b/functions.php @@ -9,6 +9,52 @@ define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); + function purge_feed($link, $feed_id, $purge_interval) { + + if (DB_TYPE == "pgsql") { + db_query($link, "DELETE FROM ttrss_entries WHERE + marked = false AND feed_id = '$feed_id' AND + date_entered < NOW() - INTERVAL '$purge_interval days'"); + } else { + db_query($link, "DELETE FROM ttrss_entries WHERE + marked = false AND feed_id = '$feed_id' AND + date_entered < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); + } + } + + function global_purge_old_posts($link, $do_output = false) { + + $result = db_query($link, + "SELECT id,purge_interval,owner_uid FROM ttrss_feeds"); + + while ($line = db_fetch_assoc($result)) { + + $feed_id = $line["id"]; + $purge_interval = $line["purge_interval"]; + $owner_uid = $line["owner_uid"]; + + if ($purge_interval == 0) { + + $tmp_result = db_query($link, + "SELECT value FROM ttrss_user_prefs WHERE + pref_name = 'PURGE_OLD_DAYS' AND owner_uid = '$owner_uid'"); + + if (db_num_rows($tmp_result) != 0) { + $purge_interval = db_fetch_result($tmp_result, 0, "value"); + } + } + + if ($do_output) { + print ""; + } + + if ($purge_interval > 0) { + purge_feed($link, $feed_id, $purge_interval); + } + } + + } + function purge_old_posts($link) { $user_id = $_SESSION["uid"]; @@ -24,16 +70,7 @@ if ($purge_interval == 0) $purge_interval = get_pref($link, 'PURGE_OLD_DAYS'); if ($purge_interval > 0) { - - if (DB_TYPE == "pgsql") { - db_query($link, "DELETE FROM ttrss_entries WHERE - marked = false AND feed_id = '$feed_id' AND - date_entered < NOW() - INTERVAL '$purge_interval days'"); - } else { - db_query($link, "DELETE FROM ttrss_entries WHERE - marked = false AND feed_id = '$feed_id' AND - date_entered < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); - } + purge_feed($link, $feed_id, $purge_interval); } } } -- 2.39.5