Skip to content

Commit 1f56bfa

Browse files
aynsixnmaillat
andauthored
PHRAS-4146 bin/setup system:install - abort app installation if mysql db is not empty (#4599)
* abort install if db table exist * fix test * unneeded * highlight install message --------- Co-authored-by: Nicolas Maillat <[email protected]>
1 parent 5c25757 commit 1f56bfa

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

docker/phraseanet/setup/init-test-install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ sleep 10
2828
--lazaret-path=$PHRASEANET_LAZARET_DIR \
2929
--caption-path=$PHRASEANET_CAPTION_DIR \
3030
--worker-tmp-files=$PHRASEANET_WORKER_TMP \
31-
--data-path=/var/alchemy/Phraseanet/datas -y
31+
--data-path=/var/alchemy/Phraseanet/datas -f
3232
done
3333

3434
/var/alchemy/Phraseanet/bin/setup system:config set workers.queue.worker-queue.registry alchemy_worker.queue_registry

lib/Alchemy/Phrasea/Command/Setup/Install.php

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function __construct($name, $structureTemplate)
6161
->addOption('scheduler-locks-path', null, InputOption::VALUE_OPTIONAL, 'Path to scheduler-locks repository', __DIR__ . '/../../../../../tmp/locks')
6262
->addOption('worker-tmp-files', null, InputOption::VALUE_OPTIONAL, 'Path to worker-tmp-files repository', __DIR__ . '/../../../../../tmp')
6363
->addOption('yes', 'y', InputOption::VALUE_NONE, 'Answer yes to all questions')
64+
->addOption('force', 'f', InputOption::VALUE_NONE, 'force to continue installation')
6465
->setHelp("Phraseanet can only be installed on 64 bits PHP.");
6566
;
6667

@@ -93,32 +94,9 @@ protected function doExecute(InputInterface $input, OutputInterface $output)
9394
/** @var DialogHelper $dialog */
9495
$dialog = $this->getHelperSet()->get('dialog');
9596

96-
$output->writeln("<comment>
97-
,-._.-._.-._.-._.-.
98-
`-. ,-'
99-
.----------------------------------------------. | |
100-
| | | |
101-
| Hello ! | | |
102-
| | | |
103-
| You are on your way to install Phraseanet, | ,';\".________.-.
104-
| You will need access to 2 MySQL databases. | ;';_' )]
105-
| | ; `-|
106-
| `. `T- |
107-
`----------------------------------------------._ \ | |
108-
`-; | |
109-
|..________..-|
110-
/\/ |________..|
111-
,'`./ >,( |
112-
\_.-|_/,-/ ii | |
113-
`.\"' `-/ .-\"\"\"|| |
114-
/`^\"-; | ||____|
115-
/ / `.__/ | ||
116-
/ | ||
117-
| ||
118-
</comment>"
119-
);
120-
121-
if (!$input->getOption('yes') && !$input->getOption('appbox')) {
97+
$output->writeln("<comment> --- You are on your way to install Phraseanet, You will need access to 2 MySQL databases. --- </comment>");
98+
99+
if (!$input->getOption('yes') && !$input->getOption('force') && !$input->getOption('appbox')) {
122100
$continue = $dialog->askConfirmation($output, 'Do you have these two DB handy ? (N/y)', false);
123101

124102
if (!$continue) {
@@ -130,16 +108,30 @@ protected function doExecute(InputInterface $input, OutputInterface $output)
130108

131109
$serverName = $this->getServerName($input, $output, $dialog);
132110

111+
/** @var Connection $abConn */
133112
$abConn = $this->getABConn($input, $output, $dialog, $serverName);
134113
if(!$abConn) {
135114
return 1; // no ab is fatal
136115
}
137116

117+
if (!$input->getOption('force') && $abConn->getSchemaManager()->tablesExist(['users'])) {
118+
$output->writeln("<error>(*) Database table already exist in appbox! installation abort</error>");
119+
120+
return 1;
121+
}
122+
138123
list($dbConn, $templateName) = $this->getDBConn($input, $output, $abConn, $dialog);
124+
125+
if (!$input->getOption('force') && $dbConn->getSchemaManager()->tablesExist(['record'])) {
126+
$output->writeln("<error>(*) Database table already exist in databox! installation abort</error>");
127+
128+
return 1;
129+
}
130+
139131
list($email, $password) = $this->getCredentials($input, $output, $dialog);
140132
$dataPath = $this->getDataPath($input, $output, $dialog);
141133

142-
if (! $input->getOption('yes')) {
134+
if (!$input->getOption('yes') && !$input->getOption('force')) {
143135
$output->writeln("<info>--- ElasticSearch connection settings ---</info>");
144136
}
145137

@@ -154,7 +146,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output)
154146

155147
$output->writeln('');
156148

157-
if (!$input->getOption('yes')) {
149+
if (!$input->getOption('yes') && !$input->getOption('force')) {
158150
$continue = $dialog->askConfirmation($output, "<question>Phraseanet is going to be installed, continue ? (N/y)</question>", false);
159151

160152
if (!$continue) {
@@ -341,7 +333,7 @@ private function getDataPath(InputInterface $input, OutputInterface $output, Dia
341333
{
342334
$dataPath = $input->getOption('data-path');
343335

344-
if (!$input->getOption('yes')) {
336+
if (!$input->getOption('yes') && !$input->getOption('force')) {
345337
$continue = $dialog->askConfirmation($output, 'Would you like to change default data-path ? (N/y)', false);
346338

347339
if ($continue) {
@@ -362,7 +354,7 @@ private function getServerName(InputInterface $input, OutputInterface $output, D
362354
{
363355
$serverName = $input->getOption('server-name');
364356

365-
if (!$serverName && !$input->getOption('yes')) {
357+
if (!$serverName && !$input->getOption('yes') && !$input->getOption('force')) {
366358
do {
367359
$serverName = $dialog->ask($output, 'Please provide the server name : ', null);
368360
} while (!$serverName);
@@ -380,7 +372,7 @@ private function getESHost(InputInterface $input, OutputInterface $output, Dialo
380372
$host = $input->getOption('es-host');
381373
$port = (int) $input->getOption('es-port');
382374

383-
if (! $input->getOption('yes')) {
375+
if (! $input->getOption('yes') && !$input->getOption('force')) {
384376
while (! $host) {
385377
$host = $dialog->ask($output, 'ElasticSearch server host : ', null);
386378
};
@@ -397,7 +389,7 @@ private function getESIndexName(InputInterface $input, OutputInterface $output,
397389
{
398390
$index = $input->getOption('es-index');
399391

400-
if (! $input->getOption('yes')) {
392+
if (!$input->getOption('yes') && !$input->getOption('force')) {
401393
$index = $dialog->ask($output, 'ElasticSearch server index name (blank to autogenerate) : ', null);
402394
}
403395

0 commit comments

Comments
 (0)