Merge branch 'master' into PHRAS-1631-collection-unpublish

This commit is contained in:
Nicolas Maillat
2020-02-28 18:20:36 +01:00
committed by GitHub
4 changed files with 207 additions and 31 deletions

View File

@@ -24,8 +24,11 @@ use Alchemy\Phrasea\Command\Thesaurus\FindConceptsCommand;
use Alchemy\Phrasea\Core\Version; use Alchemy\Phrasea\Core\Version;
use Alchemy\Phrasea\Command\CreateCollection; use Alchemy\Phrasea\Command\CreateCollection;
use Alchemy\Phrasea\Command\Collection\UnPublishCollectionCommand; use Alchemy\Phrasea\Command\Collection\UnPublishCollectionCommand;
use Alchemy\Phrasea\Command\Collection\PublishCollectionCommand;
use Alchemy\Phrasea\Command\Collection\ListCollectionCommand; use Alchemy\Phrasea\Command\Collection\ListCollectionCommand;
use Alchemy\Phrasea\Command\Databox\CreateDataboxCommand; use Alchemy\Phrasea\Command\Databox\CreateDataboxCommand;
use Alchemy\Phrasea\Command\Databox\UnMountDataboxCommand;
use Alchemy\Phrasea\Command\Databox\MountDataboxCommand;
use Alchemy\Phrasea\Command\Databox\ListDataboxCommand; use Alchemy\Phrasea\Command\Databox\ListDataboxCommand;
use Alchemy\Phrasea\Command\MailTest; use Alchemy\Phrasea\Command\MailTest;
use Alchemy\Phrasea\Command\Compile\Configuration; use Alchemy\Phrasea\Command\Compile\Configuration;
@@ -114,14 +117,15 @@ $cli->command(new \module_console_fieldsRename('fields:rename'));
$cli->command(new \module_console_fieldsMerge('fields:merge')); $cli->command(new \module_console_fieldsMerge('fields:merge'));
$cli->command(new CreateCollection('collection:create')); $cli->command(new CreateCollection('collection:create'));
$cli->command(new UnPublishCollectionCommand('collection:unpublish')); $cli->command(new UnPublishCollectionCommand('collection:unpublish'));
$cli->command(new PublishCollectionCommand('collection:publish'));
$cli->command(new ListCollectionCommand('collection:list')); $cli->command(new ListCollectionCommand('collection:list'));
$cli->command(new ListDataboxCommand('databox:list')); $cli->command(new ListDataboxCommand('databox:list'));
$cli->command(new CreateDataboxCommand('databox:create')); $cli->command(new CreateDataboxCommand('databox:create'));
$cli->command(new UnMountDataboxCommand('databox:unmount'));
$cli->command(new MountDataboxCommand('databox:mount'));
$cli->command(new UserCreateCommand('user:create')); $cli->command(new UserCreateCommand('user:create'));

View File

@@ -0,0 +1,61 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\Collection;
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
class PublishCollectionCommand extends Command
{
/**
* Constructor
*/
public function __construct($name = null)
{
parent::__construct('collection:publish');
$this->setDescription('Publish collection in Phraseanet')
->addOption('collection_id', null, InputOption::VALUE_REQUIRED, 'The base_id of the collection to publish but keep with existing right into present in application box.')
->setHelp('');
return $this;
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
try {
$collection = \collection::getByBaseId($this->container,(int)$input->getOption('collection_id'));
$dialog = $this->getHelperSet()->get('dialog');
do {
$continue = mb_strtolower($dialog->ask($output, '<question> Do you want really publish this collection? (y/N)</question>', 'N'));
} while ( ! in_array($continue, ['y', 'n']));
if ($continue !== 'y') {
$output->writeln('Aborting !');
return;
}
$collection->enable($this->container->getApplicationBox());
$output->writeln('<info>Publish collection successful</info>');
} catch (\Exception $e) {
$output->writeln('<error>Publish collection failed : '.$e->getMessage().'</error>');
}
return 0;
}
}

View File

