diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2020-08-29 23:39:35 +0200 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2020-09-27 15:35:31 +0200 |
commit | d00d1ab2a28f428223e52b17052c072c64784016 (patch) | |
tree | c019f85fb7ac67147dd43ca64b4ac3cda99832f7 /lib | |
parent | 5687baca75d47dbdffd3de74e865ad2f71ef0cb7 (diff) |
Create V2 mapper, Service and management commands
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib')
54 files changed, 2036 insertions, 268 deletions
diff --git a/lib/Command/Config/FeedAdd.php b/lib/Command/Config/FeedAdd.php new file mode 100644 index 000000000..d21f448c0 --- /dev/null +++ b/lib/Command/Config/FeedAdd.php @@ -0,0 +1,72 @@ +<?php +declare(strict_types=1); +namespace OCA\News\Command\Config; + +use OCA\News\Service\FeedServiceV2; +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 FeedAdd extends Command +{ + /** + * @var FeedServiceV2 service for the feeds. + */ + protected $feedService; + + /** + * FeedAdd constructor. + * + * @param FeedServiceV2 $feedService + */ + public function __construct(FeedServiceV2 $feedService) + { + parent::__construct(null); + + $this->feedService = $feedService; + } + + /** + * Configure command + */ + protected function configure() + { + $this->setName('news:feed:add') + ->setDescription('Add a feed') + ->addArgument('userID', InputArgument::REQUIRED, 'User to add the feed for') + ->addArgument('feed', InputArgument::REQUIRED, 'Feed to parse') + ->addOption('folder', null, InputOption::VALUE_OPTIONAL, 'Folder ID') + ->addOption('title', null, InputOption::VALUE_OPTIONAL, 'Feed title') + ->addOption('full-text', null, InputOption::VALUE_OPTIONAL, 'Scrape item URLs', false) + ->addOption('username', null, InputOption::VALUE_OPTIONAL, 'Basic auth username') + ->addOption('password', null, InputOption::VALUE_OPTIONAL, 'Basic auth password'); + } + + /** + * Execute command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + $url = $input->getArgument('feed'); + $user = $input->getArgument('userID'); + $folder = (int) $input->getOption('folder') ?? 0; + $title = $input->getOption('title'); + $username = $input->getOption('username'); + $full_text = $input->getOption('full-text'); + $password = $input->getOption('password'); + + $feed = $this->feedService->create($user, $url, $folder, $full_text, $title, $username, $password); + $this->feedService->fetch($feed, true); + + $output->writeln(json_encode($feed->toAPI(), JSON_PRETTY_PRINT)); + + return 0; + } +} diff --git a/lib/Command/Config/FeedDelete.php b/lib/Command/Config/FeedDelete.php new file mode 100644 index 000000000..c848b1fd4 --- /dev/null +++ b/lib/Command/Config/FeedDelete.php @@ -0,0 +1,56 @@ +<?php + +namespace OCA\News\Command\Config; + +use OCA\News\Db\Feed; +use OCA\News\Service\FeedServiceV2; +use OCA\News\Service\FolderServiceV2; +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 FeedDelete extends Command +{ + /** + * @var FeedServiceV2 service for the feeds. + */ + protected $feedService; + + public function __construct(FeedServiceV2 $feedService) + { + parent::__construct(null); + + $this->feedService = $feedService; + } + + /** + * Configure command + */ + protected function configure() + { + $this->setName('news:feed:delete') + ->setDescription('Remove a feed') + ->addArgument('userID', InputArgument::REQUIRED, 'User to remove the feed from') + ->addArgument('id', InputArgument::REQUIRED, 'Feed ID', null); + } + + /** + * Execute command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + $user = $input->getArgument('userID'); + $id = $input->getArgument('id'); + + $this->feedService->delete($user, $id); + + return 0; + } +} diff --git a/lib/Command/Config/FeedList.php b/lib/Command/Config/FeedList.php new file mode 100644 index 000000000..57e14d339 --- /dev/null +++ b/lib/Command/Config/FeedList.php @@ -0,0 +1,61 @@ +<?php + +namespace OCA\News\Command\Config; + +use OCA\News\Controller\ApiPayloadTrait; +use OCA\News\Service\FeedServiceV2; +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 FeedList extends Command +{ + use ApiPayloadTrait; + + /** + * @var FeedServiceV2 service for the feeds. + */ + protected $feedService; + + public function __construct(FeedServiceV2 $feedService) + { + parent::__construct(null); + + $this->feedService = $feedService; + } + + /** + * Configure command + */ + protected function configure() + { + $this->setName('news:feed:list') + ->setDescription('List all feeds') + ->addArgument('userID', InputArgument::REQUIRED, 'User to list the feeds for') + ->addOption('recursive', null, InputOption::VALUE_NONE, 'Fetch the feed recursively'); + } + + /** + * Execute command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|void + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $user = $input->getArgument('userID'); + $recursive = $input->getOption('recursive'); + + if ($recursive !== false) { + $feeds = $this->feedService->findAllForUserRecursive($user); + } else { + $feeds = $this->feedService->findAllForUser($user); + } + + $output->writeln(json_encode($this->serialize($feeds), JSON_PRETTY_PRINT)); + } +} diff --git a/lib/Command/Config/FolderAdd.php b/lib/Command/Config/FolderAdd.php new file mode 100644 index 000000000..5a7155e0c --- /dev/null +++ b/lib/Command/Config/FolderAdd.php @@ -0,0 +1,58 @@ +<?php + +namespace OCA\News\Command\Config; + +use OCA\News\Db\Feed; +use OCA\News\Service\FeedServiceV2; +use OCA\News\Service\FolderServiceV2; +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 FolderAdd extends Command +{ + /** + * @var FolderServiceV2 service for the folders. + */ + protected $folderService; + + public function __construct(FolderServiceV2 $folderService) + { + parent::__construct(null); + + $this->folderService = $folderService; + } + + /** + * Configure command + */ + protected function configure() + { + $this->setName('news:folder:add') + ->setDescription('Add a folder') + ->addArgument('userID', InputArgument::REQUIRED, 'User to add the folder for') + ->addArgument('name', InputArgument::REQUIRED, 'Folder name', null) + ->addOption('parent', null, InputOption::VALUE_OPTIONAL, 'Parent folder'); + } + + /** + * Execute command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + $user = $input->getArgument('userID'); + $name = $input->getArgument('name'); + $parent = $input->getOption('parent') ?? 0; + + $this->folderService->create($user, $name, $parent); + + return 0; + } +} diff --git a/lib/Command/Config/FolderDelete.php b/lib/Command/Config/FolderDelete.php new file mode 100644 index 000000000..c441bd615 --- /dev/null +++ b/lib/Command/Config/FolderDelete.php @@ -0,0 +1,61 @@ +<?php + +namespace OCA\News\Command\Config; + +use OCA\News\Db\Feed; +use OCA\News\Service\Exceptions\ServiceException; +use OCA\News\Service\FeedServiceV2; +use OCA\News\Service\FolderServiceV2; +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 FolderDelete extends Command +{ + /** + * @var FolderServiceV2 service for the folders. + */ + protected $folderService; + + public function __construct(FolderServiceV2 $folderService) + { + parent::__construct(null); + + $this->folderService = $folderService; + } + + /** + * Configure command + */ + protected function configure() + { + $this->setName('news:folder:delete') + ->setDescription('Remove a folder') + ->addArgument('userID', InputArgument::REQUIRED, 'User to remove the folder from') + ->addArgument('id', InputArgument::REQUIRED, 'Folder ID', null); + } + + /** + * Execute command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + $user = $input->getArgument('userID'); + $id = $input->getArgument('id'); + + if ($id === '0') { + throw new ServiceException('Can not remove root folder!'); + } + + $this->folderService->delete($user, $id); + + return 0; + } +} diff --git a/lib/Command/Config/FolderList.php b/lib/Command/Config/FolderList.php new file mode 100644 index 000000000..7a2d33ab5 --- /dev/null +++ b/lib/Command/Config/FolderList.php @@ -0,0 +1,62 @@ +<?php + +namespace OCA\News\Command\Config; + +use OCA\News\Controller\ApiPayloadTrait; +use OCA\News\Service\FeedServiceV2; +use OCA\News\Service\FolderServiceV2; +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 FolderList extends Command +{ + use ApiPayloadTrait; + + /** + * @var FolderServiceV2 service for the folders. + */ + protected $folderService; + + public function __construct(FolderServiceV2 $folderService) + { + parent::__construct(null); + + $this->folderService = $folderService; + } + + /** + * Configure command + */ + protected function configure() + { + $this->setName('news:folder:list') + ->setDescription('List all folders') + ->addArgument('userID', InputArgument::REQUIRED, 'User to list the folders for') + ->addOption('recursive', null, InputOption::VALUE_NONE, 'Fetch the folder recursively'); + } + + /** + * Execute command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|void + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $user = $input->getArgument('userID'); + $recursive = $input->getOption('recursive'); + + if ($recursive !== false) { + $folders = $this->folderService->findAllForUserRecursive($user); + } else { + $folders = $this->folderService->findAllForUser($user); + } + + $output->writeln(json_encode($this->serialize($folders), JSON_PRETTY_PRINT)); + } +} diff --git a/lib/Command/ExploreGenerator.php b/lib/Command/ExploreGenerator.php index 2e1b38e91..65c206c5e 100644 --- a/lib/Command/ExploreGenerator.php +++ b/lib/Command/ExploreGenerator.php @@ -64,7 +64,7 @@ class ExploreGenerator extends Command ->addOption('votes', null, InputOption::VALUE_OPTIONAL, 'Votes for the feed, defaults to 100'); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $url = $input->getArgument('feed'); $votes = $input->getOption('votes'); @@ -85,6 +85,7 @@ class ExploreGenerator extends Command ]; $output->writeln(json_encode($result, JSON_PRETTY_PRINT)); + return 0; } catch (\Throwable $ex) { $output->writeln('<error>Failed to fetch feed info:</error>'); $output->writeln($ex->getMessage()); diff --git a/lib/Command/ShowFeed.php b/lib/Command/ShowFeed.php index 878b71123..1218279e6 100644 --- a/lib/Command/ShowFeed.php +++ b/lib/Command/ShowFeed.php @@ -60,7 +60,7 @@ class ShowFeed extends Command ->addOption('full-text', 'f', InputOption::VALUE_NONE, 'Usa a scraper to get full text'); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $url = $input->getArgument('feed'); $user = $input->getOption('user'); @@ -71,6 +71,7 @@ class ShowFeed extends Command list($feed, $items) = $this->feedFetcher->fetch($url, true, null, $fullTextEnabled, $user, $password); $output->writeln("Feed: " . json_encode($feed, JSON_PRETTY_PRINT)); $output->writeln("Items: " . json_encode($items, JSON_PRETTY_PRINT)); + return 0; } catch (\Throwable $ex) { $output->writeln('<error>Failed to fetch feed info:</error>'); $output->writeln($ex->getMessage()); diff --git a/lib/Command/Updater/AfterUpdate.php b/lib/Command/Updater/AfterUpdate.php index c80913fab..307dece99 100644 --- a/lib/Command/Updater/AfterUpdate.php +++ b/lib/Command/Updater/AfterUpdate.php @@ -11,35 +11,43 @@ namespace OCA\News\Command\Updater; -use Exception; - +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\Output\OutputInterface; -use \OCA\News\Utility\Updater; - class AfterUpdate extends Command { - private $updater; - - public function __construct(Updater $updater) + /** + * @var ItemServiceV2 + */ + private $itemService; + + /** + * AfterUpdate constructor. + * + * @param ItemServiceV2 $itemService + */ + public function __construct(ItemServiceV2 $itemService) { parent::__construct(); - $this->updater = $updater; + $this->itemService = $itemService; } protected function configure() { $this->setName('news:updater:after-update') - ->setDescription( - 'This is used to clean up the database. It ' . - 'removes old read articles which are not starred' - ); + ->setDescription('removes old read articles which are not starred') + ->addArgument('purge_count', InputArgument::OPTIONAL, 'The amount of items to purge'); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { - $this->updater->afterUpdate(); + $count = $input->getArgument('id'); + + echo $this->itemService->purgeOverThreshold($count); + + return 0; } } diff --git a/lib/Command/Updater/AllFeeds.php b/lib/Command/Updater/AllFeeds.php index 93ef4e59a..6993d51ea 100644 --- a/lib/Command/Updater/AllFeeds.php +++ b/lib/Com |