From bc488a421d7bfc6e1ef9a825426aa6e2a5e60376 Mon Sep 17 00:00:00 2001 From: aynsix Date: Mon, 18 Nov 2019 17:35:36 +0400 Subject: [PATCH] on system:install add elasticsearch informations options --- lib/Alchemy/Phrasea/Command/Setup/Install.php | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/Alchemy/Phrasea/Command/Setup/Install.php b/lib/Alchemy/Phrasea/Command/Setup/Install.php index 99dee9c15a..8e211a9284 100644 --- a/lib/Alchemy/Phrasea/Command/Setup/Install.php +++ b/lib/Alchemy/Phrasea/Command/Setup/Install.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Command\Setup; use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Core\Configuration\StructureTemplate; +use Alchemy\Phrasea\SearchEngine\Elastic\ElasticsearchOptions; use Doctrine\DBAL\Driver\Connection; use Symfony\Component\Console\Helper\DialogHelper; use Symfony\Component\Console\Input\ArrayInput; @@ -51,7 +52,9 @@ class Install extends Command ->addOption('db-template', null, InputOption::VALUE_OPTIONAL, 'Databox template (' . $this->structureTemplate->toString() . ')', null) ->addOption('data-path', null, InputOption::VALUE_OPTIONAL, 'Path to data repository', realpath(__DIR__ . '/../../../../../datas')) ->addOption('server-name', null, InputOption::VALUE_OPTIONAL, 'Server name') - ->addOption('indexer', null, InputOption::VALUE_OPTIONAL, 'Path to Phraseanet Indexer', 'auto') + ->addOption('es-host', null, InputOption::VALUE_OPTIONAL, 'ElasticSearch server HTTP host', 'localhost') + ->addOption('es-port', null, InputOption::VALUE_OPTIONAL, 'ElasticSearch server HTTP port', 9200) + ->addOption('es-index', null, InputOption::VALUE_OPTIONAL, 'ElasticSearch index name', null) ->addOption('yes', 'y', InputOption::VALUE_NONE, 'Answer yes to all questions'); return $this; @@ -121,6 +124,21 @@ class Install extends Command list($email, $password) = $this->getCredentials($input, $output, $dialog); $dataPath = $this->getDataPath($input, $output, $dialog); + if (! $input->getOption('yes')) { + $output->writeln("--- ElasticSearch connection settings ---"); + } + + list($esHost, $esPort) = $this->getESHost($input, $output, $dialog); + $esIndexName = $this->getESIndexName($input, $output, $dialog); + + $esOptions = ElasticsearchOptions::fromArray([ + 'host' => $esHost, + 'port' => $esPort, + 'index' => $esIndexName + ]); + + $output->writeln(''); + if (!$input->getOption('yes')) { $continue = $dialog->askConfirmation($output, "Phraseanet is going to be installed, continue ? (N/y)", false); @@ -132,6 +150,7 @@ class Install extends Command } $this->container['phraseanet.installer']->install($email, $password, $abConn, $serverName, $dataPath, $dbConn, $templateName, $this->detectBinaries()); + $this->container['conf']->set(['main', 'search-engine', 'options'], $esOptions->toArray()); if (null !== $this->getApplication()) { $command = $this->getApplication()->find('crossdomain:generate'); @@ -339,6 +358,35 @@ class Install extends Command return $serverName; } + private function getESHost(InputInterface $input, OutputInterface $output, DialogHelper $dialog) + { + $host = $input->getOption('es-host'); + $port = (int) $input->getOption('es-port'); + + if (! $input->getOption('yes')) { + while (! $host) { + $host = $dialog->ask($output, 'ElasticSearch server host : ', null); + }; + + while ($port <= 0 || $port >= 65535) { + $port = (int) $dialog->ask($output, 'ElasticSearch server port : ', null); + }; + } + + return [ $host, $port ]; + } + + private function getESIndexName(InputInterface $input, OutputInterface $output, DialogHelper $dialog) + { + $index = $input->getOption('es-index'); + + if (! $input->getOption('yes')) { + $index = $dialog->ask($output, 'ElasticSearch server index name (blank to autogenerate) : ', null); + } + + return $index; + } + private function detectBinaries() { return [