diff options
Diffstat (limited to 'lib/Command/Updater')
-rw-r--r-- | lib/Command/Updater/AfterUpdate.php | 40 | ||||
-rw-r--r-- | lib/Command/Updater/AllFeeds.php | 53 | ||||
-rw-r--r-- | lib/Command/Updater/BeforeUpdate.php | 41 | ||||
-rw-r--r-- | lib/Command/Updater/UpdateFeed.php | 59 |
4 files changed, 193 insertions, 0 deletions
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 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @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 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @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 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @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 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @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('<error>Could not update feed with id ' . $feedId . + ' and user ' . $userId . ': ' . $e->getMessage() . + '</error> '); + } + } + +} |