summaryrefslogtreecommitdiffstats
path: root/apps/files_external/command
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2016-01-18 11:35:34 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-01-18 14:17:27 +0100
commit1fcb36cc394df8521552e34cd7232e663cd2839b (patch)
treed9c3c8ff5b83a6764c2e957e0820f06b814b61de /apps/files_external/command
parenta32f8aa87a959bf0050cbd7f710a690427f5a1f2 (diff)
downloadnextcloud-server-1fcb36cc394df8521552e34cd7232e663cd2839b.tar.gz
nextcloud-server-1fcb36cc394df8521552e34cd7232e663cd2839b.zip
Add files_external:export command
Diffstat (limited to 'apps/files_external/command')
-rw-r--r--apps/files_external/command/export.php56
-rw-r--r--apps/files_external/command/listcommand.php46
2 files changed, 83 insertions, 19 deletions
diff --git a/apps/files_external/command/export.php b/apps/files_external/command/export.php
new file mode 100644
index 00000000000..371061ba626
--- /dev/null
+++ b/apps/files_external/command/export.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Command;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Helper\Table;
+use Symfony\Component\Console\Helper\TableHelper;
+use Symfony\Component\Console\Input\ArrayInput;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\Input;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class Export extends ListCommand {
+
+ protected function configure() {
+ $this
+ ->setName('files_external:export')
+ ->setDescription('Export mount configurations')
+ ->addArgument(
+ 'user_id',
+ InputArgument::OPTIONAL,
+ 'user id to export the personal mounts for, if no user is provided admin mounts will be exported'
+ );
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
+ $listInput = new ArrayInput([], $listCommand->getDefinition());
+ $listInput->setArgument('user_id', $input->getArgument('user_id'));
+ $listInput->setOption('output', 'json_pretty');
+ $listInput->setOption('show-password', true);
+ $listInput->setOption('full', true);
+ $listCommand->execute($listInput, $output);
+ }
+}
diff --git a/apps/files_external/command/listcommand.php b/apps/files_external/command/listcommand.php
index f55fb464c83..c978ae5cfcb 100644
--- a/apps/files_external/command/listcommand.php
+++ b/apps/files_external/command/listcommand.php
@@ -22,6 +22,7 @@
namespace OCA\Files_External\Command;
use OC\Core\Command\Base;
+use OC\User\NoUserException;
use OCA\Files_external\Lib\StorageConfig;
use OCA\Files_external\Service\GlobalStoragesService;
use OCA\Files_external\Service\UserStoragesService;
@@ -38,22 +39,22 @@ class ListCommand extends Base {
/**
* @var GlobalStoragesService
*/
- private $globalService;
+ protected $globalService;
/**
* @var UserStoragesService
*/
- private $userService;
+ protected $userService;
/**
* @var IUserSession
*/
- private $userSession;
+ protected $userSession;
/**
* @var IUserManager
*/
- private $userManager;
+ protected $userManager;
function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) {
parent::__construct();
@@ -87,17 +88,7 @@ class ListCommand extends Base {
protected function execute(InputInterface $input, OutputInterface $output) {
$userId = $input->getArgument('user_id');
- if (!empty($userId)) {
- $user = $this->userManager->get($userId);
- if (is_null($user)) {
- $output->writeln("<error>user $userId not found</error>");
- return;
- }
- $this->userSession->setUser($user);
- $storageService = $this->userService;
- } else {
- $storageService = $this->globalService;
- }
+ $storageService = $this->getStorageService($userId);
/** @var $mounts StorageConfig[] */
$mounts = $storageService->getAllStorages();
@@ -112,11 +103,16 @@ class ListCommand extends Base {
* @param OutputInterface $output
*/
public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output){
+ $outputType = $input->getOption('output');
if (count($mounts) === 0) {
- if ($userId) {
- $output->writeln("<info>No mounts configured by $userId</info>");
+ if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
+ $output->writeln('[]');
} else {
- $output->writeln("<info>No admin mounts configured</info>");
+ if ($userId) {
+ $output->writeln("<info>No mounts configured by $userId</info>");
+ } else {
+ $output->writeln("<info>No admin mounts configured</info>");
+ }
}
return;
}
@@ -140,7 +136,6 @@ class ListCommand extends Base {
}
}
- $outputType = $input->getOption('output');
if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
$keys = array_map(function ($header) {
return strtolower(str_replace(' ', '_', $header));
@@ -237,4 +232,17 @@ class ListCommand extends Base {
$table->render();
}
}
+
+ protected function getStorageService($userId) {
+ if (!empty($userId)) {
+ $user = $this->userManager->get($userId);
+ if (is_null($user)) {
+ throw new NoUserException("user $userId not found");
+ }
+ $this->userSession->setUser($user);
+ return $this->userService;
+ } else {
+ return $this->globalService;
+ }
+ }
}