Fix Auto-Installer

This commit is contained in:
Philipp Holzer 2019-09-23 12:47:58 +02:00
parent c0afa761ac
commit ca36ea17f9
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
2 changed files with 30 additions and 20 deletions

View file

@ -129,16 +129,13 @@ HELP;
$config_file = $this->getOption(['f', 'file']); $config_file = $this->getOption(['f', 'file']);
if (!empty($config_file)) { if (!empty($config_file)) {
if ($config_file != 'config' . DIRECTORY_SEPARATOR . 'local.config.php') {
// Copy config file if (!file_exists($config_file)) {
$this->out("Copying config file...\n"); throw new RuntimeException("ERROR: Config file does not exist.\n");
if (!copy($basePathConf . DIRECTORY_SEPARATOR . $config_file, $basePathConf . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '" . $basePathConf . "'" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.config.php' manually.\n");
}
} }
//reload the config cache //reload the config cache
$loader = new ConfigFileLoader($basePathConf); $loader = new ConfigFileLoader($config_file);
$loader->setupCache($configCache); $loader->setupCache($configCache);
} else { } else {
@ -195,7 +192,7 @@ HELP;
$installer->createConfig($configCache); $installer->createConfig($configCache);
} }
$this->out(" Complete!\n\n"); $this->out("Complete!\n\n");
// Check database connection // Check database connection
$this->out("Checking database...\n"); $this->out("Checking database...\n");
@ -219,6 +216,14 @@ HELP;
throw new RuntimeException($errorMessage); throw new RuntimeException($errorMessage);
} }
if (!empty($config_file) && $config_file != 'config' . DIRECTORY_SEPARATOR . 'local.config.php') {
// Copy config file
$this->out("Copying config file...\n");
if (!copy($basePathConf . DIRECTORY_SEPARATOR . $config_file, $basePathConf . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '" . $basePathConf . "'" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.config.php' manually.\n");
}
}
$this->out(" Complete!\n\n"); $this->out(" Complete!\n\n");
// Install theme // Install theme

View file

@ -90,9 +90,12 @@ class Database
public function connect() public function connect()
{ {
if (!is_null($this->connection) && $this->connected()) { if (!is_null($this->connection) && $this->connected()) {
return true; return $this->connected;
} }
// Reset connected state
$this->connected = false;
$port = 0; $port = 0;
$serveraddr = trim($this->configCache->get('database', 'hostname')); $serveraddr = trim($this->configCache->get('database', 'hostname'));
$serverdata = explode(':', $serveraddr); $serverdata = explode(':', $serveraddr);
@ -187,19 +190,20 @@ class Database
*/ */
public function disconnect() public function disconnect()
{ {
if (is_null($this->connection)) { if (!is_null($this->connection)) {
return; switch ($this->driver) {
case 'pdo':
$this->connection = null;
break;
case 'mysqli':
$this->connection->close();
$this->connection = null;
break;
}
} }
switch ($this->driver) { $this->driver = null;
case 'pdo': $this->connected = false;
$this->connection = null;
break;
case 'mysqli':
$this->connection->close();
$this->connection = null;
break;
}
} }
/** /**
@ -369,6 +373,7 @@ class Database
$connected = $this->connection->ping(); $connected = $this->connection->ping();
break; break;
} }
return $connected; return $connected;
} }