@@ -1,7 +1,16 @@
<?php <?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2020 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\Databox; namespace Alchemy\Phrasea\Command\Databox;
use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Databox\DataboxConnectionSettings; use Alchemy\Phrasea\Databox\DataboxConnectionSettings;
use Alchemy\Phrasea\Databox\DataboxService; use Alchemy\Phrasea\Databox\DataboxService;
@@ -13,42 +22,84 @@ use Symfony\Component\Console\Output\OutputInterface;
class MountDataboxCommand extends Command class MountDataboxCommand extends Command
{ {
/**
protected function configure() * Constructor
*/
public function __construct($name = null)
{ {
$this->setName('databox:mount') parent::__construct('databox:mount');
->addArgument('databox', InputArgument::REQUIRED, 'Database name for the databox', null)
->addArgument('owner', InputArgument::REQUIRED, 'Email of the databox admin user', null) $this->setDescription('Mount databox')
->addOption('connection', 'c', InputOption::VALUE_NONE, 'Flag to set new database settings') ->addArgument('databox', InputArgument::REQUIRED, 'Database name in Mysql', null)
->addOption('db-host', null, InputOption::VALUE_OPTIONAL, 'MySQL server host', 'localhost') ->addArgument('user_id', InputArgument::REQUIRED, 'The Id of user owner (this account became full admin on this databox)', null)
->addOption('db-port', null, InputOption::VALUE_OPTIONAL, 'MySQL server port', 3306) ->addOption('db-host', null, InputOption::VALUE_OPTIONAL, 'MySQL server host')
->addOption('db-user', null, InputOption::VALUE_OPTIONAL, 'MySQL server user', 'phrasea') ->addOption('db-port', null, InputOption::VALUE_OPTIONAL, 'MySQL server port')
->addOption('db-password', null, InputOption::VALUE_OPTIONAL, 'MySQL server password', null); ->addOption('db-user', null, InputOption::VALUE_OPTIONAL, 'MySQL server user')
->addOption('db-password', null, InputOption::VALUE_OPTIONAL, 'MySQL server password')
;
return $this;
} }
protected function doExecute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$databoxName = $input->getArgument('databox'); try {
$connectionSettings = $input->getOption('connection') == false ? null : new DataboxConnectionSettings(
$input->getOption('db-host'),
$input->getOption('db-port'),
$input->getOption('db-user'),
$input->getOption('db-password')
);
/** @var UserRepository $userRepository */ /** @var UserRepository $userRepository */
$userRepository = $this->container['repo.users']; $userRepository = $this->container['repo.users'];
/** @var DataboxService $databoxService */
$databoxService = $this->container['databox.service'];
$owner = $userRepository->findByEmail($input->getArgument('owner')); $owner = $userRepository->find($input->getArgument('user_id'));
$databoxService->mountDatabox( if (empty($owner)) {
$databoxName, $output->writeln('<error>User not found ! </error>');
$owner,
$connectionSettings
);
$output->writeln('Databox mounted'); return;
}
if ($owner->isGuest() || !$this->container->getAclForUser($owner)->is_admin()) {
$output->writeln('<error>Admin role is required for the owner ! </error>');
return;
}
$databoxName = $input->getArgument('databox');
$dialog = $this->getHelperSet()->get('dialog');
$connectionSettings = new DataboxConnectionSettings(
$input->getOption('db-host')?:$this->container['conf']->get(['main', 'database', 'host']),
$input->getOption('db-port')?:$this->container['conf']->get(['main', 'database', 'port']),
$input->getOption('db-user')?:$this->container['conf']->get(['main', 'database', 'user']),
$input->getOption('db-password')?:$this->container['conf']->get(['main', 'database', 'password'])
);
do {
$continue = mb_strtolower($dialog->ask($output, '<question> Do you want really mount this databox? (y/N)</question>', 'N'));
}
while ( ! in_array($continue, ['y', 'n']));
if ($continue !== 'y') {
$output->writeln('Aborting !');
return;
}
/** @var DataboxService $databoxService */
$databoxService = $this->container['databox.service'];
\phrasea::clear_sbas_params($this->container);
$databox = $databoxService->mountDatabox(
$databoxName,
$owner,
$connectionSettings
);
$output->writeln("\n\t<info>Data-Box ID ".$databox->get_sbas_id()." mounted successful !</info>\n");
} catch (\Exception $e) {
$output->writeln('<error>Mount databox failed :'.$e->getMessage().'</error>');
}
return 0;
} }
} }

View File

@@ -0,0 +1,60 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\Databox;
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class UnMountDataboxCommand extends Command
{
/**
* Constructor
*/
public function __construct($name = null)
{
parent::__construct('databox:unmount');
$this->setDescription('Unmount databox')
->addArgument('databox_id', InputArgument::REQUIRED, 'The id of the databox to unmount', null)
;
return $this;
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
try {
$databox = $this->container->findDataboxById($input->getArgument('databox_id'));
$dialog = $this->getHelperSet()->get('dialog');
do {
$continue = mb_strtolower($dialog->ask($output, '<question> Do you want really unmount this databox? (y/N)</question>', 'N'));
} while ( ! in_array($continue, ['y', 'n']));
if ($continue !== 'y') {
$output->writeln('Aborting !');
return;
}
$databox->unmount_databox();
$output->writeln('<info>Unmount databox successful</info>');
} catch (\Exception $e) {
$output->writeln('<error>Unmount databox failed : '.$e->getMessage().'</error>');
}
return 0;
}
}