Refactor installer

This commit is contained in:
Philipp Holzer 2019-03-14 10:00:05 +01:00 committed by Hypolite Petovan
parent d88dc7484f
commit 69fa6161e5
7 changed files with 186 additions and 170 deletions

View file

@ -74,6 +74,8 @@ HELP;
$installer = new Installer(); $installer = new Installer();
$configCache = $a->getConfigCache();
$this->out(" Complete!\n\n"); $this->out(" Complete!\n\n");
// Check Environment // Check Environment
@ -81,7 +83,7 @@ HELP;
$installer->resetChecks(); $installer->resetChecks();
if (!$this->runBasicChecks($installer)) { if (!$this->runBasicChecks($installer, $configCache)) {
$errorMessage = $this->extractErrors($installer->getChecks()); $errorMessage = $this->extractErrors($installer->getChecks());
throw new RuntimeException($errorMessage); throw new RuntimeException($errorMessage);
} }
@ -100,41 +102,51 @@ HELP;
} }
} }
$db_host = $a->getConfigCache()->get('database', 'hostname'); //reload the config cache
$db_user = $a->getConfigCache()->get('database', 'username'); $loader = new Config\Cache\ConfigCacheLoader($a->getBasePath(), $a->getMode());
$db_pass = $a->getConfigCache()->get('database', 'password'); $loader->loadConfigFiles($configCache);
$db_data = $a->getConfigCache()->get('database', 'database');
} else { } else {
// Creating config file // Creating config file
$this->out("Creating config file...\n"); $this->out("Creating config file...\n");
$save_db = $this->getOption(['s', 'savedb'], false); $save_db = $this->getOption(['s', 'savedb'], false);
$db_host = $this->getOption(['H', 'dbhost'], ($save_db) ? getenv('MYSQL_HOST') : ''); //$db_host = $this->getOption(['H', 'dbhost'], ($save_db) ? (getenv('MYSQL_HOST') ? getenv('MYSQL_HOST') : Installer::DEFAULT_HOST) : '');
$db_host = $this->getOption(['H', 'dbhost'], ($save_db) ? (getenv('MYSQL_HOST')) : Installer::DEFAULT_HOST);
$db_port = $this->getOption(['p', 'dbport'], ($save_db) ? getenv('MYSQL_PORT') : null); $db_port = $this->getOption(['p', 'dbport'], ($save_db) ? getenv('MYSQL_PORT') : null);
$db_data = $this->getOption(['d', 'dbdata'], ($save_db) ? getenv('MYSQL_DATABASE') : ''); $configCache->set('database', 'hostname', $db_host . (!empty($db_port) ? ':' . $db_port : ''));
$db_user = $this->getOption(['U', 'dbuser'], ($save_db) ? getenv('MYSQL_USER') . getenv('MYSQL_USERNAME') : ''); $configCache->set('database', 'database',
$db_pass = $this->getOption(['P', 'dbpass'], ($save_db) ? getenv('MYSQL_PASSWORD') : ''); $this->getOption(['d', 'dbdata'],
$url_path = $this->getOption(['u', 'urlpath'], !empty('FRIENDICA_URL_PATH') ? getenv('FRIENDICA_URL_PATH') : null); ($save_db) ? getenv('MYSQL_DATABASE') : ''));
$configCache->set('database', 'username',
$this->getOption(['U', 'dbuser'],
($save_db) ? getenv('MYSQL_USER') . getenv('MYSQL_USERNAME') : ''));
$configCache->set('database', 'password',
$this->getOption(['P', 'dbpass'],
($save_db) ? getenv('MYSQL_PASSWORD') : ''));
$php_path = $this->getOption(['b', 'phppath'], !empty('FRIENDICA_PHP_PATH') ? getenv('FRIENDICA_PHP_PATH') : null); $php_path = $this->getOption(['b', 'phppath'], !empty('FRIENDICA_PHP_PATH') ? getenv('FRIENDICA_PHP_PATH') : null);
$admin_mail = $this->getOption(['A', 'admin'], !empty('FRIENDICA_ADMIN_MAIL') ? getenv('FRIENDICA_ADMIN_MAIL') : ''); if (!empty($php_path)) {
$tz = $this->getOption(['T', 'tz'], !empty('FRIENDICA_TZ') ? getenv('FRIENDICA_TZ') : ''); $configCache->set('config', 'php_path', $php_path);
$lang = $this->getOption(['L', 'lang'], !empty('FRIENDICA_LANG') ? getenv('FRIENDICA_LANG') : ''); }
$configCache->set('config', 'admin_email',
$this->getOption(['A', 'admin'],
!empty(getenv('FRIENDICA_ADMIN_MAIL')) ? getenv('FRIENDICA_ADMIN_MAIL') : ''));
$configCache->set('system', 'default_timezone',
$this->getOption(['T', 'tz'],
!empty(getenv('FRIENDICA_TZ')) ? getenv('FRIENDICA_TZ') : Installer::DEFAULT_TZ));
$configCache->set('system', 'language',
$this->getOption(['L', 'lang'],
!empty(getenv('FRIENDICA_LANG')) ? getenv('FRIENDICA_LANG') : Installer::DEFAULT_LANG));
if (empty($php_path)) { if (empty($php_path)) {
$php_path = $installer->getPHPPath(); $configCache->set('config', 'php_path', $installer->getPHPPath());
} }
$installer->createConfig( $installer->createConfig(
$php_path, $a,
$url_path, $configCache,
(!empty($db_port) ? $db_host . ':' . $db_port : $db_host),
$db_user,
$db_pass,
$db_data,
$tz,
$lang,
$admin_mail,
$a->getBasePath() $a->getBasePath()
); );
} }
@ -146,7 +158,7 @@ HELP;
$installer->resetChecks(); $installer->resetChecks();
if (!$installer->checkDB($a->getBasePath(), $a->getConfigCache(), $a->getProfiler(), $db_host, $db_user, $db_pass, $db_data)) { if (!$installer->checkDB($a->getBasePath(), $configCache, $a->getProfiler())) {
$errorMessage = $this->extractErrors($installer->getChecks()); $errorMessage = $this->extractErrors($installer->getChecks());
throw new RuntimeException($errorMessage); throw new RuntimeException($errorMessage);
} }
@ -180,12 +192,13 @@ HELP;
} }
/** /**
* @param Installer $installer the Installer instance * @param Installer $installer The Installer instance
* @param Config\Cache\IConfigCache $configCache The config cache
* *
* @return bool true if checks were successfully, otherwise false * @return bool true if checks were successfully, otherwise false
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
private function runBasicChecks(Installer $installer) private function runBasicChecks(Installer $installer, Config\Cache\IConfigCache $configCache)
{ {
$checked = true; $checked = true;
@ -207,8 +220,8 @@ HELP;
} }
$php_path = null; $php_path = null;
if (!empty(Config::get('config', 'php_path'))) { if (!$configCache->has('config', 'php_path')) {
$php_path = Config::get('config', 'php_path'); $php_path = $configCache->get('config', 'php_path');
} }
if (!$installer->checkPHP($php_path, true)) { if (!$installer->checkPHP($php_path, true)) {

View file

@ -6,6 +6,7 @@ namespace Friendica\Core;
use DOMDocument; use DOMDocument;
use Exception; use Exception;
use Friendica\App;
use Friendica\Core\Config\Cache\IConfigCache; use Friendica\Core\Config\Cache\IConfigCache;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
@ -129,33 +130,28 @@ class Installer
* - Creates `config/local.config.php` * - Creates `config/local.config.php`
* - Installs Database Structure * - Installs Database Structure
* *
* @param string $phppath Path to the PHP-Binary (optional, if not set e.g. 'php' or '/usr/bin/php') * @param App $app The Friendica App
* @param string $urlpath Path based on the URL of Friendica (e.g. '/friendica') * @param IConfigCache $configCache The config cache with all config relevant information
* @param string $dbhost Hostname/IP of the Friendica Database
* @param string $dbuser Username of the Database connection credentials
* @param string $dbpass Password of the Database connection credentials
* @param string $dbdata Name of the Database
* @param string $timezone Timezone of the Friendica Installaton (e.g. 'Europe/Berlin')
* @param string $language 2-letter ISO 639-1 code (eg. 'en')
* @param string $adminmail Mail-Adress of the administrator
* @param string $basepath The basepath of Friendica * @param string $basepath The basepath of Friendica
* *
* @return bool true if the config was created, otherwise false * @return bool true if the config was created, otherwise false
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public function createConfig($phppath, $urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $timezone, $language, $adminmail, $basepath) public function createConfig(App $app, IConfigCache $configCache, $basepath)
{ {
$tpl = Renderer::getMarkupTemplate('local.config.tpl'); $tpl = Renderer::getMarkupTemplate('local.config.tpl');
$txt = Renderer::replaceMacros($tpl, [ $txt = Renderer::replaceMacros($tpl, [
'$phpath' => $phppath, '$dbhost' => $configCache->get('database', 'hostname'),
'$dbhost' => $dbhost, '$dbuser' => $configCache->get('database', 'username'),
'$dbuser' => $dbuser, '$dbpass' => $configCache->get('database', 'password'),
'$dbpass' => $dbpass, '$dbdata' => $configCache->get('database', 'database'),
'$dbdata' => $dbdata,
'$timezone' => $timezone, '$phpath' => $this->getPHPPath(),
'$language' => $language, '$adminmail' => $configCache->get('config', 'admin_email'),
'$urlpath' => $urlpath,
'$adminmail' => $adminmail, '$timezone' => $configCache->get('system', 'default_timezone'),
'$language' => $configCache->get('system', 'language'),
'$urlpath' => $app->getURLPath(),
]); ]);
$result = file_put_contents($basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php', $txt); $result = file_put_contents($basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php', $txt);
@ -594,16 +590,17 @@ class Installer
* @param string $basePath The basepath of this call * @param string $basePath The basepath of this call
* @param IConfigCache $configCache The configuration cache * @param IConfigCache $configCache The configuration cache
* @param Profiler $profiler The profiler of this app * @param Profiler $profiler The profiler of this app
* @param string $dbhost Hostname/IP of the Friendica Database
* @param string $dbuser Username of the Database connection credentials
* @param string $dbpass Password of the Database connection credentials
* @param string $dbdata Name of the Database
* *
* @return bool true if the check was successful, otherwise false * @return bool true if the check was successful, otherwise false
* @throws Exception * @throws Exception
*/ */
public function checkDB($basePath, IConfigCache $configCache, Profiler $profiler, $dbhost, $dbuser, $dbpass, $dbdata) public function checkDB($basePath, IConfigCache $configCache, Profiler $profiler)
{ {
$dbhost = $configCache->get('database', 'hostname');
$dbuser = $configCache->get('database', 'username');
$dbpass = $configCache->get('database', 'password');
$dbdata = $configCache->get('database', 'database');
if (!DBA::connect($basePath, $configCache, $profiler, $dbhost, $dbuser, $dbpass, $dbdata)) { if (!DBA::connect($basePath, $configCache, $profiler, $dbhost, $dbuser, $dbpass, $dbdata)) {
$this->addCheck(L10n::t('Could not connect to database.'), false, true, ''); $this->addCheck(L10n::t('Could not connect to database.'), false, true, '');

View file

@ -5,6 +5,7 @@ namespace Friendica\Module;
use Friendica\App; use Friendica\App;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core; use Friendica\Core;
use Friendica\Core\Config\Cache\IConfigCache;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -65,45 +66,48 @@ class Install extends BaseModule
public static function post() public static function post()
{ {
$a = self::getApp(); $a = self::getApp();
$configCache = $a->getConfigCache();
switch (self::$currentWizardStep) { switch (self::$currentWizardStep) {
case self::SYSTEM_CHECK: case self::SYSTEM_CHECK:
case self::DATABASE_CONFIG: case self::DATABASE_CONFIG:
// Nothing to do in these steps self::checkSetting($configCache, $_POST, 'config', 'php_path');
break; break;
case self::SITE_SETTINGS: case self::SITE_SETTINGS:
$dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST))); self::checkSetting($configCache, $_POST, 'config', 'php_path');
$dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser', '')));
$dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass', ''))); self::checkSetting($configCache, $_POST, 'database', 'hostname', Core\Installer::DEFAULT_HOST);
$dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata', ''))); self::checkSetting($configCache, $_POST, 'database', 'username', '');
self::checkSetting($configCache, $_POST, 'database', 'password', '');
self::checkSetting($configCache, $_POST, 'database', 'database', '');
// If we cannot connect to the database, return to the previous step // If we cannot connect to the database, return to the previous step
if (!self::$installer->checkDB($a->getBasePath(), $a->getConfigCache(), $a->getProfiler(), $dbhost, $dbuser, $dbpass, $dbdata)) { if (!self::$installer->checkDB($a->getBasePath(), $configCache, $a->getProfiler())) {
self::$currentWizardStep = self::DATABASE_CONFIG; self::$currentWizardStep = self::DATABASE_CONFIG;
} }
break; break;
case self::FINISHED: case self::FINISHED:
$urlpath = $a->getURLPath(); self::checkSetting($configCache, $_POST, 'config', 'php_path');
$dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
$dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser', ''))); self::checkSetting($configCache, $_POST, 'database', 'hostname', Core\Installer::DEFAULT_HOST);
$dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass', ''))); self::checkSetting($configCache, $_POST, 'database', 'username', '');
$dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata', ''))); self::checkSetting($configCache, $_POST, 'database', 'password', '');
$timezone = Strings::escapeTags(trim(defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ))); self::checkSetting($configCache, $_POST, 'database', 'database', '');
$language = Strings::escapeTags(trim(defaults($_POST, 'language', Core\Installer::DEFAULT_LANG)));
$adminmail = Strings::escapeTags(trim(defaults($_POST, 'adminmail', ''))); self::checkSetting($configCache, $_POST, 'system', 'default_timezone', Core\Installer::DEFAULT_TZ);
self::checkSetting($configCache, $_POST, 'system', 'language', Core\Installer::DEFAULT_LANG);
self::checkSetting($configCache, $_POST, 'config', 'admin_email', '');
// 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($a->getBasePath(), $a->getConfigCache(), $a->getProfiler(), $dbhost, $dbuser, $dbpass, $dbdata)) { if (!self::$installer->checkDB($a->getBasePath(), $configCache, $a->getProfiler())) {
self::$currentWizardStep = self::DATABASE_CONFIG; self::$currentWizardStep = self::DATABASE_CONFIG;
return; return;
} }
$phpath = self::$installer->getPHPPath(); if (!self::$installer->createConfig($a, $configCache, $a->getBasePath())) {
if (!self::$installer->createConfig($phpath, $urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $timezone, $language, $adminmail, $a->getBasePath())) {
return; return;
} }
@ -116,6 +120,7 @@ class Install extends BaseModule
public static function content() public static function content()
{ {
$a = self::getApp(); $a = self::getApp();
$configCache = $a->getConfigCache();
$output = ''; $output = '';
@ -123,85 +128,62 @@ class Install extends BaseModule
switch (self::$currentWizardStep) { switch (self::$currentWizardStep) {
case self::SYSTEM_CHECK: case self::SYSTEM_CHECK:
$phppath = defaults($_POST, 'phpath', null); $php_path = $configCache->get('config', 'php_path');
$status = self::$installer->checkEnvironment($a->getBaseURL(), $phppath); $status = self::$installer->checkEnvironment($a->getBaseURL(), $php_path);
$tpl = Renderer::getMarkupTemplate('install_checks.tpl'); $tpl = Renderer::getMarkupTemplate('install_checks.tpl');
$output .= Renderer::replaceMacros($tpl, [ $output .= Renderer::replaceMacros($tpl, [
'$title' => $install_title, '$title' => $install_title,
'$pass' => L10n::t('System check'), '$pass' => L10n::t('System check'),
'$checks' => self::$installer->getChecks(), '$checks' => self::$installer->getChecks(),
'$passed' => $status, '$passed' => $status,
'$see_install' => L10n::t('Please see the file "INSTALL.txt".'), '$see_install' => L10n::t('Please see the file "INSTALL.txt".'),
'$next' => L10n::t('Next'), '$next' => L10n::t('Next'),
'$reload' => L10n::t('Check again'), '$reload' => L10n::t('Check again'),
'$phpath' => $phppath, '$php_path' => $php_path,
'$baseurl' => $a->getBaseURL() '$baseurl' => $a->getBaseURL()
]); ]);
break; break;
case self::DATABASE_CONFIG: case self::DATABASE_CONFIG:
$dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost' , Core\Installer::DEFAULT_HOST)));
$dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser' , '' )));
$dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass' , '' )));
$dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata' , '' )));
$phpath = Strings::escapeTags(trim(defaults($_POST, 'phpath' , '' )));
$adminmail = Strings::escapeTags(trim(defaults($_POST, 'adminmail', '' )));
$tpl = Renderer::getMarkupTemplate('install_db.tpl'); $tpl = Renderer::getMarkupTemplate('install_db.tpl');
$output .= Renderer::replaceMacros($tpl, [ $output .= Renderer::replaceMacros($tpl, [
'$title' => $install_title, '$title' => $install_title,
'$pass' => L10n::t('Database connection'), '$pass' => L10n::t('Database connection'),
'$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'), '$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'),
'$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'), '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
'$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'), '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'),
'checks' => self::$installer->getChecks(), 'checks' => self::$installer->getChecks(),
'$dbhost' => ['dbhost', '$dbhost' => ['database-hostname',
L10n::t('Database Server Name'), L10n::t('Database Server Name'),
$dbhost, $configCache->get('database', 'hostname'),
'', '',
'required'], 'required'],
'$dbuser' => ['dbuser', '$dbuser' => ['database-username',
L10n::t('Database Login Name'), L10n::t('Database Login Name'),
$dbuser, $configCache->get('database', 'username'),
'', '',
'required', 'required',
'autofocus'], 'autofocus'],
'$dbpass' => ['dbpass', '$dbpass' => ['database-password',
L10n::t('Database Login Password'), L10n::t('Database Login Password'),
$dbpass, $configCache->get('database', 'password'),
L10n::t("For security reasons the password must not be empty"), L10n::t("For security reasons the password must not be empty"),
'required'], 'required'],
'$dbdata' => ['dbdata', '$dbdata' => ['database-database',
L10n::t('Database Name'), L10n::t('Database Name'),
$dbdata, $configCache->get('database', 'database'),
'', '',
'required'], 'required'],
'$adminmail' => ['adminmail', '$lbl_10' => L10n::t('Please select a default timezone for your website'),
L10n::t('Site administrator email address'), '$baseurl' => $a->getBaseURL(),
$adminmail, '$php_path' => $configCache->get('config', 'php_path'),
L10n::t('Your account email address must match this in order to use the web admin panel.'), '$submit' => L10n::t('Submit')
'required',
'autofocus',
'email'],
'$lbl_10' => L10n::t('Please select a default timezone for your website'),
'$baseurl' => $a->getBaseURL(),
'$phpath' => $phpath,
'$submit' => L10n::t('Submit')
]); ]);
break; break;
case self::SITE_SETTINGS: case self::SITE_SETTINGS:
$dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
$dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser', '' )));
$dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass', '' )));
$dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata', '' )));
$phpath = Strings::escapeTags(trim(defaults($_POST, 'phpath', '' )));
$adminmail = Strings::escapeTags(trim(defaults($_POST, 'adminmail', '')));
$timezone = defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ);
/* Installed langs */ /* Installed langs */
$lang_choices = L10n::getAvailableLanguages(); $lang_choices = L10n::getAvailableLanguages();
@ -210,16 +192,23 @@ class Install extends BaseModule
'$title' => $install_title, '$title' => $install_title,
'$checks' => self::$installer->getChecks(), '$checks' => self::$installer->getChecks(),
'$pass' => L10n::t('Site settings'), '$pass' => L10n::t('Site settings'),
'$dbhost' => $dbhost, '$dbhost' => $configCache->get('database', 'hostname'),
'$dbuser' => $dbuser, '$dbuser' => $configCache->get('database', 'username'),
'$dbpass' => $dbpass, '$dbpass' => $configCache->get('database', 'password'),
'$dbdata' => $dbdata, '$dbdata' => $configCache->get('database', 'database'),
'$phpath' => $phpath, '$phpath' => $configCache->get('config', 'php_path'),
'$adminmail' => ['adminmail', L10n::t('Site administrator email address'), $adminmail, L10n::t('Your account email address must match this in order to use the web admin panel.'), 'required', 'autofocus', 'email'], '$adminmail' => ['config-admin_email',
'$timezone' => Temporal::getTimezoneField('timezone', L10n::t('Please select a default timezone for your website'), $timezone, ''), L10n::t('Site administrator email address'),
'$language' => ['language', $configCache->get('config', 'admin_email'),
L10n::t('Your account email address must match this in order to use the web admin panel.'),
'required', 'autofocus', 'email'],
'$timezone' => Temporal::getTimezoneField('system-default_timezone',
L10n::t('Please select a default timezone for your website'),
$configCache->get('system', 'default_timezone'),
''),
'$language' => ['system-language',
L10n::t('System Language:'), L10n::t('System Language:'),
Core\Installer::DEFAULT_LANG, $configCache->get('system', 'language'),
L10n::t('Set the default language for your Friendica installation interface and to send emails.'), L10n::t('Set the default language for your Friendica installation interface and to send emails.'),
$lang_choices], $lang_choices],
'$baseurl' => $a->getBaseURL(), '$baseurl' => $a->getBaseURL(),
@ -269,4 +258,24 @@ class Install extends BaseModule
. L10n::t('Go to your new Friendica node <a href="%s/register">registration page</a> and register as new user. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.', $baseurl) . L10n::t('Go to your new Friendica node <a href="%s/register">registration page</a> and register as new user. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.', $baseurl)
. "</p>"; . "</p>";
} }
/**
* Checks the $_POST settings and updates the config Cache for it
*
* @param IConfigCache $configCache The current config cache
* @param array $post The $_POST data
* @param string $cat The category of the setting
* @param string $key The key of the setting
* @param null|string $default The default value
*/
private static function checkSetting(IConfigCache $configCache, array $post, $cat, $key, $default = null)
{
$configCache->set($cat, $key,
Strings::escapeTags(
trim(defaults($post, sprintf('%s-%s', $cat, $key),
(!isset($default) ? $configCache->get($cat, $key) : $default))
)
)
);
}
} }

