From 8bc799ff387cd4a499620b3d7c3d7b589755f991 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 30 Nov 2020 20:32:56 +0000 Subject: [PATCH 1/2] Issue 8943: Only check for too old postings for feeds --- src/Model/Item.php | 53 ++++++++++++++++++++++++++----------------- src/Protocol/Feed.php | 5 +++- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 59928fd641..35faa40756 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1382,27 +1382,6 @@ class Item return false; } - // check for create date and expire time - $expire_interval = DI::config()->get('system', 'dbclean-expire-days', 0); - - $user = DBA::selectFirst('user', ['expire'], ['uid' => $item['uid']]); - if (DBA::isResult($user) && ($user['expire'] > 0) && (($user['expire'] < $expire_interval) || ($expire_interval == 0))) { - $expire_interval = $user['expire']; - } - - if (($expire_interval > 0) && !empty($item['created'])) { - $expire_date = time() - ($expire_interval * 86400); - $created_date = strtotime($item['created']); - if ($created_date < $expire_date) { - Logger::notice('Item created before expiration interval.', [ - 'created' => date('c', $created_date), - 'expired' => date('c', $expire_date), - '$item' => $item - ]); - return false; - } - } - if (!empty($item['author-id']) && Contact::isBlocked($item['author-id'])) { Logger::notice('Author is blocked node-wide', ['author-link' => $item['author-link'], 'item-uri' => $item['uri']]); return false; @@ -1446,6 +1425,38 @@ class Item return true; } + /** + * Check if the item array is too old + * + * @param array $item + * @return boolean item is too old + */ + public static function tooOld(array $item) + { + // check for create date and expire time + $expire_interval = DI::config()->get('system', 'dbclean-expire-days', 0); + + $user = DBA::selectFirst('user', ['expire'], ['uid' => $item['uid']]); + if (DBA::isResult($user) && ($user['expire'] > 0) && (($user['expire'] < $expire_interval) || ($expire_interval == 0))) { + $expire_interval = $user['expire']; + } + + if (($expire_interval > 0) && !empty($item['created'])) { + $expire_date = time() - ($expire_interval * 86400); + $created_date = strtotime($item['created']); + if ($created_date < $expire_date) { + Logger::notice('Item created before expiration interval.', [ + 'created' => date('c', $created_date), + 'expired' => date('c', $expire_date), + '$item' => $item + ]); + return true; + } + } + + return false; + } + /** * Return the id of the given item array if it has been stored before * diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 9302a05903..5d682d837e 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -503,7 +503,10 @@ class Feed $items[] = $item; break; } elseif (!Item::isValid($item)) { - Logger::info('Feed is invalid', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]); + Logger::info('Feed item is invalid', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]); + continue; + } elseif (Item::tooOld($item)) { + Logger::info('Feed is too old', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]); continue; } From b30d2c9c6b9119d117b0d9039dc0a8686b40a387 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 30 Nov 2020 20:59:18 +0000 Subject: [PATCH 2/2] Renamed function --- src/Model/Item.php | 2 +- src/Protocol/Feed.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 35faa40756..d5f5031561 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1431,7 +1431,7 @@ class Item * @param array $item * @return boolean item is too old */ - public static function tooOld(array $item) + public static function isTooOld(array $item) { // check for create date and expire time $expire_interval = DI::config()->get('system', 'dbclean-expire-days', 0); diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 5d682d837e..6390fab658 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -505,7 +505,7 @@ class Feed } elseif (!Item::isValid($item)) { Logger::info('Feed item is invalid', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]); continue; - } elseif (Item::tooOld($item)) { + } elseif (Item::isTooOld($item)) { Logger::info('Feed is too old', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]); continue; }