From 004fcbbcc7609ca83807f2e38967ef54f469bf72 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 23 Jul 2016 21:24:54 +0200 Subject: Move to new directory structure --- lib/Command/Updater/AfterUpdate.php | 40 ++++++++++++++++++++++++ lib/Command/Updater/AllFeeds.php | 53 ++++++++++++++++++++++++++++++++ lib/Command/Updater/BeforeUpdate.php | 41 +++++++++++++++++++++++++ lib/Command/Updater/UpdateFeed.php | 59 ++++++++++++++++++++++++++++++++++++ 4 files changed, 193 insertions(+) create mode 100644 lib/Command/Updater/AfterUpdate.php create mode 100644 lib/Command/Updater/AllFeeds.php create mode 100644 lib/Command/Updater/BeforeUpdate.php create mode 100644 lib/Command/Updater/UpdateFeed.php (limited to 'lib/Command/Updater') diff --git a/lib/Command/Updater/AfterUpdate.php b/lib/Command/Updater/AfterUpdate.php new file mode 100644 index 000000000..36e23b477 --- /dev/null +++ b/lib/Command/Updater/AfterUpdate.php @@ -0,0 +1,40 @@ + + * @copyright Bernhard Posselt 2016 + */ + +namespace OCA\News\Command\Updater; + +use Exception; + +use Symfony\Component\Console\Command\Command; +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) { + parent::__construct(); + $this->updater = $updater; + } + + 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'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $this->updater->afterUpdate(); + } + +} diff --git a/lib/Command/Updater/AllFeeds.php b/lib/Command/Updater/AllFeeds.php new file mode 100644 index 000000000..05330ac01 --- /dev/null +++ b/lib/Command/Updater/AllFeeds.php @@ -0,0 +1,53 @@ + + * @copyright Bernhard Posselt 2016 + */ + +namespace OCA\News\Command\Updater; + +use Exception; + +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 { + private $feedService; + + public function __construct(FeedService $feedService) { + parent::__construct(); + $this->feedService = $feedService; + } + + protected function configure() { + $json = '{"feeds": [{"id": 39, "userId": "john"}, // etc ]}'; + + $this->setName('news:updater:all-feeds') + ->setDescription('Prints a JSON string which contains all feed ' . + 'ids and user ids, e.g.: ' . $json); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $feeds = $this->feedService->findAllFromAllUsers(); + $result = ['feeds' => []]; + + foreach ($feeds as $feed) { + $result['feeds'][] = [ + 'id' => $feed->getId(), + 'userId' => $feed->getUserId() + ]; + } + + print(json_encode($result)); + } + +} diff --git a/lib/Command/Updater/BeforeUpdate.php b/lib/Command/Updater/BeforeUpdate.php new file mode 100644 index 000000000..6af0a5c3a --- /dev/null +++ b/lib/Command/Updater/BeforeUpdate.php @@ -0,0 +1,41 @@ + + * @copyright Bernhard Posselt 2016 + */ + +namespace OCA\News\Command\Updater; + +use Exception; + +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; + + public function __construct(Updater $updater) { + parent::__construct(); + $this->updater = $updater; + } + + protected function configure() { + $this->setName('news:updater:before-update') + ->setDescription('This is used to clean up the database. It ' . + 'deletes folders and feeds that are marked for ' . + 'deletion'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $this->updater->beforeUpdate(); + } + +} diff --git a/lib/Command/Updater/UpdateFeed.php b/lib/Command/Updater/UpdateFeed.php new file mode 100644 index 000000000..13fc2e625 --- /dev/null +++ b/lib/Command/Updater/UpdateFeed.php @@ -0,0 +1,59 @@ + + * @copyright Bernhard Posselt 2016 + */ + +namespace OCA\News\Command\Updater; + +use Exception; + +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\Service\FeedService; + + +class UpdateFeed extends Command { + private $feedService; + + public function __construct(FeedService $feedService) { + parent::__construct(); + $this->feedService = $feedService; + } + + protected function configure() { + $this->setName('news:updater:update-feed') + ->addArgument( + 'feed-id', + InputArgument::REQUIRED, + 'feed id, integer' + ) + ->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) { + $feedId = $input->getArgument('feed-id'); + $userId = $input->getArgument('user-id'); + try { + $this->feedService->update($feedId, $userId); + } catch (Exception $e) { + $output->writeln('Could not update feed with id ' . $feedId . + ' and user ' . $userId . ': ' . $e->getMessage() . + ' '); + } + } + +} -- cgit v1.2.3