summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Brahmer <info@b-brahmer.de>2022-10-08 14:08:55 +0200
committerBenjamin Brahmer <info@b-brahmer.de>2022-10-08 17:29:08 +0200
commitb88e1a546a2ad8fb0cb73855f747d34778a2b1af (patch)
tree484ea8bd568e8c6c571c745affadc97a15e4a89a
parent64eda2fa61d96bc80fc22b9912c9cbd1ca3c733a (diff)
New administrator setting for deleting unread items automatically
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
-rw-r--r--AUTHORS.md5
-rw-r--r--CHANGELOG.md2
-rw-r--r--lib/AppInfo/Application.php1
-rw-r--r--lib/Db/ItemMapperV2.php6
-rw-r--r--lib/Service/ItemServiceV2.php14
-rw-r--r--lib/Service/UpdaterService.php2
-rw-r--r--src/components/AdminSettings.vue10
-rw-r--r--tests/Unit/Service/ItemServiceTest.php15
8 files changed, 37 insertions, 18 deletions
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)" />
<p><em>{{ 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.') }}</em></p>
+ <NcCheckboxRadioSwitch type="switch"
+ :checked.sync="purgeUnread"
+ @update:checked="update('purgeUnread', purgeUnread)">
+ {{ t('news', 'Delete unread items automatically') }}
+ </NcCheckboxRadioSwitch>
+ <p><em>{{ t('news', 'Enable this if you also want to delete unread items. Consider increasing the value above.') }}</em></p>
+
<NcTextField :value.sync="maxRedirects"
:label="t('news', 'Maximum redirects')"
:label-visible="true"
@@ -90,6 +97,7 @@ export default {
useCronUpdates: loadState('news', 'useCronUpdates') === '1',
autoPurgeMinimumInterval: loadState('news', 'autoPurgeMinimumInterval'),
autoPurgeCount: loadState('news', 'autoPurgeCount'),
+ purgeUnread: loadState('news', 'purgeUnread') === '1',
maxRedirects: loadState('news', 'maxRedirects'),
feedFetcherTimeout: loadState('news', 'feedFetcherTimeout'),
exploreUrl: loadState('news', 'exploreUrl'),
@@ -103,7 +111,7 @@ export default {
appId: 'news',
key,
})
- if (key === 'useCronUpdates') {
+ if (key === 'useCronUpdates' || key === 'purgeUnread') {
value = value ? '1' : '0'
}
try {
diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php
index f91692cda..17a67674c 100644
--- a/tests/Unit/Service/ItemServiceTest.php
+++ b/tests/Unit/Service/ItemServiceTest.php
@@ -605,23 +605,24 @@ class ItemServiceTest extends TestCase
public function testPurgeOverThresholdNull()
{
- $this->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')