Updated instalation script to import sqlte database file when importing the rets of the config

This commit is contained in:
Alejandro Celaya 2017-07-04 20:01:42 +02:00
parent cc688fa3ce
commit 102f5c4e12
2 changed files with 17 additions and 3 deletions

View File

@ -44,6 +44,10 @@ class InstallCommand extends Command
* @var ProcessHelper
*/
private $processHelper;
/**
* @var string
*/
private $importedInstallationPath;
/**
* @var WriterInterface
*/
@ -154,8 +158,8 @@ class InstallCommand extends Command
// 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;
$this->importedInstallationPath = $this->ask('Previous shlink installation path from which to import config');
$configFile = $this->importedInstallationPath . '/' . self::GENERATED_CONFIG_PATH;
$configExists = file_exists($configFile);
if (! $configExists) {
@ -185,6 +189,14 @@ class InstallCommand extends Command
'<question>Do you want to keep imported database config? (Y/n):</question> '
));
if ($keepConfig) {
// If the user selected to keep DB config and is configured to use sqlite, copy DB file
if ($config->getDatabase()['DRIVER'] === self::DATABASE_DRIVERS['SQLite']) {
copy(
$this->importedInstallationPath . '/' . CustomizableAppConfig::SQLITE_DB_PATH,
CustomizableAppConfig::SQLITE_DB_PATH
);
}
return;
}
}

View File

@ -5,6 +5,8 @@ use Zend\Stdlib\ArraySerializableInterface;
final class CustomizableAppConfig implements ArraySerializableInterface
{
const SQLITE_DB_PATH = 'data/database.sqlite';
/**
* @var array
*/
@ -213,7 +215,7 @@ final class CustomizableAppConfig implements ArraySerializableInterface
// Build dynamic database config based on selected driver
if ($this->database['DRIVER'] === 'pdo_sqlite') {
$config['entity_manager']['connection']['path'] = 'data/database.sqlite';
$config['entity_manager']['connection']['path'] = self::SQLITE_DB_PATH;
} else {
$config['entity_manager']['connection']['user'] = $this->database['USER'];
$config['entity_manager']['connection']['password'] = $this->database['PASSWORD'];