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();
$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));
--- /dev/null
+<?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);
+ }
+}
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;
/**
* @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();
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();
* @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;
}
}
}
- $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));
$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;
+ }
+ }
}