summaryrefslogtreecommitdiffstats
path: root/lib/Command/Config/FolderList.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Command/Config/FolderList.php')
-rw-r--r--lib/Command/Config/FolderList.php62
1 files changed, 62 insertions, 0 deletions
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));
+ }
+}