From 211d33ff46a4f25207529aff32c40fb51dc92142 Mon Sep 17 00:00:00 2001 From: aynsix Date: Thu, 20 Feb 2020 15:52:05 +0300 Subject: [PATCH 1/2] command databox:list --- bin/console | 3 + .../Command/Databox/ListDataboxCommand.php | 62 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 lib/Alchemy/Phrasea/Command/Databox/ListDataboxCommand.php diff --git a/bin/console b/bin/console index 552cb672d0..03f671720f 100755 --- a/bin/console +++ b/bin/console @@ -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')); diff --git a/lib/Alchemy/Phrasea/Command/Databox/ListDataboxCommand.php b/lib/Alchemy/Phrasea/Command/Databox/ListDataboxCommand.php new file mode 100644 index 0000000000..49775437d5 --- /dev/null +++ b/lib/Alchemy/Phrasea/Command/Databox/ListDataboxCommand.php @@ -0,0 +1,62 @@ +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('Listing databox failed : '.$e->getMessage().''); + } + + return 0; + } + + private function listDatabox(\databox $databox) + { + return [ + $databox->get_sbas_id(), + $databox->get_dbname(), + $databox->get_viewname() + ]; + } + +} From ac17ca616ab98322a000e6de33ba9ebb4ca3f694 Mon Sep 17 00:00:00 2001 From: aynsix Date: Thu, 20 Feb 2020 16:16:30 +0300 Subject: [PATCH 2/2] command collection:list --- bin/console | 3 + .../Collection/ListCollectionCommand.php | 76 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 lib/Alchemy/Phrasea/Command/Collection/ListCollectionCommand.php diff --git a/bin/console b/bin/console index 552cb672d0..66c0450c79 100755 --- a/bin/console +++ b/bin/console @@ -23,6 +23,7 @@ use Alchemy\Phrasea\Command\SearchEngine\IndexPopulateCommand; use Alchemy\Phrasea\Command\Thesaurus\FindConceptsCommand; use Alchemy\Phrasea\Core\Version; use Alchemy\Phrasea\Command\CreateCollection; +use Alchemy\Phrasea\Command\Collection\ListCollectionCommand; use Alchemy\Phrasea\Command\Databox\CreateDataboxCommand; use Alchemy\Phrasea\Command\MailTest; use Alchemy\Phrasea\Command\Compile\Configuration; @@ -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 ListCollectionCommand('collection:list')); + $cli->command(new CreateDataboxCommand('databox:create')); $cli->command(new RecordAdd('records:add')); diff --git a/lib/Alchemy/Phrasea/Command/Collection/ListCollectionCommand.php b/lib/Alchemy/Phrasea/Command/Collection/ListCollectionCommand.php new file mode 100644 index 0000000000..e76796e8b7 --- /dev/null +++ b/lib/Alchemy/Phrasea/Command/Collection/ListCollectionCommand.php @@ -0,0 +1,76 @@ +setDescription('List all collection in Phraseanet') + ->addOption('databox_id', 'd', InputOption::VALUE_REQUIRED, 'The id of the databox to list collection') + ->setHelp(''); + return $this; + } + protected function doExecute(InputInterface $input, OutputInterface $output) + { + try { + $databox = $this->container->findDataboxById($input->getOption('databox_id')); + $collections = $this->listDataboxCollections($databox); + + $table = $this->getHelperSet()->get('table'); + $table + ->setHeaders(['id local for API', 'id distant', 'name','label','status','total records']) + ->setRows($collections) + ->render($output); + } catch (\Exception $e) { + $output->writeln("{$e->getMessage()}"); + } + return 0; + } + + private function listDataboxCollections(\databox $databox) + { + return array_map(function (\collection $collection) { + return $this->listCollection($collection); + }, array_merge($databox->get_collections(),$this->getUnabledCollection($databox->get_activable_colls()))); + } + + private function getUnabledCollection($collections) + { + return array_map(function ($colId){ + return \collection::getByBaseId($this->container, $colId); + },$collections); + + } + + private function listCollection(\collection $collection) + { + return [ + $collection->get_base_id(), + $collection->get_coll_id(), + $collection->get_name(), + 'en: ' . $collection->get_label('en') . + ', de: ' . $collection->get_label('de') . + ', fr: ' . $collection->get_label('fr') . + ', nl: ' . $collection->get_label('nl'), + ($collection->is_active()) ? 'enabled' : 'disabled', + $collection->get_record_amount() + ]; + } +} \ No newline at end of file