View file

@ -15,8 +15,6 @@ use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamFile; use org\bovigo\vfs\vfsStreamFile;
/** /**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @requires PHP 7.0 * @requires PHP 7.0
*/ */
class AutomaticInstallationConsoleTest extends ConsoleTest class AutomaticInstallationConsoleTest extends ConsoleTest
@ -277,12 +275,11 @@ FIN;
* Asserts all config entries * Asserts all config entries
* *
* @param null|array $assertion The optional assertion array * @param null|array $assertion The optional assertion array
* @param boolean $createConfig True, if a config file has to get generated
* @param boolean $saveDb True, if the db credentials should get saved to the file * @param boolean $saveDb True, if the db credentials should get saved to the file
* @param boolean $default True, if we use the default values * @param boolean $default True, if we use the default values
* @param boolean $defaultDb True, if we use the default value for the DB * @param boolean $defaultDb True, if we use the default value for the DB
*/ */
public function assertConfig($assertion = null, $createConfig = true, $saveDb = false, $default = true, $defaultDb = true) public function assertConfig($assertion = null, $saveDb = false, $default = true, $defaultDb = true)
{ {
if (!empty($assertion['database']['hostname'])) { if (!empty($assertion['database']['hostname'])) {
$assertion['database']['hostname'] .= (!empty($assertion['database']['port']) ? ':' . $assertion['database']['port'] : ''); $assertion['database']['hostname'] .= (!empty($assertion['database']['port']) ? ':' . $assertion['database']['port'] : '');
@ -293,15 +290,11 @@ FIN;
$this->assertConfigEntry('database', 'password', ($saveDb) ? $assertion : null); $this->assertConfigEntry('database', 'password', ($saveDb) ? $assertion : null);
$this->assertConfigEntry('database', 'database', ($saveDb) ? $assertion : null); $this->assertConfigEntry('database', 'database', ($saveDb) ? $assertion : null);
$this->assertConfigEntry('config', 'hostname', $assertion);
$this->assertConfigEntry('config', 'admin_email', $assertion); $this->assertConfigEntry('config', 'admin_email', $assertion);
$this->assertConfigEntry('config', 'php_path', trim(shell_exec('which php'))); $this->assertConfigEntry('config', 'php_path', trim(shell_exec('which php')));
$this->assertConfigEntry('system', 'default_timezone', $assertion, ($default) ? Installer::DEFAULT_TZ : null); $this->assertConfigEntry('system', 'default_timezone', $assertion, ($default) ? Installer::DEFAULT_TZ : null);
$this->assertConfigEntry('system', 'language', $assertion, ($default) ? Installer::DEFAULT_LANG : null); $this->assertConfigEntry('system', 'language', $assertion, ($default) ? Installer::DEFAULT_LANG : null);
$this->assertConfigEntry('system', 'ssl_policy', $assertion, ($default) ? SSL_POLICY_NONE : null);
$this->assertConfigEntry('system', 'urlpath', $assertion);
$this->assertConfigEntry('system', 'basepath', $createConfig ? $this->root->url() : $assertion);
} }
/** /**
@ -309,6 +302,8 @@ FIN;
*/ */
public function testEmpty() public function testEmpty()
{ {
$this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once();
$this->mockConnect(true, 1); $this->mockConnect(true, 1);
$this->mockConnected(true, 1); $this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1); $this->mockExistsTable('user', false, 1);
@ -400,7 +395,7 @@ CONF;
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
$this->assertEquals($config, file_get_contents($this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')->url())); $this->assertEquals($config, file_get_contents($this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')->url()));
$this->assertConfig($data, false, true, false, false); $this->assertConfig($data, true, false, false);
} }
/** /**
@ -410,6 +405,8 @@ CONF;
*/ */
public function testWithEnvironmentAndSave(array $data) public function testWithEnvironmentAndSave(array $data)
{ {
$this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once();
$this->mockConnect(true, 1); $this->mockConnect(true, 1);
$this->mockConnected(true, 1); $this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1); $this->mockExistsTable('user', false, 1);
@ -439,7 +436,7 @@ CONF;
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
$this->assertFinished($txt, true); $this->assertFinished($txt, true);
$this->assertConfig($data, true, true, true, false); $this->assertConfig($data, true, true, false);
} }
/** /**
@ -449,6 +446,8 @@ CONF;
*/ */
public function testWithEnvironmentWithoutSave(array $data) public function testWithEnvironmentWithoutSave(array $data)
{ {
$this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once();
$this->mockConnect(true, 1); $this->mockConnect(true, 1);
$this->mockConnected(true, 1); $this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1); $this->mockExistsTable('user', false, 1);
@ -477,7 +476,7 @@ CONF;
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
$this->assertFinished($txt, true); $this->assertFinished($txt, true);
$this->assertConfig($data, true, false, true); $this->assertConfig($data, false, true);
} }
/** /**
@ -486,6 +485,8 @@ CONF;
*/ */
public function testWithArguments(array $data) public function testWithArguments(array $data)
{ {
$this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once();
$this->mockConnect(true, 1); $this->mockConnect(true, 1);
$this->mockConnected(true, 1); $this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1); $this->mockExistsTable('user', false, 1);
@ -518,7 +519,7 @@ CONF;
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
$this->assertFinished($txt, true); $this->assertFinished($txt, true);
$this->assertConfig($data, true, true, true, true); $this->assertConfig($data, true, true, true);
} }
/** /**
@ -526,6 +527,7 @@ CONF;
*/ */
public function testNoDatabaseConnection() public function testNoDatabaseConnection()
{ {
$this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once();
$this->mockConnect(false, 1); $this->mockConnect(false, 1);
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
@ -538,7 +540,7 @@ CONF;
$this->assertStuckDB($txt); $this->assertStuckDB($txt);
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
$this->assertConfig(null, true, false, true, false); $this->assertConfig(null, false, true, false);
} }
public function testGetHelp() public function testGetHelp()
@ -560,19 +562,17 @@ Options
-v Show more debug information. -v Show more debug information.
-a All setup checks are required (except .htaccess) -a All setup checks are required (except .htaccess)
-f|--file <config> prepared config file (e.g. "config/local.config.php" itself) which will override every other config option - except the environment variables) -f|--file <config> prepared config file (e.g. "config/local.config.php" itself) which will override every other config option - except the environment variables)
-s|--savedb Save the DB credentials to the file (if environment variables is used) -s|--savedb Save the DB credentials to the file (if environment variables is used)
-H|--dbhost <host> The host of the mysql/mariadb database (env MYSQL_HOST) -H|--dbhost <host> The host of the mysql/mariadb database (env MYSQL_HOST)
-p|--dbport <port> The port of the mysql/mariadb database (env MYSQL_PORT) -p|--dbport <port> The port of the mysql/mariadb database (env MYSQL_PORT)
-d|--dbdata <database> The name of the mysql/mariadb database (env MYSQL_DATABASE) -d|--dbdata <database> The name of the mysql/mariadb database (env MYSQL_DATABASE)
-U|--dbuser <username> The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME) -U|--dbuser <username> The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME)
-P|--dbpass <password> The password of the mysql/mariadb database login (env MYSQL_PASSWORD) -P|--dbpass <password> The password of the mysql/mariadb database login (env MYSQL_PASSWORD)
-U|--urlpath <url_path> The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH) -u|--urlpath <url_path> The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH)
-B|--phppath <php_path> The path of the PHP binary (env FRIENDICA_PHP_PATH) -b|--phppath <php_path> The path of the PHP binary (env FRIENDICA_PHP_PATH)
-b|--basepath <base_path> The basepath of Friendica(env FRIENDICA_BASE_PATH) -A|--admin <mail> The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL)
-S|--sslpolicy <ssl_policy> The SSL policy of Friendica (env FRIENDICA_SSL_POLICY) -T|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
-n|--hostname <hostname> The hostname of Friendica (env FRIENDICA_PHP_HOSTNAME) -L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
-t|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
-L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
Environment variables Environment variables
MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used) MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used)
@ -580,12 +580,9 @@ Environment variables
MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb) MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb)
MYSQL_PASSWORD The password of the mysql/mariadb database login MYSQL_PASSWORD The password of the mysql/mariadb database login
MYSQL_DATABASE The name of the mysql/mariadb database MYSQL_DATABASE The name of the mysql/mariadb database
FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica') - leave empty for auto detection FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica')
FRIENDICA_PHP_PATH The path of the PHP binary - leave empty for auto detection FRIENDICA_PHP_PATH The path of the PHP binary
FRIENDICA_BASE_PATH The basepath of Friendica - leave empty for auto detection
FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access) FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access)
FRIENDICA_SSL_POLICY The SSL policy of Friendica (default is NO SSL)
FRIENDICA_HOSTNAME The hostname of Friendica - leave empty for auto detection
FRIENDICA_TZ The timezone of Friendica FRIENDICA_TZ The timezone of Friendica
FRIENDICA_LANG The langauge of Friendica FRIENDICA_LANG The langauge of Friendica
@ -606,6 +603,6 @@ HELP;
$txt = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
$this->assertEquals($txt, $theHelp); $this->assertEquals($theHelp, $txt);
} }
} }

