From d7e3c8fc0c5bb30f6bf2eca0dd829fe16d13bb77 Mon Sep 17 00:00:00 2001 From: aynsix Date: Wed, 26 Mar 2025 19:36:06 +0300 Subject: [PATCH 1/4] abort install if db table exist --- lib/Alchemy/Phrasea/Command/Setup/Install.php | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/Alchemy/Phrasea/Command/Setup/Install.php b/lib/Alchemy/Phrasea/Command/Setup/Install.php index ab67337d57..b1f8dc460e 100644 --- a/lib/Alchemy/Phrasea/Command/Setup/Install.php +++ b/lib/Alchemy/Phrasea/Command/Setup/Install.php @@ -61,6 +61,7 @@ public function __construct($name, $structureTemplate) ->addOption('scheduler-locks-path', null, InputOption::VALUE_OPTIONAL, 'Path to scheduler-locks repository', __DIR__ . '/../../../../../tmp/locks') ->addOption('worker-tmp-files', null, InputOption::VALUE_OPTIONAL, 'Path to worker-tmp-files repository', __DIR__ . '/../../../../../tmp') ->addOption('yes', 'y', InputOption::VALUE_NONE, 'Answer yes to all questions') + ->addOption('force', 'f', InputOption::VALUE_NONE, 'force to continue installation') ->setHelp("Phraseanet can only be installed on 64 bits PHP."); ; @@ -118,7 +119,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output) " ); - if (!$input->getOption('yes') && !$input->getOption('appbox')) { + if (!$input->getOption('yes') && !$input->getOption('force') && !$input->getOption('appbox')) { $continue = $dialog->askConfirmation($output, 'Do you have these two DB handy ? (N/y)', false); if (!$continue) { @@ -130,16 +131,30 @@ protected function doExecute(InputInterface $input, OutputInterface $output) $serverName = $this->getServerName($input, $output, $dialog); + /** @var Connection $abConn */ $abConn = $this->getABConn($input, $output, $dialog, $serverName); if(!$abConn) { return 1; // no ab is fatal } + if (!$input->getOption('force') && $abConn->getSchemaManager()->tablesExist(['users'])) { + $output->writeln("Database table already exist in appbox! installation abort"); + + return 1; + } + list($dbConn, $templateName) = $this->getDBConn($input, $output, $abConn, $dialog); + + if (!$input->getOption('force') && $dbConn->getSchemaManager()->tablesExist(['record'])) { + $output->writeln("Database table already exist in databox! installation abort"); + + return 1; + } + list($email, $password) = $this->getCredentials($input, $output, $dialog); $dataPath = $this->getDataPath($input, $output, $dialog); - if (! $input->getOption('yes')) { + if (!$input->getOption('yes') && !$input->getOption('force')) { $output->writeln("--- ElasticSearch connection settings ---"); } @@ -154,7 +169,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output) $output->writeln(''); - if (!$input->getOption('yes')) { + if (!$input->getOption('yes') && !$input->getOption('force')) { $continue = $dialog->askConfirmation($output, "Phraseanet is going to be installed, continue ? (N/y)", false); if (!$continue) { @@ -341,7 +356,7 @@ private function getDataPath(InputInterface $input, OutputInterface $output, Dia { $dataPath = $input->getOption('data-path'); - if (!$input->getOption('yes')) { + if (!$input->getOption('yes') && !$input->getOption('force')) { $continue = $dialog->askConfirmation($output, 'Would you like to change default data-path ? (N/y)', false); if ($continue) { @@ -362,7 +377,7 @@ private function getServerName(InputInterface $input, OutputInterface $output, D { $serverName = $input->getOption('server-name'); - if (!$serverName && !$input->getOption('yes')) { + if (!$serverName && !$input->getOption('yes') && !$input->getOption('force')) { do { $serverName = $dialog->ask($output, 'Please provide the server name : ', null); } while (!$serverName); @@ -380,7 +395,7 @@ private function getESHost(InputInterface $input, OutputInterface $output, Dialo $host = $input->getOption('es-host'); $port = (int) $input->getOption('es-port'); - if (! $input->getOption('yes')) { + if (! $input->getOption('yes') && !$input->getOption('force')) { while (! $host) { $host = $dialog->ask($output, 'ElasticSearch server host : ', null); }; @@ -397,7 +412,7 @@ private function getESIndexName(InputInterface $input, OutputInterface $output, { $index = $input->getOption('es-index'); - if (! $input->getOption('yes')) { + if (!$input->getOption('yes') && !$input->getOption('force')) { $index = $dialog->ask($output, 'ElasticSearch server index name (blank to autogenerate) : ', null); } From 40d7ef6e9bd51e14fb12e7658cf61bab1e75f764 Mon Sep 17 00:00:00 2001 From: aynsix Date: Wed, 26 Mar 2025 19:51:25 +0300 Subject: [PATCH 2/4] fix test --- docker/phraseanet/setup/init-test-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/phraseanet/setup/init-test-install.sh b/docker/phraseanet/setup/init-test-install.sh index 3bb0696794..a63e210887 100755 --- a/docker/phraseanet/setup/init-test-install.sh +++ b/docker/phraseanet/setup/init-test-install.sh @@ -28,7 +28,7 @@ sleep 10 --lazaret-path=$PHRASEANET_LAZARET_DIR \ --caption-path=$PHRASEANET_CAPTION_DIR \ --worker-tmp-files=$PHRASEANET_WORKER_TMP \ - --data-path=/var/alchemy/Phraseanet/datas -y + --data-path=/var/alchemy/Phraseanet/datas -f done /var/alchemy/Phraseanet/bin/setup system:config set workers.queue.worker-queue.registry alchemy_worker.queue_registry From 59ac34687ef3ad0e5e3c6d95b0542bb6022a80fb Mon Sep 17 00:00:00 2001 From: aynsix Date: Sat, 29 Mar 2025 08:31:44 +0300 Subject: [PATCH 3/4] unneeded --- lib/Alchemy/Phrasea/Command/Setup/Install.php | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/lib/Alchemy/Phrasea/Command/Setup/Install.php b/lib/Alchemy/Phrasea/Command/Setup/Install.php index b1f8dc460e..ab71cf2cc4 100644 --- a/lib/Alchemy/Phrasea/Command/Setup/Install.php +++ b/lib/Alchemy/Phrasea/Command/Setup/Install.php @@ -94,30 +94,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output) /** @var DialogHelper $dialog */ $dialog = $this->getHelperSet()->get('dialog'); - $output->writeln(" - ,-._.-._.-._.-._.-. - `-. ,-' - .----------------------------------------------. | | -| | | | -| Hello ! | | | -| | | | -| You are on your way to install Phraseanet, | ,';\".________.-. -| You will need access to 2 MySQL databases. | ;';_' )] -| | ; `-| -| `. `T- | - `----------------------------------------------._ \ | | - `-; | | - |..________..-| - /\/ |________..| - ,'`./ >,( | - \_.-|_/,-/ ii | | - `.\"' `-/ .-\"\"\"|| | - /`^\"-; | ||____| - / / `.__/ | || - / | || - | || -" - ); + $output->writeln("You are on your way to install Phraseanet, You will need access to 2 MySQL databases."); if (!$input->getOption('yes') && !$input->getOption('force') && !$input->getOption('appbox')) { $continue = $dialog->askConfirmation($output, 'Do you have these two DB handy ? (N/y)', false); From 301cd157cfebd77a2bfa821b09b72cd8b5f53d44 Mon Sep 17 00:00:00 2001 From: Nicolas Maillat Date: Sat, 29 Mar 2025 11:26:31 +0100 Subject: [PATCH 4/4] highlight install message --- lib/Alchemy/Phrasea/Command/Setup/Install.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Alchemy/Phrasea/Command/Setup/Install.php b/lib/Alchemy/Phrasea/Command/Setup/Install.php index ab71cf2cc4..863b77c600 100644 --- a/lib/Alchemy/Phrasea/Command/Setup/Install.php +++ b/lib/Alchemy/Phrasea/Command/Setup/Install.php @@ -94,7 +94,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output) /** @var DialogHelper $dialog */ $dialog = $this->getHelperSet()->get('dialog'); - $output->writeln("You are on your way to install Phraseanet, You will need access to 2 MySQL databases."); + $output->writeln(" --- You are on your way to install Phraseanet, You will need access to 2 MySQL databases. --- "); if (!$input->getOption('yes') && !$input->getOption('force') && !$input->getOption('appbox')) { $continue = $dialog->askConfirmation($output, 'Do you have these two DB handy ? (N/y)', false); @@ -115,7 +115,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output) } if (!$input->getOption('force') && $abConn->getSchemaManager()->tablesExist(['users'])) { - $output->writeln("Database table already exist in appbox! installation abort"); + $output->writeln("(*) Database table already exist in appbox! installation abort"); return 1; } @@ -123,7 +123,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output) list($dbConn, $templateName) = $this->getDBConn($input, $output, $abConn, $dialog); if (!$input->getOption('force') && $dbConn->getSchemaManager()->tablesExist(['record'])) { - $output->writeln("Database table already exist in databox! installation abort"); + $output->writeln("(*) Database table already exist in databox! installation abort"); return 1; }