summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2020-08-29 23:39:35 +0200
committerBenjamin Brahmer <info@b-brahmer.de>2020-09-27 15:35:31 +0200
commitd00d1ab2a28f428223e52b17052c072c64784016 (patch)
treec019f85fb7ac67147dd43ca64b4ac3cda99832f7 /lib
parent5687baca75d47dbdffd3de74e865ad2f71ef0cb7 (diff)
Create V2 mapper, Service and management commands
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/Config/FeedAdd.php72
-rw-r--r--lib/Command/Config/FeedDelete.php56
-rw-r--r--lib/Command/Config/FeedList.php61
-rw-r--r--lib/Command/Config/FolderAdd.php58
-rw-r--r--lib/Command/Config/FolderDelete.php61
-rw-r--r--lib/Command/Config/FolderList.php62
-rw-r--r--lib/Command/ExploreGenerator.php3
-rw-r--r--lib/Command/ShowFeed.php3
-rw-r--r--lib/Command/Updater/AfterUpdate.php36
-rw-r--r--lib/Command/Updater/AllFeeds.php20
-rw-r--r--lib/Command/Updater/BeforeUpdate.php20
-rw-r--r--lib/Command/Updater/UpdateFeed.php21
-rw-r--r--lib/Controller/ApiPayloadTrait.php36
-rw-r--r--lib/Controller/EntityApiSerializer.php6
-rw-r--r--lib/Controller/FeedApiController.php35
-rw-r--r--lib/Controller/FeedController.php12
-rw-r--r--lib/Controller/FolderApiController.php6
-rw-r--r--lib/Controller/FolderController.php6
-rw-r--r--lib/Controller/ItemApiController.php10
-rw-r--r--lib/Controller/ItemController.php6
-rw-r--r--lib/Controller/JSONHttpError.php7
-rw-r--r--lib/Controller/UtilityApiController.php21
-rw-r--r--lib/Cron/UpdaterJob.php (renamed from lib/Cron/Updater.php)18
-rw-r--r--lib/Db/Feed.php115
-rw-r--r--lib/Db/FeedMapper.php29
-rw-r--r--lib/Db/FeedMapperV2.php141
-rw-r--r--lib/Db/Folder.php7
-rw-r--r--lib/Db/FolderMapper.php38
-rw-r--r--lib/Db/FolderMapperV2.php87
-rw-r--r--lib/Db/Item.php6
-rw-r--r--lib/Db/ItemMapper.php52
-rw-r--r--lib/Db/ItemMapperV2.php124
-rw-r--r--lib/Db/MapperFactory.php6
-rw-r--r--lib/Db/Mysql/ItemMapper.php6
-rw-r--r--lib/Db/NewsMapper.php84
-rw-r--r--lib/Db/NewsMapperV2.php108
-rwxr-xr-xlib/Fetcher/FeedFetcher.php2
-rw-r--r--lib/Fetcher/IFeedFetcher.php2
-rw-r--r--lib/Fetcher/YoutubeFetcher.php8
-rw-r--r--lib/Service/Exceptions/ServiceConflictException.php (renamed from lib/Service/ServiceConflictException.php)2
-rw-r--r--lib/Service/Exceptions/ServiceException.php (renamed from lib/Service/ServiceException.php)2
-rw-r--r--lib/Service/Exceptions/ServiceNotFoundException.php (renamed from lib/Service/ServiceNotFoundException.php)2
-rw-r--r--lib/Service/Exceptions/ServiceValidationException.php (renamed from lib/Service/ServiceValidationException.php)2
-rw-r--r--lib/Service/FeedService.php61
-rw-r--r--lib/Service/FeedServiceV2.php336
-rw-r--r--lib/Service/FolderService.php97
-rw-r--r--lib/Service/FolderServiceV2.php102
-rw-r--r--lib/Service/ItemService.php30
-rw-r--r--lib/Service/ItemServiceV2.php104
-rw-r--r--lib/Service/Service.php70
-rw-r--r--lib/Service/StatusService.php6
-rw-r--r--lib/Service/UpdaterService.php (renamed from lib/Utility/Updater.php)20
-rw-r--r--lib/Utility/OPMLExporter.php15
-rw-r--r--lib/Utility/Time.php4
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/Command/Updater/AllFeeds.php
@@ -11,19 +11,24 @@
namespace OCA\News\Command\Updater;
-use Exception;
-
+use OCA\News\Service\FeedServiceV2;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-use OCA\News\Service\FeedService;
-
class AllFeeds extends Command
{
+ /**
+ * @var FeedServiceV2 Feed service
+ */
private $feedService;
- public function __construct(FeedService $feedService)
+ /**
+ * AllFeeds constructor.
+ *
+ * @param FeedServiceV2 $feedService
+ */
+ public function __construct(FeedServiceV2 $feedService)
{
parent::__construct();
$this->feedService = $feedService;
@@ -35,6 +40,7 @@ class AllFeeds extends Command
$this->setName('news:updater:all-feeds')
->setDescription(
+ 'DEPRECATED: use news:feed:list instead.' . PHP_EOL .
'Prints a JSON string which contains all feed ' .
'ids and user ids, e.g.: ' . $json
);
@@ -42,7 +48,7 @@ class AllFeeds extends Command
protected function execute(InputInterface $input, OutputInterface $output)
{
- $feeds = $this->feedService->findAllFromAllUsers();
+ $feeds = $this->feedService->findAll();
$result = ['feeds' => []];
foreach ($feeds as $feed) {
@@ -53,6 +59,6 @@ class AllFeeds extends Command
];
}
- print(json_encode($result));
+ $output->write(json_encode($result));
}
}
diff --git a/lib/Command/Updater/BeforeUpdate.php b/lib/Command/Updater/BeforeUpdate.php
index 3a0b1ca72..787125c32 100644
--- a/lib/Command/Updater/BeforeUpdate.php
+++ b/lib/Command/Updater/BeforeUpdate.php
@@ -11,22 +11,22 @@
namespace OCA\News\Command\Updater;
-use Exception;
-
+use OCA\News\Service\UpdaterService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-use \OCA\News\Utility\Updater;
-
class BeforeUpdate