Refactor installer
This commit is contained in:
parent
d88dc7484f
commit
69fa6161e5
7 changed files with 186 additions and 170 deletions
|
@ -74,6 +74,8 @@ HELP;
|
|||
|
||||
$installer = new Installer();
|
||||
|
||||
$configCache = $a->getConfigCache();
|
||||
|
||||
$this->out(" Complete!\n\n");
|
||||
|
||||
// Check Environment
|
||||
|
@ -81,7 +83,7 @@ HELP;
|
|||
|
||||
$installer->resetChecks();
|
||||
|
||||
if (!$this->runBasicChecks($installer)) {
|
||||
if (!$this->runBasicChecks($installer, $configCache)) {
|
||||
$errorMessage = $this->extractErrors($installer->getChecks());
|
||||
throw new RuntimeException($errorMessage);
|
||||
}
|
||||
|
@ -100,41 +102,51 @@ HELP;
|
|||
}
|
||||
}
|
||||
|
||||
$db_host = $a->getConfigCache()->get('database', 'hostname');
|
||||
$db_user = $a->getConfigCache()->get('database', 'username');
|
||||
$db_pass = $a->getConfigCache()->get('database', 'password');
|
||||
$db_data = $a->getConfigCache()->get('database', 'database');
|
||||
//reload the config cache
|
||||
$loader = new Config\Cache\ConfigCacheLoader($a->getBasePath(), $a->getMode());
|
||||
$loader->loadConfigFiles($configCache);
|
||||
|
||||
} else {
|
||||
// Creating config file
|
||||
$this->out("Creating config file...\n");
|
||||
|
||||
$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_data = $this->getOption(['d', 'dbdata'], ($save_db) ? getenv('MYSQL_DATABASE') : '');
|
||||
$db_user = $this->getOption(['U', 'dbuser'], ($save_db) ? getenv('MYSQL_USER') . getenv('MYSQL_USERNAME') : '');
|
||||
$db_pass = $this->getOption(['P', 'dbpass'], ($save_db) ? getenv('MYSQL_PASSWORD') : '');
|
||||
$url_path = $this->getOption(['u', 'urlpath'], !empty('FRIENDICA_URL_PATH') ? getenv('FRIENDICA_URL_PATH') : null);
|
||||
$configCache->set('database', 'hostname', $db_host . (!empty($db_port) ? ':' . $db_port : ''));
|
||||
$configCache->set('database', 'database',
|
||||
$this->getOption(['d', 'dbdata'],
|
||||
($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);
|
||||
$admin_mail = $this->getOption(['A', 'admin'], !empty('FRIENDICA_ADMIN_MAIL') ? getenv('FRIENDICA_ADMIN_MAIL') : '');
|
||||
$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)) {
|
||||
$configCache->set('config', 'php_path', $php_path);
|
||||
}
|
||||
$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)) {
|
||||
$php_path = $installer->getPHPPath();
|
||||
$configCache->set('config', 'php_path', $installer->getPHPPath());
|
||||
}
|
||||
|
||||
$installer->createConfig(
|
||||
$php_path,
|
||||
$url_path,
|
||||
(!empty($db_port) ? $db_host . ':' . $db_port : $db_host),
|
||||
$db_user,
|
||||
$db_pass,
|
||||
$db_data,
|
||||
$tz,
|
||||
$lang,
|
||||
$admin_mail,
|
||||
$a,
|
||||
$configCache,
|
||||
$a->getBasePath()
|
||||
);
|
||||
}
|
||||
|
@ -146,7 +158,7 @@ HELP;
|
|||
|
||||
$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());
|
||||
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
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private function runBasicChecks(Installer $installer)
|
||||
private function runBasicChecks(Installer $installer, Config\Cache\IConfigCache $configCache)
|
||||
{
|
||||
$checked = true;
|
||||
|
||||
|
@ -207,8 +220,8 @@ HELP;
|
|||
}
|
||||
|
||||
$php_path = null;
|
||||
if (!empty(Config::get('config', 'php_path'))) {
|
||||
$php_path = Config::get('config', 'php_path');
|
||||
if (!$configCache->has('config', 'php_path')) {
|
||||
$php_path = $configCache->get('config', 'php_path');
|
||||
}
|
||||
|
||||
if (!$installer->checkPHP($php_path, true)) {
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace Friendica\Core;
|
|||
|
||||
use DOMDocument;
|
||||
use Exception;
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config\Cache\IConfigCache;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
|
@ -129,33 +130,28 @@ class Installer
|
|||
* - Creates `config/local.config.php`
|
||||
* - Installs Database Structure
|
||||
*
|
||||
* @param string $phppath Path to the PHP-Binary (optional, if not set e.g. 'php' or '/usr/bin/php')
|
||||
* @param string $urlpath Path based on the URL of Friendica (e.g. '/friendica')
|
||||
* @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 App $app The Friendica App
|
||||
* @param IConfigCache $configCache The config cache with all config relevant information
|
||||
* @param string $basepath The basepath of Friendica
|
||||
*
|
||||
* @return bool true if the config was created, otherwise false
|
||||
* @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');
|
||||
$txt = Renderer::replaceMacros($tpl, [
|
||||
'$phpath' => $phppath,
|
||||
'$dbhost' => $dbhost,
|
||||
'$dbuser' => $dbuser,
|
||||
'$dbpass' => $dbpass,
|
||||
'$dbdata' => $dbdata,
|
||||
'$timezone' => $timezone,
|
||||
'$language' => $language,
|
||||
'$urlpath' => $urlpath,
|
||||
'$adminmail' => $adminmail,
|
||||
'$dbhost' => $configCache->get('database', 'hostname'),
|
||||
'$dbuser' => $configCache->get('database', 'username'),
|
||||
'$dbpass' => $configCache->get('database', 'password'),
|
||||
'$dbdata' => $configCache->get('database', 'database'),
|
||||
|
||||
'$phpath' => $this->getPHPPath(),
|
||||
'$adminmail' => $configCache->get('config', 'admin_email'),
|
||||
|
||||
'$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);
|
||||
|
@ -594,16 +590,17 @@ class Installer
|
|||
* @param string $basePath The basepath of this call
|
||||
* @param IConfigCache $configCache The configuration cache
|
||||
* @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
|
||||
* @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)) {
|
||||
$this->addCheck(L10n::t('Could not connect to database.'), false, true, '');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue