diff --git a/AUTHORS.md b/AUTHORS.md index c2e1232af..558fc8e49 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -30,6 +30,7 @@ * [Koen Martens](mailto:gmc@sonologic.nl) * [Lukas Reschke](mailto:lukas@owncloud.com) * [Tucker McKnight](mailto:tucker.mcknight@gmail.com) +* [Valdnet](mailto:47037905+Valdnet@users.noreply.github.com) * [Bart Visscher](mailto:bartv@thisnet.nl) * [Christian Elmer](mailto:christian@keinkurt.de) * [Nicolas Wendling](mailto:nicolas.wendling1011@gmail.com) @@ -68,7 +69,6 @@ * [Nikita Chernyi](mailto:rakshazi@users.noreply.github.com) * [Peter Hedlund](mailto:peter@peterandlinda.com) * [Simon Spannagel](mailto:simonspa@kth.se) -* [Valdnet](mailto:47037905+Valdnet@users.noreply.github.com) * [bbBowser](mailto:carspi@mail.de) * [benediktb](mailto:benedikt@blablub.de) * [chylex](mailto:contact@chylex.com) @@ -84,6 +84,7 @@ * [Alexander Grüßung](mailto:alexander@gruessung-online.de) * [Allan Nordhøy](mailto:epost@anotheragency.no) * [Alwaysin](mailto:adrien@demma.fr) +* [Anderson Silva](mailto:UnderEu@users.noreply.github.com) * [Andrea Boero](mailto:mail@tsumi.it) * [Andreas Demmelbauer](mailto:git@notice.at) * [Artem Lavrukhin](mailto:lavryha4590@gmail.com) @@ -94,6 +95,7 @@ * [Bernhard Posselt](mailto:bernhard@desktop.localdomain) * [Björn Bidar](mailto:bjorn.bidar@thaodan.de) * [Candid Dauth](mailto:cdauth@cdauth.eu) +* [Carl Schwan](mailto:carl@carlschwan.eu) * [Carlos Silva](mailto:r3pek@r3pek.org) * [Cesar Enrique Garcia Dabo](mailto:enrique@engarda.org) * [Chris Aumann](mailto:me@chr4.org) @@ -131,6 +133,7 @@ * [Martin Ferretti](mailto:ferrettimartin@protonmail.com) * [Matthias](mailto:matthias.baier@mabaart.de) * [Matthias Blümel](mailto:user@inanna.local) +* [Michael Chang](mailto:github@micbase.com) * [Michael Grosser](mailto:github@stp-ip.net) * [Michael Hamann](mailto:michael@content-space.de) * [Michael Holley](mailto:michaelwholley@gmail.com) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26e667118..59799a4f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ The format is mostly based on [Keep a Changelog](https://keepachangelog.com/en/1 # Unreleased ## [18.x.x] ### Changed - +- New administrator setting for deleting unread items automatically (#1931) ### Fixed # Releases 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(); } } diff --git a/src/components/AdminSettings.vue b/src/components/AdminSettings.vue index 4f7da878e..31626abf0 100644 --- a/src/components/AdminSettings.vue +++ b/src/components/AdminSettings.vue @@ -26,6 +26,13 @@ SPDX-Licence-Identifier: AGPL-3.0-or-later @update:value="update('autoPurgeCount', autoPurgeCount)" />

{{ t('news', 'Defines the maximum amount of articles that can be read per feed which will not be deleted by the cleanup job; if old articles reappear after being read, increase this value; negative values such as -1 will turn this feature off.') }}

+ + {{ t('news', 'Delete unread items automatically') }} + +

{{ t('news', 'Enable this if you also want to delete unread items. Consider increasing the value above.') }}

+ config->expects($this->once()) + $this->config->expects($this->exactly(2)) ->method('getAppValue') - ->with('news', 'autoPurgeCount', 200) - ->will($this->returnValue(200)); - + ->withConsecutive(['news', 'autoPurgeCount', 200], ['news', 'purgeUnread', false]) + ->willReturnOnConsecutiveCalls(200, false); + $this->mapper->expects($this->once()) ->method('deleteOverThreshold') - ->with(200); + ->with(200, false); $this->class->purgeOverThreshold(); } public function testPurgeOverThresholdSet() { - $this->config->expects($this->never()) + $this->config->expects($this->once()) ->method('getAppValue') - ->with('news', 'autoPurgeCount', 200); + ->with('news', 'purgeUnread', false) + ->will($this->returnValue(false)); $this->mapper->expects($this->once()) ->method('deleteOverThreshold')