From 78dce7ffe18665bf083ff69631db8ae128a2b99f Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 1 Mar 2021 21:10:46 +0100 Subject: DB: Updates should use set() Issue GH-1211 Signed-off-by: Sean Molenaar --- lib/Command/Debug/FeedRead.php | 85 +++++++++++++++++++++++++++++++++++++++ lib/Command/Debug/FolderRead.php | 84 ++++++++++++++++++++++++++++++++++++++ lib/Command/Debug/ItemRead.php | 87 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 256 insertions(+) create mode 100644 lib/Command/Debug/FeedRead.php create mode 100644 lib/Command/Debug/FolderRead.php create mode 100644 lib/Command/Debug/ItemRead.php (limited to 'lib/Command/Debug') diff --git a/lib/Command/Debug/FeedRead.php b/lib/Command/Debug/FeedRead.php new file mode 100644 index 000000000..eaf7f6b14 --- /dev/null +++ b/lib/Command/Debug/FeedRead.php @@ -0,0 +1,85 @@ +feedService = $feedService; + $this->itemService = $itemService; + } + + /** + * Configure command + * + * @return void + */ + protected function configure() + { + $this->setName('news:feed:read') + ->setDescription('Read feed') + ->addArgument('user-id', InputArgument::REQUIRED, 'User to modify the feed for') + ->addArgument('id', InputArgument::REQUIRED, 'Feed ID'); + } + + /** + * Execute command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|void + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $user = $input->getArgument('user-id'); + + $id = $input->getArgument('id'); + if (!is_numeric($id)) { + $output->writeln('Invalid id!'); + return 255; + } + + try { + $read = $this->feedService->read($user, intval($id)); + $output->writeln("Marked $read items as read", $output::VERBOSITY_VERBOSE); + } catch (ServiceConflictException | ServiceNotFoundException $e) { + $output->writeln('Failed: ' . $e->getMessage()); + return 0; + } + + return 0; + } +} diff --git a/lib/Command/Debug/FolderRead.php b/lib/Command/Debug/FolderRead.php new file mode 100644 index 000000000..a259aceb6 --- /dev/null +++ b/lib/Command/Debug/FolderRead.php @@ -0,0 +1,84 @@ +folderService = $folderService; + $this->itemService = $itemService; + } + + /** + * Configure command + * + * @return void + */ + protected function configure() + { + $this->setName('news:folder:read') + ->setDescription('Read folder') + ->addArgument('user-id', InputArgument::REQUIRED, 'User to modify the folder for') + ->addArgument('id', InputArgument::REQUIRED, 'Folder ID'); + } + + /** + * Execute command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|void + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $user = $input->getArgument('user-id'); + + $id = $input->getArgument('id'); + if (!is_numeric($id)) { + $output->writeln('Invalid id!'); + return 255; + } + + try { + $read = $this->folderService->read($user, intval($id)); + $output->writeln("Marked $read items as read", $output::VERBOSITY_VERBOSE); + } catch (ServiceConflictException | ServiceNotFoundException $e) { + $output->writeln('Failed: ' . $e->getMessage()); + return 0; + } + + return 0; + } +} diff --git a/lib/Command/Debug/ItemRead.php b/lib/Command/Debug/ItemRead.php new file mode 100644 index 000000000..a36efe3ec --- /dev/null +++ b/lib/Command/Debug/ItemRead.php @@ -0,0 +1,87 @@ +itemService = $itemService; + } + + /** + * Configure command + * + * @return void + */ + protected function configure() + { + $this->setName('news:item:read') + ->setDescription('Read item') + ->addArgument('user-id', InputArgument::REQUIRED, 'User to modify the item for') + ->addOption('id', 'i', InputOption::VALUE_REQUIRED, 'Item ID') + ->addOption('read', 'r', InputOption::VALUE_NONE, 'Item read state'); + } + + /** + * Execute command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|void + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $user = $input->getArgument('user-id'); + $read = $input->getOption('read'); + + $id = $input->getOption('id'); + if (!is_null($id) && !is_numeric($id)) { + $output->writeln('Invalid id!'); + return 255; + } + + + try { + if (is_null($id)) { + $readItems = $this->itemService->readAll($user, $this->itemService->newest($user)->getId()); + $output->writeln("Marked $readItems items as read", $output::VERBOSITY_VERBOSE); + } else { + $items = $this->itemService->read($user, intval($id), $read); + $output->writeln(json_encode($this->serialize($items), JSON_PRETTY_PRINT)); + } + } catch (ServiceConflictException | ServiceNotFoundException $e) { + $output->writeln('Failed: ' . $e->getMessage()); + return 1; + } + + return 0; + } +} -- cgit v1.2.3