diff --git a/bin/console b/bin/console index f62713e419..95331f549e 100755 --- a/bin/console +++ b/bin/console @@ -23,7 +23,9 @@ 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\Databox\ListDataboxCommand; use Alchemy\Phrasea\Command\MailTest; use Alchemy\Phrasea\Command\Compile\Configuration; use Alchemy\Phrasea\Command\RecordAdd; @@ -109,6 +111,9 @@ $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 ListDataboxCommand('databox:list')); $cli->command(new CreateDataboxCommand('databox:create')); $cli->command(new UserListCommand('user:list')); 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 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() + ]; + } + +}