mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-23 21:27:44 +03:00
Added process to import previous configuration when updating shlink
This commit is contained in:
parent
1fe2e6f6bd
commit
f9c56d7cb1
1 changed files with 38 additions and 1 deletions
|
@ -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
|
|||
' <error>Failed!</error> 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(['<info>Custom configuration properly generated!</info>', '']);
|
||||
|
||||
// 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(
|
||||
'<question>Do you want to import previous configuration? (Y/n):</question> '
|
||||
));
|
||||
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. '
|
||||
. '<question>Do you want to try another path? (Y/n):</question> '
|
||||
));
|
||||
}
|
||||
} while (! $configExists && $keepAsking);
|
||||
|
||||
// Read the config file
|
||||
$previousConfig = include $configFile;
|
||||
}
|
||||
|
||||
protected function askDatabase()
|
||||
{
|
||||
$params = [];
|
||||
|
|
Loading…
Reference in a new issue