Merge branch 'master' into PHRAS-1629-collection-list-jsonformat

This commit is contained in:
Nicolas Maillat
2020-02-21 15:45:46 +01:00
committed by GitHub
2 changed files with 39 additions and 18 deletions

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Command\Databox;
use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class ListDataboxCommand extends Command class ListDataboxCommand extends Command
@@ -25,6 +26,7 @@ class ListDataboxCommand extends Command
parent::__construct('databox:list'); parent::__construct('databox:list');
$this->setDescription('List all databox in Phraseanet') $this->setDescription('List all databox in Phraseanet')
->addOption('jsonformat', null, InputOption::VALUE_NONE, 'Output in json format')
->setHelp(''); ->setHelp('');
return $this; return $this;
@@ -33,15 +35,23 @@ class ListDataboxCommand extends Command
protected function doExecute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
try { try {
$jsonformat = $input->getOption('jsonformat');
$databoxes = array_map(function (\databox $databox) { $databoxes = array_map(function (\databox $databox) {
return $this->listDatabox($databox); return $this->listDatabox($databox);
}, $this->container->getApplicationBox()->get_databoxes()); }, $this->container->getApplicationBox()->get_databoxes());
if ($jsonformat) {
foreach ($databoxes as $databox) {
$databoxList[] = array_combine(['id', 'name', 'alias'], $databox);
}
echo json_encode($databoxList);
} else {
$table = $this->getHelperSet()->get('table'); $table = $this->getHelperSet()->get('table');
$table $table
->setHeaders(['id', 'name', 'alias']) ->setHeaders(['id', 'name', 'alias'])
->setRows($databoxes) ->setRows($databoxes)
->render($output); ->render($output);
}
} catch (\Exception $e) { } catch (\Exception $e) {
$output->writeln('<error>Listing databox failed : '.$e->getMessage().'</error>'); $output->writeln('<error>Listing databox failed : '.$e->getMessage().'</error>');

View File

@@ -42,6 +42,7 @@ class UserListCommand extends Command
->addOption('application', null, InputOption::VALUE_NONE, 'List application of user work only if --user_id is set') ->addOption('application', null, InputOption::VALUE_NONE, 'List application of user work only if --user_id is set')
->addOption('right', null, InputOption::VALUE_NONE, 'Show right information') ->addOption('right', null, InputOption::VALUE_NONE, 'Show right information')
->addOption('adress', null, InputOption::VALUE_NONE, 'Show adress information') ->addOption('adress', null, InputOption::VALUE_NONE, 'Show adress information')
->addOption('jsonformat', null, InputOption::VALUE_NONE, 'Output in json format')
->setHelp(''); ->setHelp('');
return $this; return $this;
@@ -61,6 +62,7 @@ class UserListCommand extends Command
$created = $input->getOption('created'); $created = $input->getOption('created');
$updated = $input->getOption('updated'); $updated = $input->getOption('updated');
$withRight = $input->getOption('right'); $withRight = $input->getOption('right');
$jsonformat = $input->getOption('jsonformat');
$query = $this->container['phraseanet.user-query']; $query = $this->container['phraseanet.user-query'];
@@ -88,8 +90,13 @@ class UserListCommand extends Command
$showApplication = true; $showApplication = true;
} }
$userList[] = $this->listUser($user, $withAdress, $withRight); $userList[] = $this->listUser($user, $withAdress, $withRight);
$userListRaw[] = array_combine($this->headerTable($withAdress, $withRight), $this->listUser($user, $withAdress, $withRight));
} }
if ($jsonformat) {
echo json_encode($userListRaw);
} else {
$table = $this->getHelperSet()->get('table'); $table = $this->getHelperSet()->get('table');
$table $table
->setHeaders($this->headerTable($withAdress, $withRight)) ->setHeaders($this->headerTable($withAdress, $withRight))
@@ -97,6 +104,7 @@ class UserListCommand extends Command
->render($output); ->render($output);
; ;
if ($showApplication) { if ($showApplication) {
$applicationTable = $this->getHelperSet()->get('table'); $applicationTable = $this->getHelperSet()->get('table');
$applicationTable->setHeaders(array( $applicationTable->setHeaders(array(
@@ -105,6 +113,9 @@ class UserListCommand extends Command
))->setRows($this->getApplicationOfUser($users[0]))->render($output); ))->setRows($this->getApplicationOfUser($users[0]))->render($output);
} }
}
return 0; return 0;
} }