]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #7656 from annando/redir-loop
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 23 Sep 2019 22:56:50 +0000 (18:56 -0400)
committerGitHub <noreply@github.com>
Mon, 23 Sep 2019 22:56:50 +0000 (18:56 -0400)
Fix "redir" loop

src/Console/AutomaticInstallation.php
src/Database/Database.php

index 0f1e7a742f1864e191a75cd73144020f400fb21d..8815b98799fbb854ced93fc0d124c71b09f83cd1 100644 (file)
@@ -129,16 +129,13 @@ HELP;
                $config_file = $this->getOption(['f', 'file']);
 
                if (!empty($config_file)) {
-                       if ($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");
-                               }
+
+                       if (!file_exists($config_file)) {
+                               throw new RuntimeException("ERROR: Config file does not exist.\n");
                        }
 
                        //reload the config cache
-                       $loader = new ConfigFileLoader($basePathConf);
+                       $loader = new ConfigFileLoader($config_file);
                        $loader->setupCache($configCache);
 
                } else {
@@ -195,7 +192,7 @@ HELP;
                        $installer->createConfig($configCache);
                }
 
-               $this->out(" Complete!\n\n");
+               $this->out("Complete!\n\n");
 
                // Check database connection
                $this->out("Checking database...\n");
@@ -219,6 +216,14 @@ HELP;
                        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");
 
                // Install theme
index d13b52848d311ff0c49e305bd482c7937e3f0ebb..813d4e98538decbeb08e01c5d5cf9357229939cf 100644 (file)
@@ -90,9 +90,12 @@ class Database
        public function connect()
        {
                if (!is_null($this->connection) && $this->connected()) {
-                       return true;
+                       return $this->connected;
                }
 
+               // Reset connected state
+               $this->connected = false;
+
                $port       = 0;
                $serveraddr = trim($this->configCache->get('database', 'hostname'));
                $serverdata = explode(':', $serveraddr);
@@ -187,19 +190,20 @@ class Database
         */
        public function disconnect()
        {
-               if (is_null($this->connection)) {
-                       return;
+               if (!is_null($this->connection)) {
+                       switch ($this->driver) {
+                               case 'pdo':
+                                       $this->connection = null;
+                                       break;
+                               case 'mysqli':
+                                       $this->connection->close();
+                                       $this->connection = null;
+                                       break;
+                       }
                }
 
-               switch ($this->driver) {
-                       case 'pdo':
-                               $this->connection = null;
-                               break;
-                       case 'mysqli':
-                               $this->connection->close();
-                               $this->connection = null;
-                               break;
-               }
+               $this->driver    = null;
+               $this->connected = false;
        }
 
        /**
@@ -369,6 +373,7 @@ class Database
                                $connected = $this->connection->ping();
                                break;
                }
+
                return $connected;
        }