summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSean Molenaar <SMillerDev@users.noreply.github.com>2019-03-06 13:10:37 +0100
committerBenjamin Brahmer <info@b-brahmer.de>2019-03-06 13:10:37 +0100
commit71ba5a3ad1a1c9d867af68e72a4a19acd9ffe08d (patch)
treedebd3e30226df8def9e8f0bb30136c91db84184f /lib
parent6a4e56e7274d85bcbd0e2dcde7a61d8f7a4397ec (diff)
Fix generation commands and make them available in ./occ (#402)
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php2
-rw-r--r--lib/Command/ExploreGenerator.php94
2 files changed, 94 insertions, 2 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index c70a2fb6f..755f3ea70 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -76,7 +76,6 @@ class Application extends App
return $c->query(MapperFactory::class)->build();
});
-
/**
* App config parser.
*/
@@ -123,7 +122,6 @@ class Application extends App
);
});
-
$container->registerService(Config::class, function (IContainer $c): Config {
$config = new Config(
$c->query('ConfigView'),
diff --git a/lib/Command/ExploreGenerator.php b/lib/Command/ExploreGenerator.php
new file mode 100644
index 000000000..2e1b38e91
--- /dev/null
+++ b/lib/Command/ExploreGenerator.php
@@ -0,0 +1,94 @@
+<?php
+/**
+ * Nextcloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Sean Molenaar <sean@seanmolenaar.eu>
+ * @copyright Sean Molenaar 2019
+ */
+namespace OCA\News\Command;
+
+use FeedIo\FeedIo;
+use Favicon\Favicon;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * This is used for generating a JSON config section for a feed by executing:
+ * ./occ news:generate-explore www.feed.com
+ */
+class ExploreGenerator extends Command
+{
+ /**
+ * Feed and favicon fetcher.
+ */
+ protected $reader;
+ protected $favicon;
+
+ /**
+ * Set up class.
+ *
+ * @param FeedIo $reader Feed reader
+ * @param Favicon $favicon Favicon fetcher
+ */
+ public function __construct(FeedIo $reader, Favicon $favicon)
+ {
+ $this->reader = $reader;
+ $this->favicon = $favicon;
+ parent::__construct();
+ }
+
+ protected function configure()
+ {
+ $result = [
+ 'title' => 'Feed - Title',
+ 'favicon' => 'www.web.com/favicon.ico',
+ 'url' => 'www.web.com',
+ 'feed' => 'www.web.com/rss.xml',
+ 'description' => 'description is here',
+ 'votes' => 100,
+ ];
+
+ $this->setName('news:generate-explore')
+ ->setDescription(
+ 'Prints a JSON string which represents the given ' .
+ 'feed URL and votes, e.g.: ' . json_encode($result)
+ )
+ ->addArgument('feed', InputArgument::REQUIRED, 'Feed to parse')
+ ->addOption('votes', null, InputOption::VALUE_OPTIONAL, 'Votes for the feed, defaults to 100');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $url = $input->getArgument('feed');
+ $votes = $input->getOption('votes');
+ if (!$votes) {
+ $votes = 100;
+ }
+
+ try {
+ $resource = $this->reader->read($url);
+ $feed = $resource->getFeed();
+ $result = [
+ 'title' => $feed->getTitle(),
+ 'favicon' => $this->favicon->get($feed->getLink()),
+ 'url' => $feed->getLink(),
+ 'feed' => $url,
+ 'description' => $feed->getDescription(),
+ 'votes' => $votes,
+ ];
+
+ $output->writeln(json_encode($result, JSON_PRETTY_PRINT));
+ } catch (\Throwable $ex) {
+ $output->writeln('<error>Failed to fetch feed info:</error>');
+ $output->writeln($ex->getMessage());
+ return 1;
+ }
+ }
+}