command databox:list

This commit is contained in:
aynsix
2020-02-20 15:52:05 +03:00
parent c5d4d5ae27
commit 211d33ff46
2 changed files with 65 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ use Alchemy\Phrasea\Command\Thesaurus\FindConceptsCommand;
use Alchemy\Phrasea\Core\Version;
use Alchemy\Phrasea\Command\CreateCollection;
use Alchemy\Phrasea\Command\Databox\CreateDataboxCommand;
use Alchemy\Phrasea\Command\Databox\ListDataboxCommand;
use Alchemy\Phrasea\Command\MailTest;
use Alchemy\Phrasea\Command\Compile\Configuration;
use Alchemy\Phrasea\Command\RecordAdd;
@@ -108,6 +109,8 @@ $cli->command(new \module_console_fieldsRename('fields:rename'));
$cli->command(new \module_console_fieldsMerge('fields:merge'));
$cli->command(new CreateCollection('collection:create'));
$cli->command(new ListDataboxCommand('databox:list'));
$cli->command(new CreateDataboxCommand('databox:create'));
$cli->command(new RecordAdd('records:add'));

View File

@@ -0,0 +1,62 @@
<?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\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ListDataboxCommand extends Command
{
/**
* Constructor
*/
public function __construct($name = null)
{
parent::__construct('databox:list');
$this->setDescription('List all databox in Phraseanet')
->setHelp('');
return $this;
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
try {
$databoxes = array_map(function (\databox $databox) {
return $this->listDatabox($databox);
}, $this->container->getApplicationBox()->get_databoxes());
$table = $this->getHelperSet()->get('table');
$table
->setHeaders(['id', 'name', 'alias'])
->setRows($databoxes)
->render($output);
} catch (\Exception $e) {
$output->writeln('<error>Listing databox failed : '.$e->getMessage().'</error>');
}
return 0;
}
private function listDatabox(\databox $databox)
{
return [
$databox->get_sbas_id(),
$databox->get_dbname(),
$databox->get_viewname()
];
}
}