purge_feed: add more debugging output

This commit is contained in:
Andrew Dolgov 2020-12-15 08:50:01 +03:00
parent 9b7338e807
commit f05f9b4252
1 changed files with 50 additions and 48 deletions

View File

@ -2104,12 +2104,10 @@ class Feeds extends Handler_Protected {
/**
* Purge a feed old posts.
*
* @param mixed $link A database connection.
* @param mixed $feed_id The id of the purged feed.
* @param mixed $purge_interval Olderness of purged posts.
* @param boolean $debug Set to True to enable the debug. False by default.
* @access public
* @return void
* @return mixed
*/
static function purge_feed($feed_id, $purge_interval) {
@ -2117,27 +2115,30 @@ class Feeds extends Handler_Protected {
$pdo = Db::pdo();
$owner_uid = false;
$rows_deleted = 0;
$sth = $pdo->prepare("SELECT owner_uid FROM ttrss_feeds WHERE id = ?");
$sth->execute([$feed_id]);
$owner_uid = false;
if ($row = $sth->fetch()) {
$owner_uid = $row["owner_uid"];
}
if ($purge_interval == -1 || !$purge_interval) {
return;
}
if (!$owner_uid) return;
if (FORCE_ARTICLE_PURGE == 0) {
$purge_unread = get_pref("PURGE_UNREAD_ARTICLES",
$owner_uid, false);
} else {
if (FORCE_ARTICLE_PURGE != 0) {
Debug::log("purge_feed: FORCE_ARTICLE_PURGE is set, overriding interval to " . FORCE_ARTICLE_PURGE);
$purge_unread = true;
$purge_interval = FORCE_ARTICLE_PURGE;
} else {
$purge_unread = get_pref("PURGE_UNREAD_ARTICLES", $owner_uid, false);
}
$purge_interval = (int) $purge_interval;
Debug::log("purge_feed: interval $purge_interval days for feed $feed_id, owner: $owner_uid, purge unread: $purge_unread");
if ($purge_interval <= 0) {
Debug::log("purge_feed: purging disabled for this feed, nothing to do.");
return;
}
if (!$purge_unread)
@ -2145,8 +2146,6 @@ class Feeds extends Handler_Protected {
else
$query_limit = "";
$purge_interval = (int) $purge_interval;
if (DB_TYPE == "pgsql") {
$sth = $pdo->prepare("DELETE FROM ttrss_user_entries
USING ttrss_entries
@ -2169,11 +2168,15 @@ class Feeds extends Handler_Protected {
}
$rows = $sth->rowCount();
$rows_deleted = $sth->rowCount();
Debug::log("Purged feed $feed_id ($purge_interval): deleted $rows articles");
Debug::log("purge_feed: processed $feed_id: deleted $rows_deleted articles");
return $rows;
} else {
Debug::log("purge_feed: owner of $feed_id not found");
}
return $rows_deleted;
}
static function feed_purge_interval($feed_id) {
@ -2188,11 +2191,10 @@ class Feeds extends Handler_Protected {
$purge_interval = $row["purge_interval"];
$owner_uid = $row["owner_uid"];
if ($purge_interval == 0) $purge_interval = get_pref(
'PURGE_OLD_DAYS', $owner_uid);
if ($purge_interval == 0)
$purge_interval = get_pref('PURGE_OLD_DAYS', $owner_uid, false);
return $purge_interval;
} else {
return -1;
}