file_put_contents($pidfile, $pid);
// We lose the database connection upon forking
- /// @todo refactoring during https://github.com/friendica/friendica/issues/6720
- $basePath = \Friendica\Util\BasePath::create(dirname(__DIR__), $_SERVER);
- Factory\DBFactory::init($basePath, $a->getConfigCache(), $a->getProfiler(), $_SERVER);
+ Factory\DBFactory::init($a->getConfigCache(), $a->getProfiler(), $_SERVER);
}
Config::set('system', 'worker_daemon_mode', true);
*/
class BaseObject
{
+ /**
+ * @var App
+ */
private static $app = null;
/**
-v Show more debug information.
-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)
- -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)
- -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)
- -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)
- -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)
- -A|--admin <mail> The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL)
- -T|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
- -L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
+ -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)
+ -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)
+ -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)
+ -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|--basepath <base_path> The basepath of Friendica(env FRIENDICA_BASE_PATH)
+ -S|--sslpolicy <ssl_policy> The SSL policy of Friendica (env FRIENDICA_SSL_POLICY)
+ -n|--hostname <hostname> The hostname of Friendica (env FRIENDICA_PHP_HOSTNAME)
+ -t|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
+ -L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
Environment variables
MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used)
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_DATABASE The name of the mysql/mariadb database
- FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica')
- FRIENDICA_PHP_PATH The path of the PHP binary
+ FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica') - leave empty for auto detection
+ 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_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_LANG The langauge of Friendica
$installer = new Installer();
$configCache = $a->getConfigCache();
+ $installer->setUpCache($configCache, dirname(__DIR__, 3), $_SERVER);
$this->out(" Complete!\n\n");
// Copy config file
$this->out("Copying config file...\n");
if (!copy($a->getBasePath() . DIRECTORY_SEPARATOR . $config_file, $a->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
- throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '" . $a->getBasePath() . "'" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.config.php' manually.\n");
+ throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '" . $a->getBasePath() . "'" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.config.php' manually.\n");
}
}
$php_path = $this->getOption(['b', 'phppath'], !empty('FRIENDICA_PHP_PATH') ? getenv('FRIENDICA_PHP_PATH') : null);
if (!empty($php_path)) {
$configCache->set('config', 'php_path', $php_path);
+ } else {
+ $configCache->set('config', 'php_path', $installer->getPHPPath());
}
+
$configCache->set('config', 'admin_email',
$this->getOption(['A', 'admin'],
!empty(getenv('FRIENDICA_ADMIN_MAIL')) ? getenv('FRIENDICA_ADMIN_MAIL') : ''));
$this->getOption(['L', 'lang'],
!empty(getenv('FRIENDICA_LANG')) ? getenv('FRIENDICA_LANG') : Installer::DEFAULT_LANG));
+ $configCache->set('system', 'urlpath', $this->getOption(['u', 'urlpath'], !empty(getenv('FRIENDICA_URL_PATH')) ? getenv('FRIENDICA_URL_PATH') : ''));
+ $basepath = $this->getOption(['b', 'basepath'], !empty(getenv('FRIENDICA_BASE_PATH')) ? getenv('FRIENDICA_BASE_PATH') : null);
+ if (!empty($basepath)) {
+ $configCache->set('system', 'basepath', $basepath);
+ }
+ $php_path = $this->getOption(['B', 'phppath'], !empty(getenv('FRIENDICA_PHP_PATH')) ? getenv('FRIENDICA_PHP_PATH') : null);
+ if (!empty($php_path)) {
+ $configCache->set('config', 'php_path', $php_path);
+ }
+ $ssl_policy = $this->getOption(['S', 'sslpolicy'], !empty(getenv('FRIENDICA_SSL_POLICY')) ? getenv('FRIENDICA_SSL_POLICY') : null);
+ if (!empty($ssl_policy)) {
+ $configCache->set('system', 'ssl_policy', $ssl_policy);
+ }
+ $configCache->set('config', 'hostname', $this->getOption(['n', 'hostname'], !empty(getenv('FRIENDICA_HOSTNAME')) ? getenv('FRIENDICA_HOSTNAME') : ''));
+
+ $configCache->set('system', 'url', $installer->determineBaseUrl($configCache));
- if (empty($php_path)) {
- $configCache->set('config', 'php_path', $installer->getPHPPath());
+ if (empty($configCache->get('config', 'hostname'))) {
+ $this->out('The Friendica hostname has to be set during CLI installation.');
+ return 1;
}
- $installer->createConfig(
- $a,
- $configCache,
- $a->getBasePath()
- );
+ $installer->createConfig($configCache);
}
$this->out(" Complete!\n\n");
$installer->resetChecks();
- if (!$installer->checkDB($a->getBasePath(), $configCache, $a->getProfiler())) {
+ if (!$installer->checkDB($configCache, $a->getProfiler())) {
$errorMessage = $this->extractErrors($installer->getChecks());
throw new RuntimeException($errorMessage);
}
$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)) {
$checked = false;
use DOMDocument;
use Exception;
-use Friendica\App;
use Friendica\Core\Config\Cache\IConfigCache;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\Object\Image;
use Friendica\Util\Logger\VoidLogger;
+use Friendica\Util\BasePath;
use Friendica\Util\Network;
use Friendica\Util\Profiler;
use Friendica\Util\Strings;
* - Creates `config/local.config.php`
* - Installs Database Structure
*
- * @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(App $app, IConfigCache $configCache, $basepath)
+ public function createConfig(IConfigCache $configCache)
{
+ $basepath = $configCache->get('system', 'basepath');
+
$tpl = Renderer::getMarkupTemplate('local.config.tpl');
$txt = Renderer::replaceMacros($tpl, [
'$dbhost' => $configCache->get('database', 'hostname'),
'$dbpass' => $configCache->get('database', 'password'),
'$dbdata' => $configCache->get('database', 'database'),
- '$phpath' => $this->getPHPPath(),
+ '$phpath' => $configCache->get('config', 'php_path'),
'$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'),
'$language' => $configCache->get('system', 'language'),
- '$urlpath' => $app->getURLPath(),
]);
$result = file_put_contents($basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php', $txt);
$help .= EOL . EOL;
$tpl = Renderer::getMarkupTemplate('field_input.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 = "";
}
/**
* 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 Profiler $profiler The profiler of this app
*
* @return bool true if the check was successful, otherwise false
* @throws Exception
*/
- public function checkDB($basePath, IConfigCache $configCache, Profiler $profiler)
+ public function checkDB(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, 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, '');
return false;
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);
+ }
}
* @var LoggerInterface
*/
private static $logger;
- /**
- * @var string
- */
- private static $basePath;
private static $server_info = '';
private static $connection;
private static $driver;
private static $db_name = '';
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()) {
return true;
}
// We are storing these values for being able to perform a reconnect
- self::$basePath = $basePath;
self::$configCache = $configCache;
self::$profiler = $profiler;
self::$logger = $logger;
public static function reconnect() {
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;
}
* This process must only be started once, since the value is cached.
*/
private static function buildRelationData() {
- $definition = DBStructure::definition(self::$basePath);
+ $definition = DBStructure::definition(self::$configCache->get('system', 'basepath'));
foreach ($definition AS $table => $structure) {
foreach ($structure['fields'] AS $field => $field_struct) {
/**
* Initialize the DBA connection
*
- * @param string $basePath The basepath of the application
* @param Cache\IConfigCache $configCache The configuration cache
* @param Profiler $profiler The profiler
* @param array $server The $_SERVER variables
*
* @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()) {
return;
$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
- Database\DBStructure::definition($basePath, false);
+ Database\DBStructure::definition($configCache->get('system', 'basepath'), false);
}
unset($db_host, $db_user, $db_pass, $db_data, $charset);
namespace Friendica\Factory;
use Friendica\App;
-use Friendica\Database\DBA;
use Friendica\Factory;
use Friendica\Util\BasePath;
use Friendica\Util\BaseURL;
$configLoader = new Config\ConfigFileLoader($basePath, $mode);
$configCache = Factory\ConfigFactory::createCache($configLoader);
$profiler = Factory\ProfilerFactory::create($configCache);
- Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
+ Factory\DBFactory::init($configCache, $profiler, $_SERVER);
$config = Factory\ConfigFactory::createConfig($configCache);
// needed to call PConfig::init()
Factory\ConfigFactory::createPConfig($configCache);
$logger = Factory\LoggerFactory::create($channel, $config, $profiler);
- DBA::setLogger($logger);
Factory\LoggerFactory::createDev($channel, $config, $profiler);
$baseURL = new BaseURL($config, $_SERVER);
use Friendica\Core\Config\Cache\IConfigCache;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
+use Friendica\Util\BasePath;
+use Friendica\Util\BaseURL;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
*/
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 - Adapat 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
{
$a = self::getApp();
- if (!$a->getMode()->isInstall()) {
- Core\System::httpExit(403);
- }
-
// route: install/testrwrite
// $baseurl/install/testrwrite to test if rewrite in .htaccess is working
if ($a->getArgumentValue(1, '') == 'testrewrite') {
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
// 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';
- self::$installer = new Core\Installer();
self::$currentWizardStep = defaults($_POST, 'pass', self::SYSTEM_CHECK);
}
switch (self::$currentWizardStep) {
case self::SYSTEM_CHECK:
+ case self::BASE_CONFIG:
+ self::checkSetting($configCache, $_POST, 'config', 'php_path');
+ break;
+
case self::DATABASE_CONFIG:
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;
case self::SITE_SETTINGS:
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', '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 (!self::$installer->checkDB($a->getBasePath(), $configCache, $a->getProfiler())) {
+ if (!self::$installer->checkDB($configCache, $a->getProfiler())) {
self::$currentWizardStep = self::DATABASE_CONFIG;
}
case self::FINISHED:
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', 'username', '');
self::checkSetting($configCache, $_POST, 'database', 'password', '');
self::checkSetting($configCache, $_POST, 'config', 'admin_email', '');
// 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;
return;
}
- if (!self::$installer->createConfig($a, $configCache, $a->getBasePath())) {
+ if (!self::$installer->createConfig($configCache)) {
return;
}
- self::$installer->installDatabase($a->getBasePath());
+ self::$installer->installDatabase($configCache->get('system', 'basepath'));
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:
$tpl = Renderer::getMarkupTemplate('install_db.tpl');
$output .= Renderer::replaceMacros($tpl, [
'$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.'),
'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',
L10n::t('Database Server Name'),
$configCache->get('database', 'hostname'),
'$title' => $install_title,
'$checks' => self::$installer->getChecks(),
'$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'),
'$dbuser' => $configCache->get('database', 'username'),
'$dbpass' => $configCache->get('database', 'password'),
'$dbdata' => $configCache->get('database', 'database'),
- '$phpath' => $configCache->get('config', 'php_path'),
'$adminmail' => ['config-admin_email',
L10n::t('Site administrator email address'),
$configCache->get('config', 'admin_email'),
L10n::t('Set the default language for your Friendica installation interface and to send emails.'),
$lang_choices],
'$baseurl' => $a->getBaseURL(),
+ '$php_path' => $configCache->get('config', 'php_path'),
'$submit' => L10n::t('Submit')
]);
break;
$profiler = \Mockery::mock(Profiler::class);
DBA::connect(
- $basePath,
$config,
$profiler,
new VoidLogger(),
* Mock the App
*
* @param vfsStreamDirectory $root The root directory
- * @param Config\Cache\ConfigCache $configCache
* @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->mode = \Mockery::mock(App\Mode::class);
// Disable the adapter
$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
Config::init($config);
$this->app
->shouldReceive('getConfigCache')
- ->andReturn((isset($configCache) ? $configCache : $this->configMock));
+ ->andReturn($this->configMock);
$this->app
->shouldReceive('getTemplateEngine')
->andReturn(new FriendicaSmartyEngine());
$this->app
->shouldReceive('getBaseUrl')
->andReturnUsing(function () {
- return $this->app->getConfigCache()->get('system', 'url');
+ return $this->configMock->get('system', 'url');
});
BaseObject::setApp($this->app);
$configLoader = new ConfigFileLoader($basePath, $mode);
$configCache = Factory\ConfigFactory::createCache($configLoader);
$profiler = Factory\ProfilerFactory::create($configCache);
- Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
+ Factory\DBFactory::init($configCache, $profiler, $_SERVER);
$config = Factory\ConfigFactory::createConfig($configCache);
Factory\ConfigFactory::createPConfig($configCache);
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
$this->configCache->set('config', 'php_path', trim(shell_exec('which php')));
$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) {
if ($key !== 'basepath') {
],
'config' => [
'php_path' => '',
+ 'hostname' => 'friendica.local',
'admin_email' => '',
],
'system' => [
+ 'basepath' => '',
'urlpath' => '',
+ 'url' => 'http://friendica.local',
+ 'ssl_policy' => '',
'default_timezone' => '',
'language' => '',
],
],
'config' => [
'php_path' => '',
+ 'hostname' => 'friendica.local',
'admin_email' => 'admin@philipp.info',
],
'system' => [
'urlpath' => 'test/it',
+ 'url' => 'http://friendica.local/test/it',
+ 'basepath' => '',
+ 'ssl_policy' => '2',
'default_timezone' => 'en',
'language' => 'Europe/Berlin',
],
],
'config' => [
'php_path' => '',
+ 'hostname' => 'friendica.local',
'admin_email' => 'admin@philipp.info',
],
'system' => [
'urlpath' => 'test/it',
+ 'url' => 'https://friendica.local/test/it',
+ 'basepath' => '',
+ 'ssl_policy' => '1',
'default_timezone' => 'en',
'language' => 'Europe/Berlin',
],
Could not connect to database.:
+FIN;
+
+ $this->assertEquals($finished, $txt);
+ }
+
+ private function assertStuckHostnam($txt)
+ {
+ $finished = <<<FIN
+Initializing setup...
+
+ Complete!
+
+
+Checking environment...
+
+ NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
+
+ Complete!
+
+
+Creating config file...
+
+The Friendica hostname has to be set during CLI installation.
+
FIN;
$this->assertEquals($finished, $txt);
* @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 $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'])) {
$assertion['database']['hostname'] .= (!empty($assertion['database']['port']) ? ':' . $assertion['database']['port'] : '');
$this->assertConfigEntry('config', 'admin_email', $assertion);
$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', 'language', $assertion, ($default) ? Installer::DEFAULT_LANG : null);
+ $this->assertConfigEntry('system', 'url', $assertion);
+ $this->assertConfigEntry('system', 'urlpath', $assertion);
+ $this->assertConfigEntry('system', 'ssl_policy', $assertion, ($default) ? SSL_POLICY_NONE : null);
+ $this->assertConfigEntry('system', 'basepath', ($realBasepath) ? $this->root->url() : $assertion);
}
/**
* Test the automatic installation without any parameter/setting
+ * Should stuck because of missing hostname
*/
public function testEmpty()
{
- $this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once();
+ $console = new AutomaticInstallation($this->consoleArgv);
+
+ $txt = $this->dumpExecute($console);
+
+ $this->assertStuckHostnam($txt);
+ }
+ /**
+ * Test the automatic installation without any parameter/setting
+ * except hostname
+ */
+ public function testEmptyWithHostname()
+ {
$this->mockConnect(true, 1);
$this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1);
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
$console = new AutomaticInstallation($this->consoleArgv);
+ $console->setOption('n', 'friendica.local');
$txt = $this->dumpExecute($console);
$this->assertFinished($txt, true, false);
$this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
- $this->assertConfig();
+ $this->assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local']], false, true, true, true);
}
/**
'config' => [
'admin_email' => '{$conf('config', 'admin_email')}',
+ 'hostname' => '{$conf('config', 'hostname')}',
'sitename' => 'Friendica Social Network',
'register_policy' => \Friendica\Module\Register::OPEN,
'register_text' => '',
],
'system' => [
+ 'basepath' => '{$conf('system', 'basepath')}',
'urlpath' => '{$conf('system', 'urlpath')}',
+ 'url' => '{$conf('system', 'url')}',
+ 'ssl_policy' => '{$conf('system', 'ssl_policy')}',
'default_timezone' => '{$conf('system', 'default_timezone')}',
'language' => '{$conf('system', 'language')}',
],
*/
public function testWithEnvironmentAndSave(array $data)
{
- $this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once();
-
$this->mockConnect(true, 1);
$this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1);
$this->assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username']));
$this->assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password']));
+ $this->assertTrue(putenv('FRIENDICA_HOSTNAME=' . $data['config']['hostname']));
+ $this->assertTrue(putenv('FRIENDICA_BASE_PATH=' . $data['system']['basepath']));
$this->assertTrue(putenv('FRIENDICA_URL_PATH=' . $data['system']['urlpath']));
$this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path']));
$this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email']));
$this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone']));
$this->assertTrue(putenv('FRIENDICA_LANG=' . $data['system']['language']));
+ $this->assertTrue(putenv('FRIENDICA_SSL_POLICY=' . $data['system']['ssl_policy']));
$console = new AutomaticInstallation($this->consoleArgv);
$console->setOption('savedb', true);
$txt = $this->dumpExecute($console);
$this->assertFinished($txt, true);
- $this->assertConfig($data, true, true, false);
+ $this->assertConfig($data, true, true, false, true);
}
/**
*/
public function testWithEnvironmentWithoutSave(array $data)
{
- $this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once();
-
$this->mockConnect(true, 1);
$this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1);
$this->assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username']));
$this->assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password']));
- $this->assertTrue(putenv('FRIENDICA_URL_PATH=' . $data['system']['urlpath']));
- $this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path']));
+ $this->assertTrue(putenv('FRIENDICA_HOSTNAME=' . $data['config']['hostname']));
+ $this->assertTrue(putenv('FRIENDICA_BASE_PATH=' . $data['system']['basepath']));
+ $this->assertTrue(putenv('FRIENDICA_URL_PATH=' . $data['system']['urlpath']));
+ $this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path']));
$this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email']));
- $this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone']));
- $this->assertTrue(putenv('FRIENDICA_LANG=' . $data['system']['language']));
+ $this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone']));
+ $this->assertTrue(putenv('FRIENDICA_LANG=' . $data['system']['language']));
+ $this->assertTrue(putenv('FRIENDICA_SSL_POLICY=' . $data['system']['ssl_policy']));
$console = new AutomaticInstallation($this->consoleArgv);
$txt = $this->dumpExecute($console);
$this->assertFinished($txt, true);
- $this->assertConfig($data, false, true);
+ $this->assertConfig($data, false, true, false, true);
}
/**
*/
public function testWithArguments(array $data)
{
- $this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once();
-
$this->mockConnect(true, 1);
$this->mockConnected(true, 1);
$this->mockExistsTable('user', false, 1);
$console->setOption($var, $data[$cat][$key]);
}
};
- $option('dbhost' , 'database', 'hostname');
- $option('dbport' , 'database', 'port');
- $option('dbuser' , 'database', 'username');
- $option('dbpass' , 'database', 'password');
- $option('dbdata' , 'database', 'database');
- $option('urlpath' , 'system' , 'urlpath');
- $option('phppath' , 'config' , 'php_path');
- $option('admin' , 'config' , 'admin_email');
- $option('tz' , 'system' , 'default_timezone');
- $option('lang' , 'system' , 'language');
+ $option('dbhost' , 'database', 'hostname');
+ $option('dbport' , 'database', 'port');
+ $option('dbuser' , 'database', 'username');
+ $option('dbpass' , 'database', 'password');
+ $option('dbdata' , 'database', 'database');
+ $option('urlpath' , 'system' , 'urlpath');
+ $option('phppath' , 'config' , 'php_path');
+ $option('admin' , 'config' , 'admin_email');
+ $option('tz' , 'system' , 'default_timezone');
+ $option('lang' , 'system' , 'language');
+ $option('hostname' , 'config' , 'hostname');
+ $option('basepath' , 'system' , 'basepath');
+ $option('sslpolicy' , 'system' , 'ssl_policy');
$txt = $this->dumpExecute($console);
$this->assertFinished($txt, true);
- $this->assertConfig($data, true, true, true);
+ $this->assertConfig($data, true, true, true, true);
}
/**
*/
public function testNoDatabaseConnection()
{
- $this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once();
$this->mockConnect(false, 1);
$this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
$this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
$console = new AutomaticInstallation($this->consoleArgv);
+ $console->setOption('n', 'friendica.local');
$txt = $this->dumpExecute($console);
$this->assertStuckDB($txt);
$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']], false, true, false, true);
}
public function testGetHelp()
-v Show more debug information.
-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)
- -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)
- -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)
- -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)
- -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)
- -A|--admin <mail> The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL)
- -T|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
- -L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
+ -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)
+ -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)
+ -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)
+ -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|--basepath <base_path> The basepath of Friendica(env FRIENDICA_BASE_PATH)
+ -S|--sslpolicy <ssl_policy> The SSL policy of Friendica (env FRIENDICA_SSL_POLICY)
+ -n|--hostname <hostname> The hostname of Friendica (env FRIENDICA_PHP_HOSTNAME)
+ -t|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
+ -L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
Environment variables
MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used)
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_DATABASE The name of the mysql/mariadb database
- FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica')
- FRIENDICA_PHP_PATH The path of the PHP binary
+ FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica') - leave empty for auto detection
+ 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_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_LANG The langauge of Friendica
// this is in the same namespace as Install for mocking 'function_exists'
namespace Friendica\Core;
+use Friendica\Core\Config\Cache\IConfigCache;
use Friendica\Network\CurlResult;
use Friendica\Object\Image;
use Friendica\Test\MockedTest;
false,
$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/');
+ }
}
/**
$configLoader = new ConfigFileLoader($basePath, $mode);
$configCache = Factory\ConfigFactory::createCache($configLoader);
$profiler = Factory\ProfilerFactory::create($configCache);
- Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
+ Factory\DBFactory::init($configCache, $profiler, $_SERVER);
$config = Factory\ConfigFactory::createConfig($configCache);
Factory\ConfigFactory::createPConfig($configCache);
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
$configLoader = new ConfigFileLoader($basePath, $mode);
$configCache = Factory\ConfigFactory::createCache($configLoader);
$profiler = Factory\ProfilerFactory::create($configCache);
- Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
+ Factory\DBFactory::init($configCache, $profiler, $_SERVER);
$config = Factory\ConfigFactory::createConfig($configCache);
Factory\ConfigFactory::createPConfig($configCache);
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
--- /dev/null
+<?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));
+ }
+}
--- /dev/null
+<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>
<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" />
+ <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=$dbuser}}
<form id="install-form" action="{{$baseurl}}/install" method="post">
<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-username" value="{{$dbuser}}" />
<input type="hidden" name="database-password" value="{{$dbpass}}" />
<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}}
-{{$timezone nofilter}}
+{{include file="field_input.tpl" field=$adminmail}} <br />
+{{$timezone nofilter}} <br />
{{include file="field_select.tpl" field=$language}}
<input id="install-submit" type="submit" name="submit" value="{{$submit}}" />
'php_path' => '{{$phpath}}',
'admin_email' => '{{$adminmail}}',
'sitename' => 'Friendica Social Network',
+ 'hostname' => '{{$hostname}}',
'register_policy' => \Friendica\Module\Register::OPEN,
'max_import_size' => 200000,
],
'system' => [
'urlpath' => '{{$urlpath}}',
+ 'url' => '{{$baseurl}}',
+ 'ssl_policy' => {{$sslpolicy}},
'basepath' => '{{$basepath}}',
'default_timezone' => '{{$timezone}}',
'language' => '{{$language}}',