View file

@ -28,7 +28,7 @@
</table> </table>
{{if $phpath}} {{if $phpath}}
<input type="hidden" name="phpath" value="{{$phpath}}"> <input type="hidden" name="config-php_path" value="{{$php_path}}">
{{/if}} {{/if}}
{{if $passed}} {{if $passed}}

View file

@ -18,7 +18,7 @@
<form id="install-form" action="{{$baseurl}}/install" method="post"> <form id="install-form" action="{{$baseurl}}/install" method="post">
<input type="hidden" name="phpath" value="{{$phpath}}" /> <input type="hidden" name="config-php_path" value="{{$php_path}}" />
<input type="hidden" name="pass" value="3" /> <input type="hidden" name="pass" value="3" />
{{include file="field_input.tpl" field=$dbhost}} {{include file="field_input.tpl" field=$dbhost}}

View file

@ -6,11 +6,11 @@
<form id="install-form" action="{{$baseurl}}/install" method="post"> <form id="install-form" action="{{$baseurl}}/install" method="post">
<input type="hidden" name="phpath" value="{{$phpath}}" /> <input type="hidden" name="config-php_path" value="{{$php_path}}" />
<input type="hidden" name="dbhost" value="{{$dbhost}}" /> <input type="hidden" name="database-hostname" value="{{$dbhost}}" />
<input type="hidden" name="dbuser" value="{{$dbuser}}" /> <input type="hidden" name="database-username" value="{{$dbuser}}" />
<input type="hidden" name="dbpass" value="{{$dbpass}}" /> <input type="hidden" name="database-password" value="{{$dbpass}}" />
<input type="hidden" name="dbdata" value="{{$dbdata}}" /> <input type="hidden" name="database-database" value="{{$dbdata}}" />
<input type="hidden" name="pass" value="4" /> <input type="hidden" name="pass" value="4" />
{{include file="field_input.tpl" field=$adminmail}} {{include file="field_input.tpl" field=$adminmail}}