]> git.mxchange.org Git - friendica.git/commitdiff
Bugfixings
authorPhilipp Holzer <admin@philipp.info>
Tue, 30 Oct 2018 10:30:19 +0000 (11:30 +0100)
committerPhilipp Holzer <admin@philipp.info>
Tue, 30 Oct 2018 10:30:19 +0000 (11:30 +0100)
- moved testargs.php to util directory
- Switch Environment check before config at automatic install
- checkPHP() is now finding the PHP binary too
- Bugfixing checkPHP() & required returned wrong status
- removing not used $_POST['phpath'] in web installer

src/Core/Console/AutomaticInstallation.php
src/Core/Installer.php
src/Module/Install.php
testargs.php [deleted file]
tests/src/Core/Console/AutomaticInstallationConsoleTest.php
util/testargs.php [new file with mode: 0644]

index 491e826039bbf458d1e32ab626fc73fe644a46fc..294009ada015e5939955c550dbdc2b257de8d309 100644 (file)
@@ -78,6 +78,20 @@ HELP;
 
                $installer = new Installer();
 
+               $this->out(" Complete!\n\n");
+
+               // Check Environment
+               $this->out("Checking environment...\n");
+
+               $installer->resetChecks();
+
+               if (!$this->runBasicChecks($installer)) {
+                       $errorMessage = $this->extractErrors($installer->getChecks());
+                       throw new RuntimeException($errorMessage);
+               }
+
+               $this->out(" Complete!\n\n");
+
                // if a config file is set,
                $config_file = $this->getOption(['f', 'file']);
 
@@ -111,6 +125,10 @@ HELP;
                        $tz = $this->getOption(['T', 'tz'], (!empty('FRIENDICA_TZ')) ? getenv('FRIENDICA_TZ') : '');
                        $lang = $this->getOption(['L', 'lang'], (!empty('FRIENDICA_LANG')) ? getenv('FRIENDICA_LANG') : '');
 
+                       if (empty($php_path)) {
+                               $php_path = $installer->getPHPPath();
+                       }
+
                        $installer->createConfig(
                                $php_path,
                                $url_path,
@@ -127,18 +145,6 @@ HELP;
 
                $this->out(" Complete!\n\n");
 
-               // Check basic setup
-               $this->out("Checking basic setup...\n");
-
-               $installer->resetChecks();
-
-               if (!$this->runBasicChecks($installer)) {
-                       $errorMessage = $this->extractErrors($installer->getChecks());
-                       throw new RuntimeException($errorMessage);
-               }
-
-               $this->out(" Complete!\n\n");
-
                // Check database connection
                $this->out("Checking database...\n");
 
@@ -178,37 +184,38 @@ HELP;
        }
 
        /**
-        * @param Installer $install the Installer instance
+        * @param Installer $installer the Installer instance
         *
         * @return bool true if checks were successfully, otherwise false
         */
