summaryrefslogtreecommitdiffstats
path: root/lib/Command/Updater
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/Command/Updater
parent5687baca75d47dbdffd3de74e865ad2f71ef0cb7 (diff)
Create V2 mapper, Service and management commands
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib/Command/Updater')
-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
4 files changed, 60 insertions, 37 deletions
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 extends Command
{
- private $updater;
+ /**
+ * @var UpdaterService Updater
+ */
+ private $updaterService;
- public function __construct(Updater $updater)
+ public function __construct(UpdaterService $updater)
{
parent::__construct();
- $this->updater = $updater;
+ $this->updaterService = $updater;
}
protected function configure()
@@ -39,8 +39,10 @@ class BeforeUpdate extends Command
);
}
- protected function execute(InputInterface $input, OutputInterface $output)
+ protected function execute(InputInterface $input, OutputInterface $output): int
{
- $this->updater->beforeUpdate();
+ $this->updaterService->beforeUpdate();
+
+ return 0;
}
}
diff --git a/lib/Command/Updater/UpdateFeed.php b/lib/Command/Updater/UpdateFeed.php
index f5cda22ad..5078e92a4 100644
--- a/lib/Command/Updater/UpdateFeed.php
+++ b/lib/Command/Updater/UpdateFeed.php
@@ -13,6 +13,7 @@ namespace OCA\News\Command\Updater;
use Exception;
+use OCA\News\Service\FeedServiceV2;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -22,9 +23,12 @@ use OCA\News\Service\FeedService;
class UpdateFeed extends Command
{
+ /**
+ * @var FeedServiceV2 Feed service
+ */
private $feedService;
- public function __construct(FeedService $feedService)
+ public function __construct(FeedServiceV2 $feedService)
{
parent::__construct();
$this->feedService = $feedService;
@@ -34,24 +38,25 @@ class UpdateFeed extends Command
{
$this->setName('news:updater:update-feed')
->addArgument(
- 'feed-id',
+ 'user-id',
InputArgument::REQUIRED,
- 'feed id, integer'
+ 'user id of a user, string'
)
->addArgument(
- 'user-id',
+ 'feed-id',
InputArgument::REQUIRED,
- 'user id of a user, string'
+ 'feed id, integer'
)
->setDescription('Console API for updating a single user\'s feed');
}
- protected function execute(InputInterface $input, OutputInterface $output)
+ protected function execute(InputInterface $input, OutputInterface $output): int
{
$feedId = $input->getArgument('feed-id');
$userId = $input->getArgument('user-id');
try {
- $this->feedService->update($feedId, $userId);
+ $feed = $this->feedService->findForUser($userId, $feedId);
+ $this->feedService->fetch($feed);
} catch (Exception $e) {
$output->writeln(
'<error>Could not update feed with id ' . $feedId .
@@ -59,5 +64,7 @@ class UpdateFeed extends Command
'</error> '
);
}
+
+ return 0;
}
}