diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index 491e826039..294009ada0 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -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"); diff --git a/src/Core/Installer.php b/src/Core/Installer.php index 03d888b7ea..cb871e2dfb 100644 --- a/src/Core/Installer.php +++ b/src/Core/Installer.php @@ -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; diff --git a/src/Module/Install.php b/src/Module/Install.php index e09f23a18d..2ef2c32299 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -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/tests/src/Core/Console/AutomaticInstallationConsoleTest.php b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php index ce67cc9993..03a05b09b0 100644 --- a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php +++ b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php @@ -48,6 +48,8 @@ class AutomaticInstallationConsoleTest extends ConsoleTest Creating config file... + + Complete! CFG; } @@ -56,20 +58,23 @@ CFG; Copying config file... + + Complete! CFG; } $finished = <<