-       private function runBasicChecks(Installer $install)
+       private function runBasicChecks(Installer $installer)
        {
                $checked = true;
 
-               $install->resetChecks();
-               if (!$install->checkFunctions())                {
+               $installer->resetChecks();
+               if (!$installer->checkFunctions())              {
                        $checked = false;
                }
-               if (!$install->checkImagick()) {
+               if (!$installer->checkImagick()) {
                        $checked = false;
                }
-               if (!$install->checkLocalIni()) {
+               if (!$installer->checkLocalIni()) {
                        $checked = false;
                }
-               if (!$install->checkSmarty3()) {
+               if (!$installer->checkSmarty3()) {
                        $checked = false;
                }
-               if ($install->checkKeys()) {
+               if (!$installer->checkKeys()) {
                        $checked = false;
                }
 
+               $php_path = null;
                if (!empty(Config::get('config', 'php_path'))) {
-                       if (!$install->checkPHP(Config::get('config', 'php_path'), true)) {
-                               throw new RuntimeException(" ERROR: The php_path is not valid in the config.\n");
-                       }
-               } else {
-                       throw new RuntimeException(" ERROR: The php_path is not set in the config.\n");
+                       $php_path = Config::get('config', 'php_path');
+               }
+
+               if (!$installer->checkPHP($php_path, true)) {
+                       $checked = false;
                }
 
                $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
index 03d888b7ea00853091ab0bf9b97f96bcf22d63de..cb871e2dfba51e8a322a351fe82d8ce931aa1236 100644 (file)
@@ -26,6 +26,11 @@ class Installer
         */
        private $checks;
 
+       /**
+        * @var string The path to the PHP binary
+        */
+       private $phppath = null;
+
        /**
         * Returns all checks made
         *
@@ -36,6 +41,22 @@ class Installer
                return $this->checks;
        }
 
+       /**
+        * Returns the PHP path
+        *
+        * @return string the PHP Path
+        */
+       public function getPHPPath()
+       {
+               // if not set, determine the PHP path
+               if (!isset($this->phppath)) {
+                       $this->checkPHP();
+                       $this->resetChecks();
+               }
+
+               return $this->phppath;
+       }
+
        /**
         * Resets all checks
         */
@@ -197,11 +218,17 @@ class Installer
         */
        public function checkPHP($phppath = null, $required = false)
        {
-               $passed = $passed2 = $passed3 = false;
-               if (isset($phppath)) {
-                       $passed = file_exists($phppath);
-               } else {
-                       $phppath = trim(shell_exec('which php'));
+               $passed = false;
+               $passed2 = false;
+               $passed3 = false;
+
+               if (!isset($phppath)) {
+                       $phppath = 'php';
+               }
+
+               $passed = file_exists($phppath);
+               if (!$passed) {
+                       $phppath = trim(shell_exec('which ' . $phppath));
                        $passed = strlen($phppath);
                }
 
@@ -232,12 +259,12 @@ class Installer
                        $this->addCheck(L10n::t('PHP cli binary'), $passed2, true, $help);
                } else {
                        // return if it was required
-                       return $required;
+                       return !$required;
                }
 
                if ($passed2) {
                        $str = autoname(8);
-                       $cmd = "$phppath testargs.php $str";
+                       $cmd = "$phppath util/testargs.php $str";
                        $result = trim(shell_exec($cmd));
                        $passed3 = $result == $str;
                        $help = "";
@@ -557,7 +584,7 @@ class Installer
                }
 
                if (DBA::connected()) {
-                       if (DBA::count('user') > 0) {
+                       if (DBStructure::existsTable('user')) {
                                $this->addCheck(L10n::t('Database already in use.'), false, true, '');
 
                                return false;
index e09f23a18daa6715227bac3596daedd8c6f744a2..2ef2c32299d1ba2a4033dcc4b8e7944c1efe3f96 100644 (file)
@@ -87,7 +87,6 @@ class Install extends BaseModule
                                $dbuser    = notags(trim(defaults($_POST, 'dbuser', '')));
                                $dbpass    = notags(trim(defaults($_POST, 'dbpass', '')));
                                $dbdata    = notags(trim(defaults($_POST, 'dbdata', '')));
-                               $phpath    = notags(trim(defaults($_POST, 'phpath', '')));
                                $timezone  = notags(trim(defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ)));
                                $language  = notags(trim(defaults($_POST, 'language', Core\Installer::DEFAULT_LANG)));
                                $adminmail = notags(trim(defaults($_POST, 'adminmail', '')));
@@ -95,8 +94,11 @@ class Install extends BaseModule
                                // If we cannot connect to the database, return to the Database config wizard
                                if (!self::$installer->checkDB($dbhost, $dbuser, $dbpass, $dbdata)) {
                                        self::$currentWizardStep = self::DATABASE_CONFIG;
+                                       return;
                                }
 
+                               $phpath = self::$installer->getPHPPath();
+
                                if (!self::$installer->createConfig($phpath, $urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $timezone, $language, $adminmail, $a->getBasePath())) {
                                        return;
                                }
diff --git a/testargs.php b/testargs.php
deleted file mode 100644 (file)
index a0ddea3..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-
-/**
- *
- * File: testargs.php
- *
- * Purpose:
- * During installation we need to check if register_argc_argv is
- * enabled for the command line PHP processor, because otherwise
- * deliveries will fail. So we will do a shell exec of php and
- * execute this file with a command line argument, and see if it
- * echoes the argument back to us. Otherwise notify the person
- * that their installation doesn't meet the system requirements.
- *
- */
-
-
-if (($_SERVER["argc"] > 1) && isset($_SERVER["argv"][1])) {
-       echo $_SERVER["argv"][1];
-} else {
-       echo '';
-}
index ce67cc9993c8540c4ea3bcbf93f8d613ac43a74a..03a05b09b010ee767cbc0e666cc9c15ccd644d8b 100644 (file)
@@ -48,6 +48,8 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
 
 
 Creating config file...
+
+ Complete!
 CFG;
                }
 
@@ -56,20 +58,23 @@ CFG;
 
 
 Copying config file...
+
+ Complete!
 CFG;
                }
 
                $finished = <<<FIN
-Initializing setup...{$cfg}
+Initializing setup...
 
  Complete!
 
 
-Checking basic setup...
+Checking environment...
 
  NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
 
  Complete!
+{$cfg}
 
 
 Checking database...
diff --git a/util/testargs.php b/util/testargs.php
new file mode 100644 (file)
index 0000000..a0ddea3
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ *
+ * File: testargs.php
+ *
+ * Purpose:
+ * During installation we need to check if register_argc_argv is
+ * enabled for the command line PHP processor, because otherwise
+ * deliveries will fail. So we will do a shell exec of php and
+ * execute this file with a command line argument, and see if it
+ * echoes the argument back to us. Otherwise notify the person
+ * that their installation doesn't meet the system requirements.
+ *
+ */
+
+
+if (($_SERVER["argc"] > 1) && isset($_SERVER["argv"][1])) {
+       echo $_SERVER["argv"][1];
+} else {
+       echo '';
+}