diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-18 16:58:26 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-18 16:58:26 +0100 |
commit | 11e774dd7b3f9088e8e3774c290e68f02dc2fadd (patch) | |
tree | 75cd3e197edf8f4aaa1e2b53764ffa4607e14579 /apps/files_external | |
parent | e895ce69fec4b691c9915ba1b94e10d0a003f9f5 (diff) | |
parent | 1fcb36cc394df8521552e34cd7232e663cd2839b (diff) | |
download | nextcloud-server-11e774dd7b3f9088e8e3774c290e68f02dc2fadd.tar.gz nextcloud-server-11e774dd7b3f9088e8e3774c290e68f02dc2fadd.zip |
Merge pull request #21770 from owncloud/files_external-export
Add files_external:export command
Diffstat (limited to 'apps/files_external')
-rw-r--r-- | apps/files_external/appinfo/register_command.php | 4 | ||||
-rw-r--r-- | apps/files_external/command/export.php | 56 | ||||
-rw-r--r-- | apps/files_external/command/listcommand.php | 46 |
3 files changed, 86 insertions, 20 deletions
diff --git a/apps/files_external/appinfo/register_command.php b/apps/files_external/appinfo/register_command.php index 12bf6a45df3..be32cd410f8 100644 --- a/apps/files_external/appinfo/register_command.php +++ b/apps/files_external/appinfo/register_command.php @@ -23,7 +23,8 @@ use OCA\Files_External\Command\ListCommand; use OCA\Files_External\Command\Config; use OCA\Files_External\Command\Option; -use \OCA\Files_External\Command\Import; +use OCA\Files_External\Command\Import; +use OCA\Files_External\Command\Export; $userManager = OC::$server->getUserManager(); $userSession = OC::$server->getUserSession(); @@ -40,3 +41,4 @@ $application->add(new ListCommand($globalStorageService, $userStorageService, $u $application->add(new Config($globalStorageService)); $application->add(new Option($globalStorageService)); $application->add(new Import($globalStorageService, $userStorageService, $userSession, $userManager, $importLegacyStorageService, $backendService)); +$application->add(new Export($globalStorageService, $userStorageService, $userSession, $userManager)); 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; + } + } } |