From 023c61b88f3bfdc3829606a17fa3bf9deac600fc Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 19 Jan 2021 12:30:48 +0100 Subject: Mappers: Implement item purging Signed-off-by: Sean Molenaar --- lib/Command/Updater/AfterUpdate.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'lib/Command/Updater/AfterUpdate.php') diff --git a/lib/Command/Updater/AfterUpdate.php b/lib/Command/Updater/AfterUpdate.php index bedc8c9ff..f9e5671f0 100644 --- a/lib/Command/Updater/AfterUpdate.php +++ b/lib/Command/Updater/AfterUpdate.php @@ -15,6 +15,7 @@ use OCA\News\Service\ItemServiceV2; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class AfterUpdate extends Command @@ -42,14 +43,26 @@ class AfterUpdate extends Command { $this->setName('news:updater:after-update') ->setDescription('removes old read articles which are not starred') - ->addArgument('purge_count', InputArgument::OPTIONAL, 'The amount of items to purge'); + ->addArgument('purge-count', InputArgument::OPTIONAL, 'The amount of items to purge') + ->addOption('purge-unread', null, InputOption::VALUE_NONE, 'If unread items should be purged'); } protected function execute(InputInterface $input, OutputInterface $output): int { - $count = (int) $input->getArgument('purge_count'); + $count = $input->getArgument('purge-count'); + $removeUnread = $input->getOption('purge-unread'); - $output->writeln($this->itemService->purgeOverThreshold($count)); + if ($count !== null) { + $count = intval($count); + } + + $result = $this->itemService->purgeOverThreshold($count, $removeUnread); + if ($result === null) { + $output->writeln('No cleanup needed', $output::VERBOSITY_VERBOSE); + return 0; + } + + $output->writeln('Removed ' . $result . ' item(s)', $output::VERBOSITY_VERBOSE); return 0; } -- cgit v1.2.3