From 21203dbf6386e72ef780d0b5d4b81a7e25e94485 Mon Sep 17 00:00:00 2001 From: David Baucum Date: Tue, 1 Jun 2021 23:51:34 -0400 Subject: Update all feeds from command Closes #1359 Signed-off-by: David Baucum --- lib/Command/Updater/UpdateUser.php | 70 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/Command/Updater/UpdateUser.php (limited to 'lib') diff --git a/lib/Command/Updater/UpdateUser.php b/lib/Command/Updater/UpdateUser.php new file mode 100644 index 000000000..050641972 --- /dev/null +++ b/lib/Command/Updater/UpdateUser.php @@ -0,0 +1,70 @@ +feedService = $feedService; + } + + /** + * @return void + */ + protected function configure() + { + $this->setName('news:updater:update-user') + ->addArgument( + 'user-id', + InputArgument::REQUIRED, + 'user id of a user, string' + ) + ->setDescription('Console API for updating a single user\'s feed'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $userId = $input->getArgument('user-id'); + $feeds = $this->feedService->findAllForUser($userId); + $updateErrors = false; + foreach ($feeds as $feed) { + try { + $updated_feed = $this->feedService->fetch($feed); + if ($updated_feed->getUpdateErrorCount() !== 0) { + $output->writeln($updated_feed->getLastUpdateError()); + $updateErrors = true; + } + } catch (Exception $e) { + $output->writeln( + 'Could not update feed with id ' . $feed->getId() . + '. ' . $e->getMessage() . ' ' + ); + return 1; + } + } + if ($updateErrors) { + return 255; + } + return 0; + } +} -- cgit v1.2.3