Bugfixings

- 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
This commit is contained in:
Philipp Holzer 2018-10-30 11:30:19 +01:00
parent f0382ab919
commit cf39c9df81
No known key found for this signature in database
GPG Key ID: 517BE60E2CE5C8A5
5 changed files with 77 additions and 36 deletions

View File

@ -78,6 +78,20 @@ HELP;
$installer = new Installer(); $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, // if a config file is set,
$config_file = $this->getOption(['f', 'file']); $config_file = $this->getOption(['f', 'file']);
@ -111,6 +125,10 @@ HELP;
$tz = $this->getOption(['T', 'tz'], (!empty('FRIENDICA_TZ')) ? getenv('FRIENDICA_TZ') : ''); $tz = $this->getOption(['T', 'tz'], (!empty('FRIENDICA_TZ')) ? getenv('FRIENDICA_TZ') : '');
$lang = $this->getOption(['L', 'lang'], (!empty('FRIENDICA_LANG')) ? getenv('FRIENDICA_LANG') : ''); $lang = $this->getOption(['L', 'lang'], (!empty('FRIENDICA_LANG')) ? getenv('FRIENDICA_LANG') : '');
if (empty($php_path)) {
$php_path = $installer->getPHPPath();
}
$installer->createConfig( $installer->createConfig(
$php_path, $php_path,
$url_path, $url_path,
@ -127,18 +145,6 @@ HELP;
$this->out(" Complete!\n\n"); $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 // Check database connection
$this->out("Checking database...\n"); $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 * @return bool true if checks were successfully, otherwise false
*/ */
private function runBasicChecks(Installer $install) private function runBasicChecks(Installer $installer)
{ {
$checked = true; $checked = true;
$install->resetChecks(); $installer->resetChecks();
if (!$install->checkFunctions()) { if (!$installer->checkFunctions()) {
$checked = false; $checked = false;
} }
if (!$install->checkImagick()) { if (!$installer->checkImagick()) {
$checked = false; $checked = false;
} }
if (!$install->checkLocalIni()) { if (!$installer->checkLocalIni()) {
$checked = false; $checked = false;
} }
if (!$install->checkSmarty3()) { if (!$installer->checkSmarty3()) {
$checked = false; $checked = false;
} }
if ($install->checkKeys()) { if (!$installer->checkKeys()) {
$checked = false; $checked = false;
} }
$php_path = null;
if (!empty(Config::get('config', 'php_path'))) { if (!empty(Config::get('config', 'php_path'))) {
if (!$install->checkPHP(Config::get('config', 'php_path'), true)) { $php_path = Config::get('config', 'php_path');
throw new RuntimeException(" ERROR: The php_path is not valid in the config.\n"); }
}
} else { if (!$installer->checkPHP($php_path, true)) {
throw new RuntimeException(" ERROR: The php_path is not set in the config.\n"); $checked = false;
} }
$this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n"); $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");

View File

@ -26,6 +26,11 @@ class Installer
*/ */
private $checks; private $checks;
/**
* @var string The path to the PHP binary
*/
private $phppath = null;
/** /**
* Returns all checks made * Returns all checks made
* *
@ -36,6 +41,22 @@ class Installer
return $this->checks; 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 * Resets all checks
*/ */
@ -197,11 +218,17 @@ class Installer
*/ */
public function checkPHP($phppath = null, $required = false) public function checkPHP($phppath = null, $required = false)
{ {
$passed = $passed2 = $passed3 = false; $passed = false;
if (isset($phppath)) { $passed2 = false;
$passed = file_exists($phppath); $passed3 = false;
} else {
$phppath = trim(shell_exec('which php')); if (!isset($phppath)) {
$phppath = 'php';
}
$passed = file_exists($phppath);
if (!$passed) {
$phppath = trim(shell_exec('which ' . $phppath));
$passed = strlen($phppath); $passed = strlen($phppath);
} }
@ -232,12 +259,12 @@ class Installer
$this->addCheck(L10n::t('PHP cli binary'), $passed2, true, $help); $this->addCheck(L10n::t('PHP cli binary'), $passed2, true, $help);
} else { } else {
// return if it was required // return if it was required
return $required; return !$required;
} }
if ($passed2) { if ($passed2) {
$str = autoname(8); $str = autoname(8);
$cmd = "$phppath testargs.php $str"; $cmd = "$phppath util/testargs.php $str";
$result = trim(shell_exec($cmd)); $result = trim(shell_exec($cmd));
$passed3 = $result == $str; $passed3 = $result == $str;
$help = ""; $help = "";
@ -557,7 +584,7 @@ class Installer
} }
if (DBA::connected()) { if (DBA::connected()) {
if (DBA::count('user') > 0) { if (DBStructure::existsTable('user')) {
$this->addCheck(L10n::t('Database already in use.'), false, true, ''); $this->addCheck(L10n::t('Database already in use.'), false, true, '');
return false; return false;

View File

@ -87,7 +87,6 @@ class Install extends BaseModule
$dbuser = notags(trim(defaults($_POST, 'dbuser', ''))); $dbuser = notags(trim(defaults($_POST, 'dbuser', '')));
$dbpass = notags(trim(defaults($_POST, 'dbpass', ''))); $dbpass = notags(trim(defaults($_POST, 'dbpass', '')));
$dbdata = notags(trim(defaults($_POST, 'dbdata', ''))); $dbdata = notags(trim(defaults($_POST, 'dbdata', '')));
$phpath = notags(trim(defaults($_POST, 'phpath', '')));
$timezone = notags(trim(defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ))); $timezone = notags(trim(defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ)));
$language = notags(trim(defaults($_POST, 'language', Core\Installer::DEFAULT_LANG))); $language = notags(trim(defaults($_POST, 'language', Core\Installer::DEFAULT_LANG)));
$adminmail = notags(trim(defaults($_POST, 'adminmail', ''))); $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 we cannot connect to the database, return to the Database config wizard
if (!self::$installer->checkDB($dbhost, $dbuser, $dbpass, $dbdata)) { if (!self::$installer->checkDB($dbhost, $dbuser, $dbpass, $dbdata)) {
self::$currentWizardStep = self::DATABASE_CONFIG; 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())) { if (!self::$installer->createConfig($phpath, $urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $timezone, $language, $adminmail, $a->getBasePath())) {
return; return;
} }

View File

@ -48,6 +48,8 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
Creating config file... Creating config file...
Complete!
CFG; CFG;
} }
@ -56,20 +58,23 @@ CFG;
Copying config file... Copying config file...
Complete!
CFG; CFG;
} }
$finished = <<<FIN $finished = <<<FIN
Initializing setup...{$cfg} Initializing setup...
Complete! Complete!
Checking basic setup... Checking environment...
NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation. NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
Complete! Complete!
{$cfg}
Checking database... Checking database...