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 * @var ProcessHelper
*/ */
private $processHelper; private $processHelper;
/**
* @var string
*/
private $importedInstallationPath;
/** /**
* @var WriterInterface * @var WriterInterface
*/ */
@ -154,8 +158,8 @@ class InstallCommand extends Command
// Ask the user for the older shlink path // Ask the user for the older shlink path
$keepAsking = true; $keepAsking = true;
do { do {
$installationPath = $this->ask('Previous shlink installation path from which to import config'); $this->importedInstallationPath = $this->ask('Previous shlink installation path from which to import config');
$configFile = $installationPath . '/' . self::GENERATED_CONFIG_PATH; $configFile = $this->importedInstallationPath . '/' . self::GENERATED_CONFIG_PATH;
$configExists = file_exists($configFile); $configExists = file_exists($configFile);
if (! $configExists) { if (! $configExists) {
@ -185,6 +189,14 @@ class InstallCommand extends Command
'<question>Do you want to keep imported database config? (Y/n):</question> ' '<question>Do you want to keep imported database config? (Y/n):</question> '
)); ));
if ($keepConfig) { 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; return;
} }
} }

View file

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