diff options
author | Benjamin Brahmer <info@b-brahmer.de> | 2022-10-08 14:08:55 +0200 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2022-10-08 17:29:08 +0200 |
commit | b88e1a546a2ad8fb0cb73855f747d34778a2b1af (patch) | |
tree | 484ea8bd568e8c6c571c745affadc97a15e4a89a /lib | |
parent | 64eda2fa61d96bc80fc22b9912c9cbd1ca3c733a (diff) |
New administrator setting for deleting unread items automatically
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppInfo/Application.php | 1 | ||||
-rw-r--r-- | lib/Db/ItemMapperV2.php | 6 | ||||
-rw-r--r-- | lib/Service/ItemServiceV2.php | 14 | ||||
-rw-r--r-- | lib/Service/UpdaterService.php | 2 |
4 files changed, 15 insertions, 8 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 55f9b0ff5..9212cf6ca 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -55,6 +55,7 @@ class Application extends App implements IBootstrap public const DEFAULT_SETTINGS = [ 'autoPurgeMinimumInterval' => 60, 'autoPurgeCount' => 200, + 'purgeUnread' => false, 'maxRedirects' => 10, 'feedFetcherTimeout' => 60, 'useCronUpdates' => true, diff --git a/lib/Db/ItemMapperV2.php b/lib/Db/ItemMapperV2.php index 096b42005..704a8214d 100644 --- a/lib/Db/ItemMapperV2.php +++ b/lib/Db/ItemMapperV2.php @@ -185,13 +185,13 @@ class ItemMapperV2 extends NewsMapperV2 * Delete items from feed that are over the max item threshold * * @param int $threshold Deletion threshold - * @param bool $removeUnread If unread articles should be removed + * @param bool $purgeUnread If unread articles should be removed * * @return int|null Removed items * * @throws \Doctrine\DBAL\Exception */ - public function deleteOverThreshold(int $threshold, bool $removeUnread = false): ?int + public function deleteOverThreshold(int $threshold, bool $purgeUnread): ?int { $feedQb = $this->db->getQueryBuilder(); $feedQb->select('feed_id', $feedQb->func()->count('*', 'itemCount')) @@ -214,7 +214,7 @@ class ItemMapperV2 extends NewsMapperV2 ->andWhere('starred = false') ->addOrderBy('id', 'DESC'); - if ($removeUnread === false) { + if ($purgeUnread === false) { $rangeQuery->andWhere('unread = false'); } diff --git a/lib/Service/ItemServiceV2.php b/lib/Service/ItemServiceV2.php index 57804a8c3..ab83ba5c5 100644 --- a/lib/Service/ItemServiceV2.php +++ b/lib/Service/ItemServiceV2.php @@ -145,12 +145,12 @@ class ItemServiceV2 extends Service } /** - * @param int|null $threshold - * @param bool $removeUnread + * @param int|null $threshold + * @param bool|null $purgeUnread * * @return int|null Amount of deleted items or null if not applicable */ - public function purgeOverThreshold(int $threshold = null, bool $removeUnread = false): ?int + public function purgeOverThreshold(int $threshold = null, bool $purgeUnread = null): ?int { $threshold = (int) ($threshold ?? $this->config->getAppValue( Application::NAME, @@ -158,11 +158,17 @@ class ItemServiceV2 extends Service Application::DEFAULT_SETTINGS['autoPurgeCount'] )); + $purgeUnread = (bool) ($purgeUnread ?? $this->config->getAppValue( + Application::NAME, + 'purgeUnread', + Application::DEFAULT_SETTINGS['purgeUnread'] + )); + if ($threshold <= 0) { return null; } - return $this->mapper->deleteOverThreshold($threshold, $removeUnread); + return $this->mapper->deleteOverThreshold($threshold, $purgeUnread); } /** * Mark an item as starred diff --git a/lib/Service/UpdaterService.php b/lib/Service/UpdaterService.php index bf944d19f..5ab553d10 100644 --- a/lib/Service/UpdaterService.php +++ b/lib/Service/UpdaterService.php @@ -58,6 +58,6 @@ class UpdaterService public function afterUpdate(): void { - $this->itemService->purgeOverThreshold(null); + $this->itemService->purgeOverThreshold(); } } |