Add files_external:export command
This commit is contained in:
parent
a32f8aa87a
commit
1fcb36cc39
3 changed files with 86 additions and 20 deletions
|
@ -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));
|
||||
|
|
56
apps/files_external/command/export.php
Normal file
56
apps/files_external/command/export.php
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue