From 102f5c4e12373ea968ce7305c5cff459c4e282a6 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 4 Jul 2017 20:01:42 +0200 Subject: [PATCH] Updated instalation script to import sqlte database file when importing the rets of the config --- .../CLI/src/Command/Install/InstallCommand.php | 16 ++++++++++++++-- module/CLI/src/Model/CustomizableAppConfig.php | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/module/CLI/src/Command/Install/InstallCommand.php b/module/CLI/src/Command/Install/InstallCommand.php index 2ff9e9da..d036c78e 100644 --- a/module/CLI/src/Command/Install/InstallCommand.php +++ b/module/CLI/src/Command/Install/InstallCommand.php @@ -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 'Do you want to keep imported database config? (Y/n): ' )); 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; } } diff --git a/module/CLI/src/Model/CustomizableAppConfig.php b/module/CLI/src/Model/CustomizableAppConfig.php index 4b7043c0..a1f48bbd 100644 --- a/module/CLI/src/Model/CustomizableAppConfig.php +++ b/module/CLI/src/Model/CustomizableAppConfig.php @@ -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'];