Merge pull request #7006 from nupplaphil/feature/install_enhancement
Adding basepath/url settings to the installer
This commit is contained in:
commit
e0911efc87
26 changed files with 573 additions and 298 deletions
|
@ -144,9 +144,7 @@ if (!$foreground) {
|
||||||
file_put_contents($pidfile, $pid);
|
file_put_contents($pidfile, $pid);
|
||||||
|
|
||||||
// We lose the database connection upon forking
|
// We lose the database connection upon forking
|
||||||
/// @todo refactoring during https://github.com/friendica/friendica/issues/6720
|
Factory\DBFactory::init($a->getConfigCache(), $a->getProfiler(), $_SERVER);
|
||||||
$basePath = \Friendica\Util\BasePath::create(dirname(__DIR__), $_SERVER);
|
|
||||||
Factory\DBFactory::init($basePath, $a->getConfigCache(), $a->getProfiler(), $_SERVER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::set('system', 'worker_daemon_mode', true);
|
Config::set('system', 'worker_daemon_mode', true);
|
||||||
|
|
|
@ -37,5 +37,6 @@ return [
|
||||||
'system' => [
|
'system' => [
|
||||||
'default_timezone' => 'UTC',
|
'default_timezone' => 'UTC',
|
||||||
'language' => 'en',
|
'language' => 'en',
|
||||||
|
'basepath' => '/vagrant',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
10
src/App.php
10
src/App.php
|
@ -138,6 +138,16 @@ class App
|
||||||
return $this->config->getCache();
|
return $this->config->getCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current config of this node
|
||||||
|
*
|
||||||
|
* @return Configuration
|
||||||
|
*/
|
||||||
|
public function getConfig()
|
||||||
|
{
|
||||||
|
return $this->config;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The basepath of this app
|
* The basepath of this app
|
||||||
*
|
*
|
||||||
|
|
|
@ -15,6 +15,9 @@ use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
*/
|
*/
|
||||||
class BaseObject
|
class BaseObject
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var App
|
||||||
|
*/
|
||||||
private static $app = null;
|
private static $app = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,6 +7,8 @@ use Friendica\BaseObject;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\Installer;
|
use Friendica\Core\Installer;
|
||||||
use Friendica\Core\Theme;
|
use Friendica\Core\Theme;
|
||||||
|
use Friendica\Util\BasePath;
|
||||||
|
use Friendica\Util\BaseURL;
|
||||||
use Friendica\Util\Config\ConfigFileLoader;
|
use Friendica\Util\Config\ConfigFileLoader;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
|
@ -36,10 +38,10 @@ Options
|
||||||
-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|--url <url> The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL)
|
||||||
-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)
|
||||||
-A|--admin <mail> The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL)
|
-b|--basepath <base_path> The basepath of Friendica (env FRIENDICA_BASE_PATH)
|
||||||
-T|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
|
-t|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
|
||||||
-L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
|
-L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
|
||||||
|
|
||||||
Environment variables
|
Environment variables
|
||||||
|
@ -48,8 +50,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')
|
FRIENDICA_URL The full base URL of Friendica - f.e. 'https://friendica.local/sub'
|
||||||
FRIENDICA_PHP_PATH The path of the PHP binary
|
FRIENDICA_PHP_PATH The path of the PHP binary - leave empty for auto detection
|
||||||
|
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_TZ The timezone of Friendica
|
FRIENDICA_TZ The timezone of Friendica
|
||||||
FRIENDICA_LANG The langauge of Friendica
|
FRIENDICA_LANG The langauge of Friendica
|
||||||
|
@ -76,6 +79,7 @@ HELP;
|
||||||
$installer = new Installer();
|
$installer = new Installer();
|
||||||
|
|
||||||
$configCache = $a->getConfigCache();
|
$configCache = $a->getConfigCache();
|
||||||
|
$installer->setUpCache($configCache, BasePath::create($a->getBasePath(), $_SERVER));
|
||||||
|
|
||||||
$this->out(" Complete!\n\n");
|
$this->out(" Complete!\n\n");
|
||||||
|
|
||||||
|
@ -113,7 +117,6 @@ HELP;
|
||||||
|
|
||||||
$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') ? getenv('MYSQL_HOST') : Installer::DEFAULT_HOST) : '');
|
|
||||||
$db_host = $this->getOption(['H', 'dbhost'], ($save_db) ? (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);
|
||||||
$configCache->set('database', 'hostname', $db_host . (!empty($db_port) ? ':' . $db_port : ''));
|
$configCache->set('database', 'hostname', $db_host . (!empty($db_port) ? ':' . $db_port : ''));
|
||||||
|
@ -126,10 +129,14 @@ HELP;
|
||||||
$configCache->set('database', 'password',
|
$configCache->set('database', 'password',
|
||||||
$this->getOption(['P', 'dbpass'],
|
$this->getOption(['P', 'dbpass'],
|
||||||
($save_db) ? getenv('MYSQL_PASSWORD') : ''));
|
($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);
|
||||||
if (!empty($php_path)) {
|
if (!empty($php_path)) {
|
||||||
$configCache->set('config', 'php_path', $php_path);
|
$configCache->set('config', 'php_path', $php_path);
|
||||||
|
} else {
|
||||||
|
$configCache->set('config', 'php_path', $installer->getPHPPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
$configCache->set('config', 'admin_email',
|
$configCache->set('config', 'admin_email',
|
||||||
$this->getOption(['A', 'admin'],
|
$this->getOption(['A', 'admin'],
|
||||||
!empty(getenv('FRIENDICA_ADMIN_MAIL')) ? getenv('FRIENDICA_ADMIN_MAIL') : ''));
|
!empty(getenv('FRIENDICA_ADMIN_MAIL')) ? getenv('FRIENDICA_ADMIN_MAIL') : ''));
|
||||||
|
@ -140,16 +147,22 @@ HELP;
|
||||||
$this->getOption(['L', 'lang'],
|
$this->getOption(['L', 'lang'],
|
||||||
!empty(getenv('FRIENDICA_LANG')) ? getenv('FRIENDICA_LANG') : Installer::DEFAULT_LANG));
|
!empty(getenv('FRIENDICA_LANG')) ? getenv('FRIENDICA_LANG') : Installer::DEFAULT_LANG));
|
||||||
|
|
||||||
|
$basepath = $this->getOption(['b', 'basepath'], !empty(getenv('FRIENDICA_BASE_PATH')) ? getenv('FRIENDICA_BASE_PATH') : null);
|
||||||
if (empty($php_path)) {
|
if (!empty($basepath)) {
|
||||||
$configCache->set('config', 'php_path', $installer->getPHPPath());
|
$configCache->set('system', 'basepath', $basepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
$installer->createConfig(
|
$url = $this->getOption(['U', 'url'], !empty(getenv('FRIENDICA_URL')) ? getenv('FRIENDICA_URL') : null);
|
||||||
$a,
|
|
||||||
$configCache,
|
if (empty($url)) {
|
||||||
$a->getBasePath()
|
$this->out('The Friendica URL has to be set during CLI installation.');
|
||||||
);
|
return 1;
|
||||||
|
} else {
|
||||||
|
$baseUrl = new BaseURL($a->getConfig(), []);
|
||||||
|
$baseUrl->saveByURL($url);
|
||||||
|
}
|
||||||
|
|
||||||
|
$installer->createConfig($configCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->out(" Complete!\n\n");
|
$this->out(" Complete!\n\n");
|
||||||
|
@ -159,7 +172,7 @@ HELP;
|
||||||
|
|
||||||
$installer->resetChecks();
|
$installer->resetChecks();
|
||||||
|
|
||||||
if (!$installer->checkDB($a->getBasePath(), $configCache, $a->getProfiler())) {
|
if (!$installer->checkDB($configCache, $a->getProfiler())) {
|
||||||
$errorMessage = $this->extractErrors($installer->getChecks());
|
$errorMessage = $this->extractErrors($installer->getChecks());
|
||||||
throw new RuntimeException($errorMessage);
|
throw new RuntimeException($errorMessage);
|
||||||
}
|
}
|
||||||
|
@ -220,10 +233,7 @@ HELP;
|
||||||
$checked = false;
|
$checked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$php_path = null;
|
|
||||||
if ($configCache->has('config', 'php_path')) {
|
|
||||||
$php_path = $configCache->get('config', 'php_path');
|
$php_path = $configCache->get('config', 'php_path');
|
||||||
}
|
|
||||||
|
|
||||||
if (!$installer->checkPHP($php_path, true)) {
|
if (!$installer->checkPHP($php_path, true)) {
|
||||||
$checked = false;
|
$checked = false;
|
||||||
|
|
|
@ -6,7 +6,6 @@ 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;
|
||||||
|
@ -131,15 +130,15 @@ class Installer
|
||||||
* - Creates `config/local.config.php`
|
* - Creates `config/local.config.php`
|
||||||
* - Installs Database Structure
|
* - Installs Database Structure
|
||||||
*
|
*
|
||||||
* @param App $app The Friendica App
|
|
||||||
* @param IConfigCache $configCache The config cache with all config relevant information
|
* @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
|
* @return bool true if the config was created, otherwise false
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public function createConfig(App $app, IConfigCache $configCache, $basepath)
|
public function createConfig(IConfigCache $configCache)
|
||||||
{
|
{
|
||||||
|
$basepath = $configCache->get('system', 'basepath');
|
||||||
|
|
||||||
$tpl = Renderer::getMarkupTemplate('local.config.tpl');
|
$tpl = Renderer::getMarkupTemplate('local.config.tpl');
|
||||||
$txt = Renderer::replaceMacros($tpl, [
|
$txt = Renderer::replaceMacros($tpl, [
|
||||||
'$dbhost' => $configCache->get('database', 'hostname'),
|
'$dbhost' => $configCache->get('database', 'hostname'),
|
||||||
|
@ -147,13 +146,17 @@ class Installer
|
||||||
'$dbpass' => $configCache->get('database', 'password'),
|
'$dbpass' => $configCache->get('database', 'password'),
|
||||||
'$dbdata' => $configCache->get('database', 'database'),
|
'$dbdata' => $configCache->get('database', 'database'),
|
||||||
|
|
||||||
'$phpath' => $this->getPHPPath(),
|
'$phpath' => $configCache->get('config', 'php_path'),
|
||||||
'$adminmail' => $configCache->get('config', 'admin_email'),
|
'$adminmail' => $configCache->get('config', 'admin_email'),
|
||||||
|
'$hostname' => $configCache->get('config', 'hostname'),
|
||||||
|
|
||||||
|
'$urlpath' => $configCache->get('system', 'urlpath'),
|
||||||
|
'$baseurl' => $configCache->get('system', 'url'),
|
||||||
|
'$sslpolicy' => $configCache->get('system', 'ssl_policy'),
|
||||||
|
'$basepath' => $basepath,
|
||||||
'$timezone' => $configCache->get('system', 'default_timezone'),
|
'$timezone' => $configCache->get('system', 'default_timezone'),
|
||||||
'$language' => $configCache->get('system', 'language'),
|
'$language' => $configCache->get('system', 'language'),
|
||||||
'$urlpath' => $app->getURLPath(),
|
], false);
|
||||||
]);
|
|
||||||
|
|
||||||
$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);
|
||||||
|
|
||||||
|
@ -243,8 +246,9 @@ class Installer
|
||||||
$help .= L10n::t("If you don't have a command line version of PHP installed on your server, you will not be able to run the background processing. See <a href='https://github.com/friendica/friendica/blob/master/doc/Install.md#set-up-the-worker'>'Setup the worker'</a>") . EOL;
|
$help .= L10n::t("If you don't have a command line version of PHP installed on your server, you will not be able to run the background processing. See <a href='https://github.com/friendica/friendica/blob/master/doc/Install.md#set-up-the-worker'>'Setup the worker'</a>") . EOL;
|
||||||
$help .= EOL . EOL;
|
$help .= EOL . EOL;
|
||||||
$tpl = Renderer::getMarkupTemplate('field_input.tpl');
|
$tpl = Renderer::getMarkupTemplate('field_input.tpl');
|
||||||
|
/// @todo Separate backend Installer class and presentation layer/view
|
||||||
$help .= Renderer::replaceMacros($tpl, [
|
$help .= Renderer::replaceMacros($tpl, [
|
||||||
'$field' => ['phpath', L10n::t('PHP executable path'), $phppath, L10n::t('Enter full path to php executable. You can leave this blank to continue the installation.')],
|
'$field' => ['config-php_path', L10n::t('PHP executable path'), $phppath, L10n::t('Enter full path to php executable. You can leave this blank to continue the installation.')],
|
||||||
]);
|
]);
|
||||||
$phppath = "";
|
$phppath = "";
|
||||||
}
|
}
|
||||||
|
@ -588,21 +592,20 @@ class Installer
|
||||||
/**
|
/**
|
||||||
* Checking the Database connection and if it is available for the current installation
|
* Checking the Database connection and if it is available for the current installation
|
||||||
*
|
*
|
||||||
* @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
|
||||||
*
|
*
|
||||||
* @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)
|
public function checkDB(IConfigCache $configCache, Profiler $profiler)
|
||||||
{
|
{
|
||||||
$dbhost = $configCache->get('database', 'hostname');
|
$dbhost = $configCache->get('database', 'hostname');
|
||||||
$dbuser = $configCache->get('database', 'username');
|
$dbuser = $configCache->get('database', 'username');
|
||||||
$dbpass = $configCache->get('database', 'password');
|
$dbpass = $configCache->get('database', 'password');
|
||||||
$dbdata = $configCache->get('database', 'database');
|
$dbdata = $configCache->get('database', 'database');
|
||||||
|
|
||||||
if (!DBA::connect($basePath, $configCache, $profiler, new VoidLogger(), $dbhost, $dbuser, $dbpass, $dbdata)) {
|
if (!DBA::connect($configCache, $profiler, new VoidLogger(), $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, '');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -618,4 +621,18 @@ class Installer
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup the default cache for a new installation
|
||||||
|
*
|
||||||
|
* @param IConfigCache $configCache The configuration cache
|
||||||
|
* @param string $basePath The determined basepath
|
||||||
|
*
|
||||||
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
|
*/
|
||||||
|
public function setUpCache(IConfigCache $configCache, $basePath)
|
||||||
|
{
|
||||||
|
$configCache->set('config', 'php_path' , $this->getPHPPath());
|
||||||
|
$configCache->set('system', 'basepath' , $basePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,17 +54,20 @@ class Renderer extends BaseObject
|
||||||
*
|
*
|
||||||
* @param string|FriendicaSmarty $s The string requiring macro substitution or an instance of FriendicaSmarty
|
* @param string|FriendicaSmarty $s The string requiring macro substitution or an instance of FriendicaSmarty
|
||||||
* @param array $vars key value pairs (search => replace)
|
* @param array $vars key value pairs (search => replace)
|
||||||
|
* @param bool $overwriteURL Overwrite the base url with the system wide set base url
|
||||||
*
|
*
|
||||||
* @return string substituted string
|
* @return string substituted string
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public static function replaceMacros($s, $vars)
|
public static function replaceMacros($s, $vars, $overwriteURL = true)
|
||||||
{
|
{
|
||||||
$stamp1 = microtime(true);
|
$stamp1 = microtime(true);
|
||||||
$a = self::getApp();
|
$a = self::getApp();
|
||||||
|
|
||||||
// pass $baseurl to all templates
|
// pass $baseurl to all templates
|
||||||
|
if ($overwriteURL) {
|
||||||
$vars['$baseurl'] = System::baseUrl();
|
$vars['$baseurl'] = System::baseUrl();
|
||||||
|
}
|
||||||
$t = self::getTemplateEngine();
|
$t = self::getTemplateEngine();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -44,10 +44,6 @@ class DBA
|
||||||
* @var LoggerInterface
|
* @var LoggerInterface
|
||||||
*/
|
*/
|
||||||
private static $logger;
|
private static $logger;
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private static $basePath;
|
|
||||||
private static $server_info = '';
|
private static $server_info = '';
|
||||||
private static $connection;
|
private static $connection;
|
||||||
private static $driver;
|
private static $driver;
|
||||||
|
@ -63,14 +59,13 @@ class DBA
|
||||||
private static $db_name = '';
|
private static $db_name = '';
|
||||||
private static $db_charset = '';
|
private static $db_charset = '';
|
||||||
|
|
||||||
public static function connect($basePath, IConfigCache $configCache, Profiler $profiler, LoggerInterface $logger, $serveraddr, $user, $pass, $db, $charset = null)
|
public static function connect(IConfigCache $configCache, Profiler $profiler, LoggerInterface $logger, $serveraddr, $user, $pass, $db, $charset = null)
|
||||||
{
|
{
|
||||||
if (!is_null(self::$connection) && self::connected()) {
|
if (!is_null(self::$connection) && self::connected()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are storing these values for being able to perform a reconnect
|
// We are storing these values for being able to perform a reconnect
|
||||||
self::$basePath = $basePath;
|
|
||||||
self::$configCache = $configCache;
|
self::$configCache = $configCache;
|
||||||
self::$profiler = $profiler;
|
self::$profiler = $profiler;
|
||||||
self::$logger = $logger;
|
self::$logger = $logger;
|
||||||
|
@ -189,7 +184,7 @@ class DBA
|
||||||
public static function reconnect() {
|
public static function reconnect() {
|
||||||
self::disconnect();
|
self::disconnect();
|
||||||
|
|
||||||
$ret = self::connect(self::$basePath, self::$configCache, self::$profiler, self::$logger, self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name, self::$db_charset);
|
$ret = self::connect(self::$configCache, self::$profiler, self::$logger, self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name, self::$db_charset);
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1079,7 +1074,7 @@ class DBA
|
||||||
* This process must only be started once, since the value is cached.
|
* This process must only be started once, since the value is cached.
|
||||||
*/
|
*/
|
||||||
private static function buildRelationData() {
|
private static function buildRelationData() {
|
||||||
$definition = DBStructure::definition(self::$basePath);
|
$definition = DBStructure::definition(self::$configCache->get('system', 'basepath'));
|
||||||
|
|
||||||
foreach ($definition AS $table => $structure) {
|
foreach ($definition AS $table => $structure) {
|
||||||
foreach ($structure['fields'] AS $field => $field_struct) {
|
foreach ($structure['fields'] AS $field => $field_struct) {
|
||||||
|
|
|
@ -12,16 +12,13 @@ class DBFactory
|
||||||
/**
|
/**
|
||||||
* Initialize the DBA connection
|
* Initialize the DBA connection
|
||||||
*
|
*
|
||||||
* @param string $basePath The basepath of the application
|
|
||||||
* @param Cache\IConfigCache $configCache The configuration cache
|
* @param Cache\IConfigCache $configCache The configuration cache
|
||||||
* @param Profiler $profiler The profiler
|
* @param Profiler $profiler The profiler
|
||||||
* @param array $server The $_SERVER variables
|
* @param array $server The $_SERVER variables
|
||||||
*
|
*
|
||||||
* @throws \Exception if connection went bad
|
* @throws \Exception if connection went bad
|
||||||
*
|
|
||||||
* @todo refactor basedir during https://github.com/friendica/friendica/issues/6720
|
|
||||||
*/
|
*/
|
||||||
public static function init($basePath, Cache\IConfigCache $configCache, Profiler $profiler, array $server)
|
public static function init(Cache\IConfigCache $configCache, Profiler $profiler, array $server)
|
||||||
{
|
{
|
||||||
if (Database\DBA::connected()) {
|
if (Database\DBA::connected()) {
|
||||||
return;
|
return;
|
||||||
|
@ -52,9 +49,9 @@ class DBFactory
|
||||||
$db_data = $server['MYSQL_DATABASE'];
|
$db_data = $server['MYSQL_DATABASE'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database\DBA::connect($basePath, $configCache, $profiler, new VoidLogger(), $db_host, $db_user, $db_pass, $db_data, $charset)) {
|
if (Database\DBA::connect($configCache, $profiler, new VoidLogger(), $db_host, $db_user, $db_pass, $db_data, $charset)) {
|
||||||
// Loads DB_UPDATE_VERSION constant
|
// Loads DB_UPDATE_VERSION constant
|
||||||
Database\DBStructure::definition($basePath, false);
|
Database\DBStructure::definition($configCache->get('system', 'basepath'), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($db_host, $db_user, $db_pass, $db_data, $charset);
|
unset($db_host, $db_user, $db_pass, $db_data, $charset);
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
namespace Friendica\Factory;
|
namespace Friendica\Factory;
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Database\DBA;
|
|
||||||
use Friendica\Factory;
|
use Friendica\Factory;
|
||||||
use Friendica\Util\BasePath;
|
use Friendica\Util\BasePath;
|
||||||
use Friendica\Util\BaseURL;
|
use Friendica\Util\BaseURL;
|
||||||
|
@ -30,12 +29,11 @@ class DependencyFactory
|
||||||
$configLoader = new Config\ConfigFileLoader($basePath, $mode);
|
$configLoader = new Config\ConfigFileLoader($basePath, $mode);
|
||||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||||
Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
|
Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
||||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||||
// needed to call PConfig::init()
|
// needed to call PConfig::init()
|
||||||
Factory\ConfigFactory::createPConfig($configCache);
|
Factory\ConfigFactory::createPConfig($configCache);
|
||||||
$logger = Factory\LoggerFactory::create($channel, $config, $profiler);
|
$logger = Factory\LoggerFactory::create($channel, $config, $profiler);
|
||||||
DBA::setLogger($logger);
|
|
||||||
Factory\LoggerFactory::createDev($channel, $config, $profiler);
|
Factory\LoggerFactory::createDev($channel, $config, $profiler);
|
||||||
$baseURL = new BaseURL($config, $_SERVER);
|
$baseURL = new BaseURL($config, $_SERVER);
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ use Friendica\Core;
|
||||||
use Friendica\Core\Config\Cache\IConfigCache;
|
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\BasePath;
|
||||||
|
use Friendica\Util\BaseURL;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use Friendica\Util\Temporal;
|
use Friendica\Util\Temporal;
|
||||||
|
|
||||||
|
@ -18,17 +20,21 @@ class Install extends BaseModule
|
||||||
*/
|
*/
|
||||||
const SYSTEM_CHECK = 1;
|
const SYSTEM_CHECK = 1;
|
||||||
/**
|
/**
|
||||||
* Step two - Database configuration
|
* Step two - Base information
|
||||||
*/
|
*/
|
||||||
const DATABASE_CONFIG = 2;
|
const BASE_CONFIG = 2;
|
||||||
/**
|
/**
|
||||||
* Step three - Adapat site settings
|
* Step three - Database configuration
|
||||||
*/
|
*/
|
||||||
const SITE_SETTINGS = 3;
|
const DATABASE_CONFIG = 3;
|
||||||
/**
|
/**
|
||||||
* Step four - All steps finished
|
* Step four - Adapt site settings
|
||||||
*/
|
*/
|
||||||
const FINISHED = 4;
|
const SITE_SETTINGS = 4;
|
||||||
|
/**
|
||||||
|
* Step five - All steps finished
|
||||||
|
*/
|
||||||
|
const FINISHED = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int The current step of the wizard
|
* @var int The current step of the wizard
|
||||||
|
@ -55,11 +61,16 @@ class Install extends BaseModule
|
||||||
Core\System::httpExit(204);
|
Core\System::httpExit(204);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self::$installer = new Core\Installer();
|
||||||
|
|
||||||
|
// get basic installation information and save them to the config cache
|
||||||
|
$configCache = $a->getConfigCache();
|
||||||
|
self::$installer->setUpCache($configCache, BasePath::create($a->getBasePath(), $_SERVER));
|
||||||
|
|
||||||
// We overwrite current theme css, because during install we may not have a working mod_rewrite
|
// We overwrite current theme css, because during install we may not have a working mod_rewrite
|
||||||
// so we may not have a css at all. Here we set a static css file for the install procedure pages
|
// so we may not have a css at all. Here we set a static css file for the install procedure pages
|
||||||
Renderer::$theme['stylesheet'] = $a->getBaseURL() . '/view/install/style.css';
|
Renderer::$theme['stylesheet'] = $a->getBaseURL() . '/view/install/style.css';
|
||||||
|
|
||||||
self::$installer = new Core\Installer();
|
|
||||||
self::$currentWizardStep = defaults($_POST, 'pass', self::SYSTEM_CHECK);
|
self::$currentWizardStep = defaults($_POST, 'pass', self::SYSTEM_CHECK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,20 +81,34 @@ class Install extends BaseModule
|
||||||
|
|
||||||
switch (self::$currentWizardStep) {
|
switch (self::$currentWizardStep) {
|
||||||
case self::SYSTEM_CHECK:
|
case self::SYSTEM_CHECK:
|
||||||
|
case self::BASE_CONFIG:
|
||||||
|
self::checkSetting($configCache, $_POST, 'config', 'php_path');
|
||||||
|
break;
|
||||||
|
|
||||||
case self::DATABASE_CONFIG:
|
case self::DATABASE_CONFIG:
|
||||||
self::checkSetting($configCache, $_POST, 'config', 'php_path');
|
self::checkSetting($configCache, $_POST, 'config', 'php_path');
|
||||||
|
|
||||||
|
self::checkSetting($configCache, $_POST, 'config', 'hostname');
|
||||||
|
self::checkSetting($configCache, $_POST, 'system', 'ssl_policy');
|
||||||
|
self::checkSetting($configCache, $_POST, 'system', 'basepath');
|
||||||
|
self::checkSetting($configCache, $_POST, 'system', 'urlpath');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case self::SITE_SETTINGS:
|
case self::SITE_SETTINGS:
|
||||||
self::checkSetting($configCache, $_POST, 'config', 'php_path');
|
self::checkSetting($configCache, $_POST, 'config', 'php_path');
|
||||||
|
|
||||||
|
self::checkSetting($configCache, $_POST, 'config', 'hostname');
|
||||||
|
self::checkSetting($configCache, $_POST, 'system', 'ssl_policy');
|
||||||
|
self::checkSetting($configCache, $_POST, 'system', 'basepath');
|
||||||
|
self::checkSetting($configCache, $_POST, 'system', 'urlpath');
|
||||||
|
|
||||||
self::checkSetting($configCache, $_POST, 'database', 'hostname', Core\Installer::DEFAULT_HOST);
|
self::checkSetting($configCache, $_POST, 'database', 'hostname', Core\Installer::DEFAULT_HOST);
|
||||||
self::checkSetting($configCache, $_POST, 'database', 'username', '');
|
self::checkSetting($configCache, $_POST, 'database', 'username', '');
|
||||||
self::checkSetting($configCache, $_POST, 'database', 'password', '');
|
self::checkSetting($configCache, $_POST, 'database', 'password', '');
|
||||||
self::checkSetting($configCache, $_POST, 'database', 'database', '');
|
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(), $configCache, $a->getProfiler())) {
|
if (!self::$installer->checkDB($configCache, $a->getProfiler())) {
|
||||||
self::$currentWizardStep = self::DATABASE_CONFIG;
|
self::$currentWizardStep = self::DATABASE_CONFIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +117,11 @@ class Install extends BaseModule
|
||||||
case self::FINISHED:
|
case self::FINISHED:
|
||||||
self::checkSetting($configCache, $_POST, 'config', 'php_path');
|
self::checkSetting($configCache, $_POST, 'config', 'php_path');
|
||||||
|
|
||||||
|
self::checkSetting($configCache, $_POST, 'config', 'hostname');
|
||||||
|
self::checkSetting($configCache, $_POST, 'system', 'ssl_policy');
|
||||||
|
self::checkSetting($configCache, $_POST, 'system', 'basepath');
|
||||||
|
self::checkSetting($configCache, $_POST, 'system', 'urlpath');
|
||||||
|
|
||||||
self::checkSetting($configCache, $_POST, 'database', 'hostname', Core\Installer::DEFAULT_HOST);
|
self::checkSetting($configCache, $_POST, 'database', 'hostname', Core\Installer::DEFAULT_HOST);
|
||||||
self::checkSetting($configCache, $_POST, 'database', 'username', '');
|
self::checkSetting($configCache, $_POST, 'database', 'username', '');
|
||||||
self::checkSetting($configCache, $_POST, 'database', 'password', '');
|
self::checkSetting($configCache, $_POST, 'database', 'password', '');
|
||||||
|
@ -102,16 +132,16 @@ class Install extends BaseModule
|
||||||
self::checkSetting($configCache, $_POST, 'config', 'admin_email', '');
|
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(), $configCache, $a->getProfiler())) {
|
if (!self::$installer->checkDB($configCache, $a->getProfiler())) {
|
||||||
self::$currentWizardStep = self::DATABASE_CONFIG;
|
self::$currentWizardStep = self::DATABASE_CONFIG;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!self::$installer->createConfig($a, $configCache, $a->getBasePath())) {
|
if (!self::$installer->createConfig($configCache)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$installer->installDatabase($a->getBasePath());
|
self::$installer->installDatabase($configCache->get('system', 'basepath'));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -146,6 +176,43 @@ class Install extends BaseModule
|
||||||
]);
|
]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case self::BASE_CONFIG:
|
||||||
|
$ssl_choices = [
|
||||||
|
BaseUrl::SSL_POLICY_NONE => L10n::t("No SSL policy, links will track page SSL state"),
|
||||||
|
BaseUrl::SSL_POLICY_FULL => L10n::t("Force all links to use SSL"),
|
||||||
|
BaseUrl::SSL_POLICY_SELFSIGN => L10n::t("Self-signed certificate, use SSL for local links only \x28discouraged\x29")
|
||||||
|
];
|
||||||
|
|
||||||
|
$tpl = Renderer::getMarkupTemplate('install_base.tpl');
|
||||||
|
$output .= Renderer::replaceMacros($tpl, [
|
||||||
|
'$title' => $install_title,
|
||||||
|
'$pass' => L10n::t('Base settings'),
|
||||||
|
'$ssl_policy' => ['system-ssl_policy',
|
||||||
|
L10n::t("SSL link policy"),
|
||||||
|
$configCache->get('system', 'ssl_policy'),
|
||||||
|
L10n::t("Determines whether generated links should be forced to use SSL"),
|
||||||
|
$ssl_choices],
|
||||||
|
'$hostname' => ['config-hostname',
|
||||||
|
L10n::t('Host name'),
|
||||||
|
$configCache->get('config', 'hostname'),
|
||||||
|
L10n::t('Overwrite this field in case the determinated hostname isn\'t right, otherweise leave it as is.'),
|
||||||
|
'required'],
|
||||||
|
'$basepath' => ['system-basepath',
|
||||||
|
L10n::t("Base path to installation"),
|
||||||
|
$configCache->get('system', 'basepath'),
|
||||||
|
L10n::t("If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot."),
|
||||||
|
'required'],
|
||||||
|
'$urlpath' => ['system-urlpath',
|
||||||
|
L10n::t('Sub path of the URL'),
|
||||||
|
$configCache->get('system', 'urlpath'),
|
||||||
|
L10n::t('Overwrite this field in case the sub path determination isn\'t right, otherwise leave it as is. Leaving this field blank means the installation is at the base URL without sub path.'),
|
||||||
|
''],
|
||||||
|
'$baseurl' => $a->getBaseURL(),
|
||||||
|
'$php_path' => $configCache->get('config', 'php_path'),
|
||||||
|
'$submit' => L10n::t('Submit'),
|
||||||
|
]);
|
||||||
|
break;
|
||||||
|
|
||||||
case self::DATABASE_CONFIG:
|
case self::DATABASE_CONFIG:
|
||||||
$tpl = Renderer::getMarkupTemplate('install_db.tpl');
|
$tpl = Renderer::getMarkupTemplate('install_db.tpl');
|
||||||
$output .= Renderer::replaceMacros($tpl, [
|
$output .= Renderer::replaceMacros($tpl, [
|
||||||
|
@ -155,6 +222,10 @@ class Install extends BaseModule
|
||||||
'$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(),
|
||||||
|
'$hostname' => $configCache->get('config', 'hostname'),
|
||||||
|
'$ssl_policy' => $configCache->get('system', 'ssl_policy'),
|
||||||
|
'$basepath' => $configCache->get('system', 'basepath'),
|
||||||
|
'$urlpath' => $configCache->get('system', 'urlpath'),
|
||||||
'$dbhost' => ['database-hostname',
|
'$dbhost' => ['database-hostname',
|
||||||
L10n::t('Database Server Name'),
|
L10n::t('Database Server Name'),
|
||||||
$configCache->get('database', 'hostname'),
|
$configCache->get('database', 'hostname'),
|
||||||
|
@ -192,11 +263,14 @@ 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'),
|
||||||
|
'$hostname' => $configCache->get('config', 'hostname'),
|
||||||
|
'$ssl_policy' => $configCache->get('system', 'ssl_policy'),
|
||||||
|
'$basepath' => $configCache->get('system', 'basepath'),
|
||||||
|
'$urlpath' => $configCache->get('system', 'urlpath'),
|
||||||
'$dbhost' => $configCache->get('database', 'hostname'),
|
'$dbhost' => $configCache->get('database', 'hostname'),
|
||||||
'$dbuser' => $configCache->get('database', 'username'),
|
'$dbuser' => $configCache->get('database', 'username'),
|
||||||
'$dbpass' => $configCache->get('database', 'password'),
|
'$dbpass' => $configCache->get('database', 'password'),
|
||||||
'$dbdata' => $configCache->get('database', 'database'),
|
'$dbdata' => $configCache->get('database', 'database'),
|
||||||
'$phpath' => $configCache->get('config', 'php_path'),
|
|
||||||
'$adminmail' => ['config-admin_email',
|
'$adminmail' => ['config-admin_email',
|
||||||
L10n::t('Site administrator email address'),
|
L10n::t('Site administrator email address'),
|
||||||
$configCache->get('config', 'admin_email'),
|
$configCache->get('config', 'admin_email'),
|
||||||
|
@ -212,6 +286,7 @@ class Install extends BaseModule
|
||||||
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(),
|
||||||
|
'$php_path' => $configCache->get('config', 'php_path'),
|
||||||
'$submit' => L10n::t('Submit')
|
'$submit' => L10n::t('Submit')
|
||||||
]);
|
]);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -285,7 +285,7 @@ class BaseURL
|
||||||
if (empty($this->url)) {
|
if (empty($this->url)) {
|
||||||
$this->determineBaseUrl();
|
$this->determineBaseUrl();
|
||||||
|
|
||||||
if (!empty($url)) {
|
if (!empty($this->url)) {
|
||||||
$this->config->set('system', 'url', $this->url);
|
$this->config->set('system', 'url', $this->url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@ abstract class DatabaseTest extends MockedTest
|
||||||
$profiler = \Mockery::mock(Profiler::class);
|
$profiler = \Mockery::mock(Profiler::class);
|
||||||
|
|
||||||
DBA::connect(
|
DBA::connect(
|
||||||
$basePath,
|
|
||||||
$config,
|
$config,
|
||||||
$profiler,
|
$profiler,
|
||||||
new VoidLogger(),
|
new VoidLogger(),
|
||||||
|
|
|
@ -39,10 +39,9 @@ trait AppMockTrait
|
||||||
* Mock the App
|
* Mock the App
|
||||||
*
|
*
|
||||||
* @param vfsStreamDirectory $root The root directory
|
* @param vfsStreamDirectory $root The root directory
|
||||||
* @param Config\Cache\ConfigCache $configCache
|
|
||||||
* @param bool $raw If true, no config mocking will be done
|
* @param bool $raw If true, no config mocking will be done
|
||||||
*/
|
*/
|
||||||
public function mockApp(vfsStreamDirectory $root, $configCache = null, $raw = false)
|
public function mockApp(vfsStreamDirectory $root, $raw = false)
|
||||||
{
|
{
|
||||||
$this->configMock = \Mockery::mock(Config\Cache\IConfigCache::class);
|
$this->configMock = \Mockery::mock(Config\Cache\IConfigCache::class);
|
||||||
$this->mode = \Mockery::mock(App\Mode::class);
|
$this->mode = \Mockery::mock(App\Mode::class);
|
||||||
|
@ -50,7 +49,7 @@ trait AppMockTrait
|
||||||
// Disable the adapter
|
// Disable the adapter
|
||||||
$configAdapterMock->shouldReceive('isConnected')->andReturn(false);
|
$configAdapterMock->shouldReceive('isConnected')->andReturn(false);
|
||||||
|
|
||||||
$config = new Config\Configuration((isset($configCache) ? $configCache : $this->configMock), $configAdapterMock);
|
$config = new Config\Configuration($this->configMock, $configAdapterMock);
|
||||||
// Initialize empty Config
|
// Initialize empty Config
|
||||||
Config::init($config);
|
Config::init($config);
|
||||||
|
|
||||||
|
@ -69,7 +68,10 @@ trait AppMockTrait
|
||||||
|
|
||||||
$this->app
|
$this->app
|
||||||
->shouldReceive('getConfigCache')
|
->shouldReceive('getConfigCache')
|
||||||
->andReturn((isset($configCache) ? $configCache : $this->configMock));
|
->andReturn($this->configMock);
|
||||||
|
$this->app
|
||||||
|
->shouldReceive('getConfig')
|
||||||
|
->andReturn($config);
|
||||||
$this->app
|
$this->app
|
||||||
->shouldReceive('getTemplateEngine')
|
->shouldReceive('getTemplateEngine')
|
||||||
->andReturn(new FriendicaSmartyEngine());
|
->andReturn(new FriendicaSmartyEngine());
|
||||||
|
@ -82,7 +84,7 @@ trait AppMockTrait
|
||||||
$this->app
|
$this->app
|
||||||
->shouldReceive('getBaseUrl')
|
->shouldReceive('getBaseUrl')
|
||||||
->andReturnUsing(function () {
|
->andReturnUsing(function () {
|
||||||
return $this->app->getConfigCache()->get('system', 'url');
|
return $this->configMock->get('system', 'url');
|
||||||
});
|
});
|
||||||
|
|
||||||
BaseObject::setApp($this->app);
|
BaseObject::setApp($this->app);
|
||||||
|
|
|
@ -37,10 +37,11 @@ trait RendererMockTrait
|
||||||
*
|
*
|
||||||
* @param string $template The template to use (normally, it is the mock result of 'mockGetMarkupTemplate()'
|
* @param string $template The template to use (normally, it is the mock result of 'mockGetMarkupTemplate()'
|
||||||
* @param array|\Closure|null $args The arguments to pass to the macro
|
* @param array|\Closure|null $args The arguments to pass to the macro
|
||||||
|
* @param bool $overwriteURL if the URL should get overwritten
|
||||||
* @param string $return the return value of the mock
|
* @param string $return the return value of the mock
|
||||||
* @param null|int $times How often the method will get used
|
* @param null|int $times How often the method will get used
|
||||||
*/
|
*/
|
||||||
public function mockReplaceMacros($template, $args = null, $return = '', $times = null)
|
public function mockReplaceMacros($template, $args = null, $overwriteURL = true, $return = '', $times = null)
|
||||||
{
|
{
|
||||||
if (!isset($this->rendererMock)) {
|
if (!isset($this->rendererMock)) {
|
||||||
$this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
|
$this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
|
||||||
|
@ -50,10 +51,18 @@ trait RendererMockTrait
|
||||||
$args = [];
|
$args = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($overwriteURL) {
|
||||||
$this->rendererMock
|
$this->rendererMock
|
||||||
->shouldReceive('replaceMacros')
|
->shouldReceive('replaceMacros')
|
||||||
->with($template, $args)
|
->with($template, $args)
|
||||||
->times($times)
|
->times($times)
|
||||||
->andReturn($return);
|
->andReturn($return);
|
||||||
|
} else {
|
||||||
|
$this->rendererMock
|
||||||
|
->shouldReceive('replaceMacros')
|
||||||
|
->with($template, $args, false)
|
||||||
|
->times($times)
|
||||||
|
->andReturn($return);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ class ApiTest extends DatabaseTest
|
||||||
$configLoader = new ConfigFileLoader($basePath, $mode);
|
$configLoader = new ConfigFileLoader($basePath, $mode);
|
||||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||||
Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
|
Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
||||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||||
Factory\ConfigFactory::createPConfig($configCache);
|
Factory\ConfigFactory::createPConfig($configCache);
|
||||||
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Friendica\Test\Util\DBAMockTrait;
|
||||||
use Friendica\Test\Util\DBStructureMockTrait;
|
use Friendica\Test\Util\DBStructureMockTrait;
|
||||||
use Friendica\Test\Util\L10nMockTrait;
|
use Friendica\Test\Util\L10nMockTrait;
|
||||||
use Friendica\Test\Util\RendererMockTrait;
|
use Friendica\Test\Util\RendererMockTrait;
|
||||||
|
use Friendica\Util\BaseURL;
|
||||||
use Friendica\Util\Logger\VoidLogger;
|
use Friendica\Util\Logger\VoidLogger;
|
||||||
use org\bovigo\vfs\vfsStream;
|
use org\bovigo\vfs\vfsStream;
|
||||||
use org\bovigo\vfs\vfsStreamFile;
|
use org\bovigo\vfs\vfsStreamFile;
|
||||||
|
@ -56,7 +57,7 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
|
||||||
$this->configCache->set('config', 'php_path', trim(shell_exec('which php')));
|
$this->configCache->set('config', 'php_path', trim(shell_exec('which php')));
|
||||||
$this->configCache->set('system', 'theme', 'smarty3');
|
$this->configCache->set('system', 'theme', 'smarty3');
|
||||||
|
|
||||||
$this->mockApp($this->root, null, true);
|
$this->mockApp($this->root, true);
|
||||||
|
|
||||||
$this->configMock->shouldReceive('set')->andReturnUsing(function ($cat, $key, $value) {
|
$this->configMock->shouldReceive('set')->andReturnUsing(function ($cat, $key, $value) {
|
||||||
if ($key !== 'basepath') {
|
if ($key !== 'basepath') {
|
||||||
|
@ -97,10 +98,14 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
|
||||||
],
|
],
|
||||||
'config' => [
|
'config' => [
|
||||||
'php_path' => '',
|
'php_path' => '',
|
||||||
|
'hostname' => 'friendica.local',
|
||||||
'admin_email' => '',
|
'admin_email' => '',
|
||||||
],
|
],
|
||||||
'system' => [
|
'system' => [
|
||||||
|
'basepath' => '',
|
||||||
'urlpath' => '',
|
'urlpath' => '',
|
||||||
|
'url' => 'http://friendica.local',
|
||||||
|
'ssl_policy' => 0,
|
||||||
'default_timezone' => '',
|
'default_timezone' => '',
|
||||||
'language' => '',
|
'language' => '',
|
||||||
],
|
],
|
||||||
|
@ -117,10 +122,14 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
|
||||||
],
|
],
|
||||||
'config' => [
|
'config' => [
|
||||||
'php_path' => '',
|
'php_path' => '',
|
||||||
|
'hostname' => 'friendica.local',
|
||||||
'admin_email' => 'admin@philipp.info',
|
'admin_email' => 'admin@philipp.info',
|
||||||
],
|
],
|
||||||
'system' => [
|
'system' => [
|
||||||
'urlpath' => 'test/it',
|
'urlpath' => 'test/it',
|
||||||
|
'url' => 'http://friendica.local/test/it',
|
||||||
|
'basepath' => '',
|
||||||
|
'ssl_policy' => '2',
|
||||||
'default_timezone' => 'en',
|
'default_timezone' => 'en',
|
||||||
'language' => 'Europe/Berlin',
|
'language' => 'Europe/Berlin',
|
||||||
],
|
],
|
||||||
|
@ -137,10 +146,14 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
|
||||||
],
|
],
|
||||||
'config' => [
|
'config' => [
|
||||||
'php_path' => '',
|
'php_path' => '',
|
||||||
|
'hostname' => 'friendica.local',
|
||||||
'admin_email' => 'admin@philipp.info',
|
'admin_email' => 'admin@philipp.info',
|
||||||
],
|
],
|
||||||
'system' => [
|
'system' => [
|
||||||
'urlpath' => 'test/it',
|
'urlpath' => 'test/it',
|
||||||
|
'url' => 'https://friendica.local/test/it',
|
||||||
|
'basepath' => '',
|
||||||
|
'ssl_policy' => '1',
|
||||||
'default_timezone' => 'en',
|
'default_timezone' => 'en',
|
||||||
'language' => 'Europe/Berlin',
|
'language' => 'Europe/Berlin',
|
||||||
],
|
],
|
||||||
|
@ -236,6 +249,30 @@ Checking database...
|
||||||
Could not connect to database.:
|
Could not connect to database.:
|
||||||
|
|
||||||
|
|
||||||
|
FIN;
|
||||||
|
|
||||||
|
$this->assertEquals($finished, $txt);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function assertStuckURL($txt)
|
||||||
|
{
|
||||||
|
$finished = <<<FIN
|
||||||
|
Initializing setup...
|
||||||
|
|
||||||
|
Complete!
|
||||||
|
|
||||||
|
|
||||||
|
Checking environment...
|
||||||
|
|
||||||
|
NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
|
||||||
|
|
||||||
|
Complete!
|
||||||
|
|
||||||
|
|
||||||
|
Creating config file...
|
||||||
|
|
||||||
|
The Friendica URL has to be set during CLI installation.
|
||||||
|
|
||||||
FIN;
|
FIN;
|
||||||
|
|
||||||
$this->assertEquals($finished, $txt);
|
$this->assertEquals($finished, $txt);
|
||||||
|
@ -269,8 +306,9 @@ FIN;
|
||||||
* @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
|
||||||
|
* @param boolean $realBasepath True, if we use the real basepath of the installation, not the mocked one
|
||||||
*/
|
*/
|
||||||
public function assertConfig($assertion = null, $saveDb = false, $default = true, $defaultDb = true)
|
public function assertConfig($assertion = null, $saveDb = false, $default = true, $defaultDb = true, $realBasepath = false)
|
||||||
{
|
{
|
||||||
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'] : '');
|
||||||
|
@ -283,34 +321,52 @@ FIN;
|
||||||
|
|
||||||
$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('config', 'hostname', $assertion);
|
||||||
|
|
||||||
$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', 'url', $assertion);
|
||||||
|
$this->assertConfigEntry('system', 'urlpath', $assertion);
|
||||||
|
$this->assertConfigEntry('system', 'ssl_policy', $assertion, ($default) ? BaseURL::DEFAULT_SSL_SCHEME : null);
|
||||||
|
$this->assertConfigEntry('system', 'basepath', ($realBasepath) ? $this->root->url() : $assertion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the automatic installation without any parameter/setting
|
* Test the automatic installation without any parameter/setting
|
||||||
|
* Should stuck because of missing hostname
|
||||||
*/
|
*/
|
||||||
public function testEmpty()
|
public function testEmpty()
|
||||||
{
|
{
|
||||||
$this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once();
|
$console = new AutomaticInstallation($this->consoleArgv);
|
||||||
|
|
||||||
|
$txt = $this->dumpExecute($console);
|
||||||
|
|
||||||
|
$this->assertStuckURL($txt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the automatic installation without any parameter/setting
|
||||||
|
* except URL
|
||||||
|
*/
|
||||||
|
public function testEmptyWithURL()
|
||||||
|
{
|
||||||
$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);
|
||||||
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
||||||
|
|
||||||
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
||||||
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
|
$this->mockReplaceMacros('testTemplate', \Mockery::any(), false, '', 1);
|
||||||
|
|
||||||
$console = new AutomaticInstallation($this->consoleArgv);
|
$console = new AutomaticInstallation($this->consoleArgv);
|
||||||
|
$console->setOption('url', 'http://friendica.local');
|
||||||
|
|
||||||
$txt = $this->dumpExecute($console);
|
$txt = $this->dumpExecute($console);
|
||||||
|
|
||||||
$this->assertFinished($txt, true, false);
|
$this->assertFinished($txt, true, false);
|
||||||
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
|
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
|
||||||
|
|
||||||
$this->assertConfig();
|
$this->assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local', 'ssl_policy' => 0, 'urlPath' => '']], false, true, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -356,12 +412,16 @@ return [
|
||||||
|
|
||||||
'config' => [
|
'config' => [
|
||||||
'admin_email' => '{$conf('config', 'admin_email')}',
|
'admin_email' => '{$conf('config', 'admin_email')}',
|
||||||
|
'hostname' => '{$conf('config', 'hostname')}',
|
||||||
'sitename' => 'Friendica Social Network',
|
'sitename' => 'Friendica Social Network',
|
||||||
'register_policy' => \Friendica\Module\Register::OPEN,
|
'register_policy' => \Friendica\Module\Register::OPEN,
|
||||||
'register_text' => '',
|
'register_text' => '',
|
||||||
],
|
],
|
||||||
'system' => [
|
'system' => [
|
||||||
|
'basepath' => '{$conf('system', 'basepath')}',
|
||||||
'urlpath' => '{$conf('system', 'urlpath')}',
|
'urlpath' => '{$conf('system', 'urlpath')}',
|
||||||
|
'url' => '{$conf('system', 'url')}',
|
||||||
|
'ssl_policy' => '{$conf('system', 'ssl_policy')}',
|
||||||
'default_timezone' => '{$conf('system', 'default_timezone')}',
|
'default_timezone' => '{$conf('system', 'default_timezone')}',
|
||||||
'language' => '{$conf('system', 'language')}',
|
'language' => '{$conf('system', 'language')}',
|
||||||
],
|
],
|
||||||
|
@ -392,15 +452,13 @@ 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);
|
||||||
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
||||||
|
|
||||||
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
||||||
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
|
$this->mockReplaceMacros('testTemplate', \Mockery::any(), false, '', 1);
|
||||||
|
|
||||||
$this->assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname']));
|
$this->assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname']));
|
||||||
$this->assertTrue(putenv('MYSQL_PORT=' . $data['database']['port']));
|
$this->assertTrue(putenv('MYSQL_PORT=' . $data['database']['port']));
|
||||||
|
@ -408,7 +466,9 @@ CONF;
|
||||||
$this->assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username']));
|
$this->assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username']));
|
||||||
$this->assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password']));
|
$this->assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password']));
|
||||||
|
|
||||||
$this->assertTrue(putenv('FRIENDICA_URL_PATH=' . $data['system']['urlpath']));
|
$this->assertTrue(putenv('FRIENDICA_HOSTNAME=' . $data['config']['hostname']));
|
||||||
|
$this->assertTrue(putenv('FRIENDICA_BASE_PATH=' . $data['system']['basepath']));
|
||||||
|
$this->assertTrue(putenv('FRIENDICA_URL=' . $data['system']['url']));
|
||||||
$this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path']));
|
$this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path']));
|
||||||
$this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email']));
|
$this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email']));
|
||||||
$this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone']));
|
$this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone']));
|
||||||
|
@ -420,7 +480,7 @@ CONF;
|
||||||
$txt = $this->dumpExecute($console);
|
$txt = $this->dumpExecute($console);
|
||||||
|
|
||||||
$this->assertFinished($txt, true);
|
$this->assertFinished($txt, true);
|
||||||
$this->assertConfig($data, true, true, false);
|
$this->assertConfig($data, true, true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -430,15 +490,13 @@ 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);
|
||||||
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
||||||
|
|
||||||
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
||||||
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
|
$this->mockReplaceMacros('testTemplate', \Mockery::any(), false, '', 1);
|
||||||
|
|
||||||
$this->assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname']));
|
$this->assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname']));
|
||||||
$this->assertTrue(putenv('MYSQL_PORT=' . $data['database']['port']));
|
$this->assertTrue(putenv('MYSQL_PORT=' . $data['database']['port']));
|
||||||
|
@ -446,7 +504,9 @@ CONF;
|
||||||
$this->assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username']));
|
$this->assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username']));
|
||||||
$this->assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password']));
|
$this->assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password']));
|
||||||
|
|
||||||
$this->assertTrue(putenv('FRIENDICA_URL_PATH=' . $data['system']['urlpath']));
|
$this->assertTrue(putenv('FRIENDICA_HOSTNAME=' . $data['config']['hostname']));
|
||||||
|
$this->assertTrue(putenv('FRIENDICA_BASE_PATH=' . $data['system']['basepath']));
|
||||||
|
$this->assertTrue(putenv('FRIENDICA_URL=' . $data['system']['url']));
|
||||||
$this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path']));
|
$this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path']));
|
||||||
$this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email']));
|
$this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email']));
|
||||||
$this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone']));
|
$this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone']));
|
||||||
|
@ -457,7 +517,7 @@ CONF;
|
||||||
$txt = $this->dumpExecute($console);
|
$txt = $this->dumpExecute($console);
|
||||||
|
|
||||||
$this->assertFinished($txt, true);
|
$this->assertFinished($txt, true);
|
||||||
$this->assertConfig($data, false, true);
|
$this->assertConfig($data, false, true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -466,15 +526,13 @@ 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);
|
||||||
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
$this->mockUpdate([$this->root->url(), false, true, true], null, 1);
|
||||||
|
|
||||||
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
|
||||||
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
|
$this->mockReplaceMacros('testTemplate', \Mockery::any(), false, '', 1);
|
||||||
|
|
||||||
$console = new AutomaticInstallation($this->consoleArgv);
|
$console = new AutomaticInstallation($this->consoleArgv);
|
||||||
|
|
||||||
|
@ -488,16 +546,17 @@ CONF;
|
||||||
$option('dbuser' , 'database', 'username');
|
$option('dbuser' , 'database', 'username');
|
||||||
$option('dbpass' , 'database', 'password');
|
$option('dbpass' , 'database', 'password');
|
||||||
$option('dbdata' , 'database', 'database');
|
$option('dbdata' , 'database', 'database');
|
||||||
$option('urlpath' , 'system' , 'urlpath');
|
$option('url' , 'system' , 'url');
|
||||||
$option('phppath' , 'config' , 'php_path');
|
$option('phppath' , 'config' , 'php_path');
|
||||||
$option('admin' , 'config' , 'admin_email');
|
$option('admin' , 'config' , 'admin_email');
|
||||||
$option('tz' , 'system' , 'default_timezone');
|
$option('tz' , 'system' , 'default_timezone');
|
||||||
$option('lang' , 'system' , 'language');
|
$option('lang' , 'system' , 'language');
|
||||||
|
$option('basepath' , 'system' , 'basepath');
|
||||||
|
|
||||||
$txt = $this->dumpExecute($console);
|
$txt = $this->dumpExecute($console);
|
||||||
|
|
||||||
$this->assertFinished($txt, true);
|
$this->assertFinished($txt, true);
|
||||||
$this->assertConfig($data, true, true, true);
|
$this->assertConfig($data, true, true, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -505,20 +564,20 @@ 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);
|
||||||
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
|
$this->mockReplaceMacros('testTemplate', \Mockery::any(), false, '', 1);
|
||||||
|
|
||||||
$console = new AutomaticInstallation($this->consoleArgv);
|
$console = new AutomaticInstallation($this->consoleArgv);
|
||||||
|
$console->setOption('url', 'http://friendica.local');
|
||||||
|
|
||||||
$txt = $this->dumpExecute($console);
|
$txt = $this->dumpExecute($console);
|
||||||
|
|
||||||
$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, false, true, false);
|
$this->assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local', 'ssl_policy' => 0, 'urlpath' => '']], false, true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetHelp()
|
public function testGetHelp()
|
||||||
|
@ -546,10 +605,10 @@ Options
|
||||||
-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|--url <url> The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL)
|
||||||
-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)
|
||||||
-A|--admin <mail> The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL)
|
-b|--basepath <base_path> The basepath of Friendica (env FRIENDICA_BASE_PATH)
|
||||||
-T|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
|
-t|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
|
||||||
-L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
|
-L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
|
||||||
|
|
||||||
Environment variables
|
Environment variables
|
||||||
|
@ -558,8 +617,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')
|
FRIENDICA_URL The full base URL of Friendica - f.e. 'https://friendica.local/sub'
|
||||||
FRIENDICA_PHP_PATH The path of the PHP binary
|
FRIENDICA_PHP_PATH The path of the PHP binary - leave empty for auto detection
|
||||||
|
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_TZ The timezone of Friendica
|
FRIENDICA_TZ The timezone of Friendica
|
||||||
FRIENDICA_LANG The langauge of Friendica
|
FRIENDICA_LANG The langauge of Friendica
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
// this is in the same namespace as Install for mocking 'function_exists'
|
// this is in the same namespace as Install for mocking 'function_exists'
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core;
|
||||||
|
|
||||||
|
use Friendica\Core\Config\Cache\IConfigCache;
|
||||||
use Friendica\Network\CurlResult;
|
use Friendica\Network\CurlResult;
|
||||||
use Friendica\Object\Image;
|
use Friendica\Object\Image;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
|
@ -392,6 +393,21 @@ class InstallerTest extends MockedTest
|
||||||
false,
|
false,
|
||||||
$install->getChecks());
|
$install->getChecks());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the setup of the config cache for installation
|
||||||
|
*/
|
||||||
|
public function testSetUpCache()
|
||||||
|
{
|
||||||
|
$this->mockL10nT();
|
||||||
|
|
||||||
|
$install = new Installer();
|
||||||
|
$configCache = \Mockery::mock(IConfigCache::class);
|
||||||
|
$configCache->shouldReceive('set')->with('config', 'php_path', \Mockery::any())->once();
|
||||||
|
$configCache->shouldReceive('set')->with('system', 'basepath', '/test/')->once();
|
||||||
|
|
||||||
|
$install->setUpCache($configCache, '/test/');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,7 +20,7 @@ class DBATest extends DatabaseTest
|
||||||
$configLoader = new ConfigFileLoader($basePath, $mode);
|
$configLoader = new ConfigFileLoader($basePath, $mode);
|
||||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||||
Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
|
Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
||||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||||
Factory\ConfigFactory::createPConfig($configCache);
|
Factory\ConfigFactory::createPConfig($configCache);
|
||||||
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
||||||
|
|
|
@ -20,7 +20,7 @@ class DBStructureTest extends DatabaseTest
|
||||||
$configLoader = new ConfigFileLoader($basePath, $mode);
|
$configLoader = new ConfigFileLoader($basePath, $mode);
|
||||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||||
Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
|
Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
||||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||||
Factory\ConfigFactory::createPConfig($configCache);
|
Factory\ConfigFactory::createPConfig($configCache);
|
||||||
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
||||||
|
|
29
tests/src/Util/BasePathTest.php
Normal file
29
tests/src/Util/BasePathTest.php
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
namespace Friendica\Test\src\Util;
|
||||||
|
|
||||||
|
use Friendica\Test\MockedTest;
|
||||||
|
use Friendica\Util\BasePath;
|
||||||
|
|
||||||
|
class BasePathTest extends MockedTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test the basepath determination
|
||||||
|
*/
|
||||||
|
public function testDetermineBasePath()
|
||||||
|
{
|
||||||
|
$serverArr = ['DOCUMENT_ROOT' => '/invalid', 'PWD' => '/invalid2'];
|
||||||
|
$this->assertEquals('/valid', BasePath::create('/valid', $serverArr));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the basepath determination with DOCUMENT_ROOT and PWD
|
||||||
|
*/
|
||||||
|
public function testDetermineBasePathWithServer()
|
||||||
|
{
|
||||||
|
$serverArr = ['DOCUMENT_ROOT' => '/valid'];
|
||||||
|
$this->assertEquals('/valid', BasePath::create('', $serverArr));
|
||||||
|
|
||||||
|
$serverArr = ['PWD' => '/valid_too'];
|
||||||
|
$this->assertEquals('/valid_too', BasePath::create('', $serverArr));
|
||||||
|
}
|
||||||
|
}
|
|
@ -179,18 +179,26 @@ class BaseURLTest extends MockedTest
|
||||||
$configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($input['sslPolicy']);
|
$configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($input['sslPolicy']);
|
||||||
$configMock->shouldReceive('get')->with('system', 'url')->andReturn($input['url']);
|
$configMock->shouldReceive('get')->with('system', 'url')->andReturn($input['url']);
|
||||||
|
|
||||||
|
// If we don't have an urlPath as an input, we assert it, we will save it to the DB for the next time
|
||||||
if (!isset($input['urlPath']) && isset($assert['urlPath'])) {
|
if (!isset($input['urlPath']) && isset($assert['urlPath'])) {
|
||||||
$configMock->shouldReceive('set')->with('system', 'urlpath', $assert['urlPath'])->once();
|
$configMock->shouldReceive('set')->with('system', 'urlpath', $assert['urlPath'])->once();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we don't have the ssl_policy as an input, we assert it, we will save it to the DB for the next time
|
||||||
if (!isset($input['sslPolicy']) && isset($assert['sslPolicy'])) {
|
if (!isset($input['sslPolicy']) && isset($assert['sslPolicy'])) {
|
||||||
$configMock->shouldReceive('set')->with('system', 'ssl_policy', $assert['sslPolicy'])->once();
|
$configMock->shouldReceive('set')->with('system', 'ssl_policy', $assert['sslPolicy'])->once();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($input['hostname']) && !empty($assert['hostname'])) {
|
// If we don't have the hostname as an input, we assert it, we will save it to the DB for the next time
|
||||||
|
if (empty($input['hostname']) && !empty($assert['hostname'])) {
|
||||||
$configMock->shouldReceive('set')->with('config', 'hostname', $assert['hostname'])->once();
|
$configMock->shouldReceive('set')->with('config', 'hostname', $assert['hostname'])->once();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we don't have an URL at first, but we assert it, we will save it to the DB for the next time
|
||||||
|
if (empty($input['url']) && !empty($assert['url'])) {
|
||||||
|
$configMock->shouldReceive('set')->with('system', 'url', $assert['url'])->once();
|
||||||
|
}
|
||||||
|
|
||||||
$baseUrl = new BaseURL($configMock, $server);
|
$baseUrl = new BaseURL($configMock, $server);
|
||||||
|
|
||||||
$this->assertEquals($assert['hostname'], $baseUrl->getHostname());
|
$this->assertEquals($assert['hostname'], $baseUrl->getHostname());
|
||||||
|
|
34
view/templates/install_base.tpl
Normal file
34
view/templates/install_base.tpl
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<h1><img src="{{$baseurl}}/images/friendica-32.png"> {{$title}}</h1>
|
||||||
|
<h2>{{$pass}}</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
{{$info_01}}<br>
|
||||||
|
{{$info_02}}<br>
|
||||||
|
{{$info_03}}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
{{foreach $checks as $check}}
|
||||||
|
<tr><td>{{$check.title}} </td><td>
|
||||||
|
{{if ! $check.status}}
|
||||||
|
<img src="{{$baseurl}}/view/install/red.png" alt="Requirement not satisfied">
|
||||||
|
{{/if}}
|
||||||
|
{{/foreach}}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<form id="install-form" action="{{$baseurl}}/install" method="post">
|
||||||
|
|
||||||
|
<input type="hidden" name="config-php_path" value="{{$php_path}}" />
|
||||||
|
<input type="hidden" name="pass" value="3" />
|
||||||
|
|
||||||
|
{{include file="field_select.tpl" field=$ssl_policy}}
|
||||||
|
<br />
|
||||||
|
{{include file="field_input.tpl" field=$hostname}}
|
||||||
|
<br />
|
||||||
|
{{include file="field_input.tpl" field=$basepath}}
|
||||||
|
<br />
|
||||||
|
{{include file="field_input.tpl" field=$urlpath}}
|
||||||
|
|
||||||
|
<input id="install-submit" type="submit" name="submit" value="{{$submit}}" />
|
||||||
|
|
||||||
|
</form>
|
|
@ -19,7 +19,11 @@
|
||||||
<form id="install-form" action="{{$baseurl}}/install" method="post">
|
<form id="install-form" action="{{$baseurl}}/install" method="post">
|
||||||
|
|
||||||
<input type="hidden" name="config-php_path" value="{{$php_path}}" />
|
<input type="hidden" name="config-php_path" value="{{$php_path}}" />
|
||||||
<input type="hidden" name="pass" value="3" />
|
<input type="hidden" name="config-hostname" value="{{$hostname}}" />
|
||||||
|
<input type="hidden" name="system-ssl_policy" value="{{$ssl_policy}}" />
|
||||||
|
<input type="hidden" name="system-basepath" value="{{$basepath}}" />
|
||||||
|
<input type="hidden" name="system-urlpath" value="{{$urlpath}}" />
|
||||||
|
<input type="hidden" name="pass" value="4" />
|
||||||
|
|
||||||
{{include file="field_input.tpl" field=$dbhost}}
|
{{include file="field_input.tpl" field=$dbhost}}
|
||||||
{{include file="field_input.tpl" field=$dbuser}}
|
{{include file="field_input.tpl" field=$dbuser}}
|
||||||
|
|
|
@ -7,14 +7,18 @@
|
||||||
<form id="install-form" action="{{$baseurl}}/install" method="post">
|
<form id="install-form" action="{{$baseurl}}/install" method="post">
|
||||||
|
|
||||||
<input type="hidden" name="config-php_path" value="{{$php_path}}" />
|
<input type="hidden" name="config-php_path" value="{{$php_path}}" />
|
||||||
|
<input type="hidden" name="config-hostname" value="{{$hostname}}" />
|
||||||
|
<input type="hidden" name="system-ssl_policy" value="{{$ssl_policy}}" />
|
||||||
|
<input type="hidden" name="system-basepath" value="{{$basepath}}" />
|
||||||
|
<input type="hidden" name="system-urlpath" value="{{$urlpath}}" />
|
||||||
<input type="hidden" name="database-hostname" value="{{$dbhost}}" />
|
<input type="hidden" name="database-hostname" value="{{$dbhost}}" />
|
||||||
<input type="hidden" name="database-username" value="{{$dbuser}}" />
|
<input type="hidden" name="database-username" value="{{$dbuser}}" />
|
||||||
<input type="hidden" name="database-password" value="{{$dbpass}}" />
|
<input type="hidden" name="database-password" value="{{$dbpass}}" />
|
||||||
<input type="hidden" name="database-database" value="{{$dbdata}}" />
|
<input type="hidden" name="database-database" value="{{$dbdata}}" />
|
||||||
<input type="hidden" name="pass" value="4" />
|
<input type="hidden" name="pass" value="5" />
|
||||||
|
|
||||||
{{include file="field_input.tpl" field=$adminmail}}
|
{{include file="field_input.tpl" field=$adminmail}} <br />
|
||||||
{{$timezone nofilter}}
|
{{$timezone nofilter}} <br />
|
||||||
{{include file="field_select.tpl" field=$language}}
|
{{include file="field_select.tpl" field=$language}}
|
||||||
|
|
||||||
<input id="install-submit" type="submit" name="submit" value="{{$submit}}" />
|
<input id="install-submit" type="submit" name="submit" value="{{$submit}}" />
|
||||||
|
|
|
@ -24,11 +24,14 @@ return [
|
||||||
'php_path' => '{{$phpath}}',
|
'php_path' => '{{$phpath}}',
|
||||||
'admin_email' => '{{$adminmail}}',
|
'admin_email' => '{{$adminmail}}',
|
||||||
'sitename' => 'Friendica Social Network',
|
'sitename' => 'Friendica Social Network',
|
||||||
|
'hostname' => '{{$hostname}}',
|
||||||
'register_policy' => \Friendica\Module\Register::OPEN,
|
'register_policy' => \Friendica\Module\Register::OPEN,
|
||||||
'max_import_size' => 200000,
|
'max_import_size' => 200000,
|
||||||
],
|
],
|
||||||
'system' => [
|
'system' => [
|
||||||
'urlpath' => '{{$urlpath}}',
|
'urlpath' => '{{$urlpath}}',
|
||||||
|
'url' => '{{$baseurl}}',
|
||||||
|
'ssl_policy' => {{$sslpolicy}},
|
||||||
'basepath' => '{{$basepath}}',
|
'basepath' => '{{$basepath}}',
|
||||||
'default_timezone' => '{{$timezone}}',
|
'default_timezone' => '{{$timezone}}',
|
||||||
'language' => '{{$language}}',
|
'language' => '{{$language}}',
|
||||||
|
|
Loading…
Reference in a new issue