diff --git a/module/CLI/src/Command/Install/AbstractInstallCommand.php b/module/CLI/src/Command/Install/AbstractInstallCommand.php
index 5c271231..f6341627 100644
--- a/module/CLI/src/Command/Install/AbstractInstallCommand.php
+++ b/module/CLI/src/Command/Install/AbstractInstallCommand.php
@@ -11,6 +11,7 @@ use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
+use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
use Zend\Config\Writer\WriterInterface;
@@ -24,6 +25,7 @@ abstract class AbstractInstallCommand extends Command
'SQLite' => 'pdo_sqlite',
];
const SUPPORTED_LANGUAGES = ['en', 'es'];
+ const GENERATED_CONFIG_PATH = 'config/params/generated_config.php';
/**
* @var InputInterface
@@ -86,9 +88,15 @@ abstract class AbstractInstallCommand extends Command
' Failed! You will have to manually delete the data/cache/app_config.php file to get'
. ' new config applied.'
);
+ return;
}
}
+ // If running update command, ask the user to import previous config
+ if ($this->isUpdate()) {
+ $this->importConfig();
+ }
+
// Ask for custom config params
$params['DATABASE'] = $this->askDatabase();
$params['URL_SHORTENER'] = $this->askUrlShortener();
@@ -97,7 +105,7 @@ abstract class AbstractInstallCommand extends Command
// Generate config params files
$config = $this->buildAppConfig($params);
- $this->configWriter->toFile('config/params/generated_config.php', $config, false);
+ $this->configWriter->toFile(self::GENERATED_CONFIG_PATH, $config, false);
$output->writeln(['Custom configuration properly generated!', '']);
// If current command is not update, generate database
@@ -124,6 +132,35 @@ abstract class AbstractInstallCommand extends Command
}
}
+ protected function importConfig()
+ {
+ // Ask the user if he/she wants to import an older configuration
+ $importConfig = $this->questionHelper->ask($this->input, $this->output, new ConfirmationQuestion(
+ 'Do you want to import previous configuration? (Y/n): '
+ ));
+ if (! $importConfig) {
+ return;
+ }
+
+ // Ask the user for the older shlink path
+ $keepAsking = true;
+ do {
+ $installationPath = $this->ask('Previous shlink installation path from which to import config');
+ $configFile = $installationPath . '/' . self::GENERATED_CONFIG_PATH;
+ $configExists = file_exists($configFile);
+
+ if (! $configExists) {
+ $keepAsking = $this->questionHelper->ask($this->input, $this->output, new ConfirmationQuestion(
+ 'Provided path does not seem to be a valid shlink root path. '
+ . 'Do you want to try another path? (Y/n): '
+ ));
+ }
+ } while (! $configExists && $keepAsking);
+
+ // Read the config file
+ $previousConfig = include $configFile;
+ }
+
protected function askDatabase()
{
$params = [];