46 private $has_completed = [
53 private $is_action =
false;
55 private $autoLogin =
true;
68 public function run() {
71 $this->is_action = $app->_services->request->getMethod() ===
'POST';
94 $params = $app->_services->request->request->all();
96 $method =
"run" . ucwords(
$step);
114 $config->elgg_config_locks =
false;
115 $config->installer_running =
true;
116 $config->dbencoding =
'utf8mb4';
118 $config->system_cache_enabled =
false;
119 $config->simplecache_enabled =
false;
120 $config->debug = \Psr\Log\LogLevel::WARNING;
121 $config->cacheroot = Paths::sanitize(sys_get_temp_dir()) .
'elgginstaller/caches/';
122 $config->assetroot = Paths::sanitize(sys_get_temp_dir()) .
'elgginstaller/assets/';
126 $app = Application::factory([
127 'service_provider' => $services,
128 'handle_exceptions' =>
false,
129 'handle_shutdown' =>
false,
137 Application::setInstance($app);
141 $app->_services->boot->getCache()->disable();
142 $app->_services->plugins->getCache()->disable();
143 $app->_services->sessionCache->disable();
144 $app->_services->dic_cache->getCache()->disable();
145 $app->_services->dataCache->disable();
146 $app->_services->autoloadManager->getCache()->disable();
149 $app->_services->views->setViewtype(
'installation');
150 $app->_services->views->registerViewtypeFallback(
'installation');
151 $app->_services->views->registerPluginViews(
Paths::elgg());
152 $app->_services->translator->registerTranslations(
Paths::elgg() .
"install/languages/",
true);
168 $this->autoLogin = (bool) $flag;
190 'dbhost' =>
'localhost',
191 'dbprefix' =>
'elgg_',
195 $params = array_merge(
$defaults, $params);
209 foreach ($required_params as
$key) {
210 if (empty($params[$key])) {
211 $msg =
elgg_echo(
'install:error:requiredfield', [$key]);
217 $params[
'password1'] = $params[
'password2'] = $params[
'password'];
219 if ($create_htaccess) {
221 if (!$rewrite_tester->createHtaccess($params[
'wwwroot'])) {
231 $params[
'dataroot'] = Paths::sanitize($params[
'dataroot']);
235 if (!$this->has_completed[
'config']) {
244 $config = $app->_services->config;
247 'dbhost' =>
'dbhost',
248 'dbuser' =>
'dbuser',
249 'dbpassword' =>
'dbpass',
250 'dbname' =>
'dbname',
251 'dataroot' =>
'dataroot',
252 'dbprefix' =>
'dbprefix',
254 foreach ($config_keys as $params_key => $config_key) {
255 if ($params[$params_key] !==
$config->$config_key) {
264 if (!$this->has_completed[
'database']) {
306 return new \Elgg\Http\OkResponse(
$output);
321 return $this->
render(
'welcome');
353 'severity' =>
'notice',
354 'message' =>
elgg_echo(
'install:check:database')
367 'num_failures' => $numFailures,
368 'num_warnings' => $numWarnings,
395 'type' =>
'password',
406 'value' =>
'localhost',
421 'value' => $app->_services->config->wwwroot,
425 'type' =>
'dropdown',
427 'options' => \DateTimeZone::listIdentifiers(),
434 $this->is_action =
true;
437 if ($this->is_action) {
438 $getResponse =
function () use ($app, $submissionVars, $formVars) {
460 $app->_services->systemMessages->addSuccessMessage(
elgg_echo(
'install:success:database'));
465 $response = $getResponse();
473 $params = [
'variables' => $formVars,];
499 'value' =>
'My New Community',
514 if ($this->is_action) {
515 $getResponse =
function () use ($app, $submissionVars, $formVars) {
525 $app->_services->systemMessages->addSuccessMessage(
elgg_echo(
'install:success:settings'));
530 $response = $getResponse();
538 return $this->
render(
'settings', [
'variables' => $formVars]);
571 'type' =>
'password',
574 'pattern' =>
'.{6,}',
577 'type' =>
'password',
583 if ($this->is_action) {
584 $getResponse =
function () use ($app, $submissionVars, $formVars) {
593 $app->_services->systemMessages->addSuccessMessage(
elgg_echo(
'install:success:admin'));
598 $response = $getResponse();
607 $lang = $app->_services->translator->getCurrentLanguage();
608 $translations = $app->_services->translator->getLoadedTranslations();
609 $app->_services->translator->addTranslation(
$lang, [
610 'install:admin:help:password1' => sprintf(
612 $app->_services->config->min_password_length
618 return $this->
render(
'admin', [
'variables' => $formVars]);
631 '#text' =>
elgg_echo(
'install:complete:admin_notice:link_text'),
639 _elgg_rmdir(Paths::sanitize(sys_get_temp_dir()) .
'elgginstaller/');
666 $this->is_action =
false;
668 return new \Elgg\Http\RedirectResponse($this->
getNextStepUrl($currentStep));
679 $index = 1 + array_search($currentStep, $this->
steps);
699 return $app->_services->config->wwwroot .
"install.php?step=$nextStep";
711 $path = Config::resolvePath();
718 $this->has_completed[
'config'] =
true;
722 $app->_services->config->dbuser,
723 $app->_services->config->dbpass,
724 $app->_services->config->dbname,
725 $app->_services->config->dbhost
728 if (!$dbSettingsPass) {
732 $db = $app->_services->db;
736 $result = $db->getData(
"SHOW TABLES");
741 $table = (array) $table;
742 if (in_array(
"{$db->prefix}config", $table)) {
743 $this->has_completed[
'database'] =
true;
746 if ($this->has_completed[
'database'] ==
false) {
751 $qb = \Elgg\Database\Select::fromTable(
'config');
752 $qb->select(
'COUNT(*) AS total');
754 $result = $db->getDataRow($qb);
756 $this->has_completed[
'settings'] =
true;
762 $qb = \Elgg\Database\Select::fromTable(
'entities',
'e');
763 $qb->select(
'COUNT(*) AS total')
766 $result = $db->getDataRow($qb);
768 $this->has_completed[
'admin'] =
true;
788 if (
$step !=
'complete') {
789 if (!in_array(
false, $this->has_completed)) {
791 return new \Elgg\Http\RedirectResponse(
'/');
806 if (
$step !==
'welcome') {
810 if ($this->has_completed[
'database'] ==
false) {
814 if ($this->has_completed[
'settings'] ==
false) {
815 return new \Elgg\Http\RedirectResponse(
"install.php?step=settings");
818 if ($this->has_completed[
'admin'] ==
false) {
819 return new \Elgg\Http\RedirectResponse(
"install.php?step=admin");
823 return new \Elgg\Http\RedirectResponse(
"install.php?step=complete");
843 $index_db = array_search(
'database', $this->
getSteps());
844 $index_settings = array_search(
'settings', $this->
getSteps());
845 $index_admin = array_search(
'admin', $this->
getSteps());
846 $index_complete = array_search(
'complete', $this->
getSteps());
851 $use_elgg_session = ($index_step == $index_admin && $this->is_action) || ($index_step == $index_complete);
852 if (!$use_elgg_session) {
856 if ($index_step > $index_db) {
860 $app->_services->config->site =
new ElggSite();
876 $config = Config::fromFile(Config::resolvePath());
877 $app->_services->setValue(
'config',
$config);
880 $app->_services->db->resetConnections(DbConfig::fromElggConfig(
$config));
882 $msg =
elgg_echo(
'InstallationException:CannotLoadSettings');
917 if (!is_writable(Paths::projectConfig())) {
918 $msg =
elgg_echo(
'install:check:installdir', [Paths::PATH_TO_CONFIG]);
921 'severity' =>
'error',
940 if (!is_file(Config::resolvePath())) {
944 if (!is_readable(Config::resolvePath())) {
947 'severity' =>
'error',
948 'message' =>
elgg_echo(
'install:check:readsettings'),
966 $min_php_version =
'7.0.0';
967 if (version_compare(PHP_VERSION, $min_php_version,
'<')) {
969 'severity' =>
'error',
970 'message' =>
elgg_echo(
'install:check:php:version', [$min_php_version, PHP_VERSION])
978 if (count($phpReport) == 0) {
980 'severity' =>
'success',
981 'message' =>
elgg_echo(
'install:check:php:success')
997 $requiredExtensions = [
1003 foreach ($requiredExtensions as
$extension) {
1006 'severity' =>
'error',
1007 'message' =>
elgg_echo(
'install:check:php:extension', [$extension])
1012 $recommendedExtensions = [
1015 foreach ($recommendedExtensions as $extension) {
1018 'severity' =>
'warning',
1019 'message' =>
elgg_echo(
'install:check:php:extension:recommend', [$extension])
1033 if (ini_get(
'open_basedir')) {
1035 'severity' =>
'warning',
1036 'message' =>
elgg_echo(
"install:check:php:open_basedir")
1040 if (ini_get(
'safe_mode')) {
1042 'severity' =>
'warning',
1043 'message' =>
elgg_echo(
"install:check:php:safe_mode")
1047 if (ini_get(
'arg_separator.output') !==
'&') {
1048 $separator = htmlspecialchars(ini_get(
'arg_separator.output'));
1051 'severity' =>
'error',
1056 if (ini_get(
'register_globals')) {
1058 'severity' =>
'error',
1059 'message' =>
elgg_echo(
"install:check:php:register_globals")
1063 if (ini_get(
'session.auto_start')) {
1065 'severity' =>
'error',
1066 'message' =>
elgg_echo(
"install:check:php:session.auto_start")
1083 $url = $app->_services->config->wwwroot;
1084 $url .= Request::REWRITE_TEST_TOKEN .
'?' . http_build_query([
1085 Request::REWRITE_TEST_TOKEN =>
'1',
1100 foreach (
$report as $category => $checks) {
1101 foreach ($checks as $check) {
1102 if ($check[
'severity'] === $condition) {
1130 if (
$info[
'required'] ==
true && !$submissionVars[
$field]) {
1132 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:requiredfield', [
$name]));
1139 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:wwwroot', [$submissionVars[
'wwwroot']]));
1145 if (stripos(PHP_OS,
'win') === 0) {
1146 if (strpos($submissionVars[
'dataroot'],
':') !== 1) {
1147 $msg =
elgg_echo(
'install:error:relative_path', [$submissionVars[
'dataroot']]);
1148 $app->_services->systemMessages->addErrorMessage($msg);
1153 if (strpos($submissionVars[
'dataroot'],
'/') !== 0) {
1154 $msg =
elgg_echo(
'install:error:relative_path', [$submissionVars[
'dataroot']]);
1155 $app->_services->systemMessages->addErrorMessage($msg);
1162 if (!is_dir($submissionVars[
'dataroot'])) {
1163 $msg =
elgg_echo(
'install:error:datadirectoryexists', [$submissionVars[
'dataroot']]);
1164 $app->_services->systemMessages->addErrorMessage($msg);
1170 if (!is_writable($submissionVars[
'dataroot'])) {
1171 $msg =
elgg_echo(
'install:error:writedatadirectory', [$submissionVars[
'dataroot']]);
1172 $app->_services->systemMessages->addErrorMessage($msg);
1177 if (!$app->_services->config->data_dir_override) {
1179 if (stripos($submissionVars[
'dataroot'], $app->_services->config->path) === 0) {
1180 $msg =
elgg_echo(
'install:error:locationdatadirectory', [$submissionVars[
'dataroot']]);
1181 $app->_services->systemMessages->addErrorMessage($msg);
1192 if (!preg_match(
"/^[a-zA-Z_][\w]*$/", $submissionVars[
'dbprefix'])) {
1193 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:database_prefix'));
1199 $submissionVars[
'dbuser'],
1200 $submissionVars[
'dbpassword'],
1201 $submissionVars[
'dbname'],
1202 $submissionVars[
'dbhost']
1223 'dbname' => $dbname,
1224 'dbencoding' =>
'utf8mb4',
1229 $db->getDataRow(
"SELECT 1");
1231 if (0 === strpos($e->getMessage(),
"Elgg couldn't connect")) {
1232 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:databasesettings'));
1234 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:nodatabase', [$dbname]));
1241 $version = $db->getServerVersion(DbConfig::READ_WRITE);
1242 if (version_compare(
$version,
'5.5.3',
'<')) {
1243 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:oldmysql2', [
$version]));
1262 $template = Application::elggDir()->getContents(
"elgg-config/settings.example.php");
1264 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:readsettingsphp'));
1269 foreach (
$params as $k => $v) {
1273 $v = Paths::sanitize($v);
1277 $template = str_replace(
"{{" . $k .
"}}", $v, $template);
1280 $result = file_put_contents(Config::resolvePath(), $template);
1282 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:writesettingphp'));
1297 $this->
getApp()->_services->setValue(
'dbConfig', $dbConfig);
1298 $this->
getApp()->_services->db->resetConnections($dbConfig);
1312 $app->_services->db->setupConnections();
1314 $app->_services->systemMessages->addErrorMessage($e->getMessage());
1329 return $this->
getApp()->migrate();
1349 if ($formVars[
'dataroot'][
'type'] !=
'combo') {
1354 if ($submissionVars[
'dataroot'] !=
'dataroot-checkbox') {
1359 if (file_exists($dir) || mkdir($dir, 0755)) {
1360 $submissionVars[
'dataroot'] = $dir;
1361 if (!file_exists(
"$dir/.htaccess")) {
1362 $htaccess =
"Order Deny,Allow\nDeny from All\n";
1363 if (!file_put_contents(
"$dir/.htaccess", $htaccess)) {
1386 $submissionVars[
$field] = trim($submissionVars[
$field]);
1387 if (
$info[
'required'] ==
true && $submissionVars[$field] ===
'') {
1389 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:requiredfield', [
$name]));
1396 if ($submissionVars[
'siteemail'] && !
is_email_address($submissionVars[
'siteemail'])) {
1397 $msg =
elgg_echo(
'install:error:emailaddress', [$submissionVars[
'siteemail']]);
1398 $app->_services->systemMessages->addErrorMessage($msg);
1421 $site->name = strip_tags($submissionVars[
'sitename']);
1423 $site->email = $submissionVars[
'siteemail'];
1427 if (
$site->guid !== 1) {
1428 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:createsite'));
1433 $app->_services->config->site =
$site;
1436 'installed' => time(),
1438 'simplecache_enabled' => 1,
1439 'system_cache_enabled' => 1,
1440 'simplecache_minify_js' =>
true,
1441 'simplecache_minify_css' =>
true,
1442 'simplecache_lastupdate' => time(),
1443 'processed_upgrades' => [],
1445 'default_access' => $submissionVars[
'siteaccess'],
1446 'allow_registration' =>
false,
1447 'walled_garden' =>
false,
1448 'allow_user_default_access' =>
'',
1449 'default_limit' => 10,
1450 'security_protect_upgrade' =>
true,
1451 'security_notify_admins' =>
true,
1452 'security_notify_user_password' =>
true,
1453 'security_email_require_password' =>
true,
1462 $app->_services->reset(
'plugins');
1466 $plugins = $app->_services->plugins->find(
'any');
1469 $manifest = $plugin->getManifest();
1474 if (!$manifest->getActivateOnInstall()) {
1478 $plugin->activate();
1482 $app->_services->events->unregisterHandler(
'create',
'object',
'_elgg_create_notice_of_pending_upgrade');
1483 $upgrades = $app->_services->upgradeLocator->locate();
1485 $upgrade->setCompleted();
1508 if (
$info[
'required'] ==
true && !$submissionVars[
$field]) {
1510 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:requiredfield', [
$name]));
1516 if ($submissionVars[
'password1'] !== $submissionVars[
'password2']) {
1517 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:admin:password:mismatch'));
1522 if (trim($submissionVars[
'password1']) ==
"") {
1523 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:admin:password:empty'));
1528 $minLength = $app->_services->configTable->get(
'min_password_length');
1529 if (strlen($submissionVars[
'password1']) < $minLength) {
1530 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:admin:password:tooshort'));
1536 if ($submissionVars[
'email'] && !
is_email_address($submissionVars[
'email'])) {
1537 $msg =
elgg_echo(
'install:error:emailaddress', [$submissionVars[
'email']]);
1538 $app->_services->systemMessages->addErrorMessage($msg);
1560 $submissionVars[
'username'],
1561 $submissionVars[
'password1'],
1562 $submissionVars[
'displayname'],
1563 $submissionVars[
'email']
1566 $app->_services->systemMessages->addErrorMessage($e->getMessage());
1571 if (
$guid ===
false) {
1572 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:admin:cannot_create'));
1580 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:loadadmin'));
1587 $ia = $app->_services->session->setIgnoreAccess(
true);
1588 if (!
$user->makeAdmin()) {
1589 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:adminaccess'));
1591 $app->_services->configTable->set(
'admin_registered', 1);
1593 $app->_services->session->setIgnoreAccess($ia);
1596 $user->validated =
true;
1597 $user->validated_method =
'admin_user';
1607 $app->_services->systemMessages->addErrorMessage(
elgg_echo(
'install:error:adminlogin'));
1624 $session->setName(
'Elgg_install');
1625 $app->_services->setValue(
'session', $session);
1638 $app->_services->setValue(
'session', $session);
foreach(array_keys($combine_languages) as $language) $translations
if(!$user||!$user->canDelete()) $name
createDataDirectory(&$submissionVars, $formVars)
Site settings support methods.
createSessionFromDatabase()
Setup session.
Bundled plugins(the contents of the"/mod"directory) are available only under the GPLv2 license.The remainder of the project is available under either MIT or GPLv2.Both licenses can be found below.More info and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two steps
$params
Saves global plugin settings.
countNumConditions($report, $condition)
Count the number of failures in the requirements report.
runAdmin($submissionVars)
Admin account controller.
_elgg_sane_validate_url($url)
Use a "fixed" filter_var() with FILTER_VALIDATE_URL that handles multi-byte chars.
checkPhpDirectives(&$phpReport)
Check PHP parameters.
runWelcome($vars)
Step controllers.
elgg_add_admin_notice($id, $message)
Write a persistent message to the admin view.
createSessionFromFile()
Setup session.
installDatabase()
Create the database tables.
run()
Dispatches a request to one of the step controllers.
checkInstallCompletion($step)
Security check to ensure the installer cannot be run after installation has finished.
getNextStep($currentStep)
Get the next step as a string.
$guid
Removes an admin notice.
static fromFiles(Config $config)
Create a session stored in files.
getSteps()
Step management.
getApp()
Build the application needed by the installer.
catch(LoginException $e) if($request->isXhr()) $output
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
checkPHP(&$report)
Check version of PHP, extensions, and variables.
if(!$item instanceof ElggEntity) $link
runDatabase($submissionVars)
Database set up controller.
elgg_view_page($title, $body, $page_shell= 'default', $vars=[])
Assembles and outputs a full page.
validateSettingsVars($submissionVars, $formVars)
Validate the site settings form variables.
elgg_save_config($name, $value)
Save a configuration setting.
resumeInstall($step)
Check if this is a case of a install being resumed and figure out where to continue from...
$config
Advanced site settings, debugging section.
$upgrades
Lists pending upgrades.
continueToNextStep($currentStep)
Forwards the browser to the next step.
getNextStepUrl($currentStep)
Get the URL of the next step.
if(!$user||!$user->canEdit()) $password
finishBootstrapping($step)
Bootstrapping.
render($step, $vars=[])
Renders the data passed by a controller.
runComplete()
Controller for last step.
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
makeFormSticky($formVars, $submissionVars)
Action handling methods.
checkPhpExtensions(&$phpReport)
Check the server's PHP extensions.
if(!empty($screenshots)) $info
register_user($username, $password, $name, $email, $allow_multiple_emails=false, $subtype=null)
Registers a user, returning false if the username already exists.
_elgg_rmdir($dir, $empty=false)
Recursively deletes a directory, including all hidden files.
runSettings($submissionVars)
Site settings controller.
elgg_get_site_entity()
Get the current site entity.
checkRewriteRules(&$report)
Confirm that the rewrite rules are firing.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
runRequirements($vars)
Requirements controller.
validateDatabaseVars($submissionVars, $formVars)
Database support methods.
determineInstallStatus()
Updates $this->has_completed according to the current installation.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
createSettingsFile($params)
Writes the settings file to the engine directory.
checkSettingsFile(&$report=[])
Check that the settings file exists.
elgg_get_version($human_readable=false)
Get the current Elgg version information.
isInstallDirWritable(&$report)
Indicates whether the webserver can add settings.php on its own or not.
loadSettingsFile()
Load settings.
login(\ElggUser $user, $persistent=false)
Logs in a specified .
checkDatabaseSettings($user, $password, $dbname, $host)
Confirm the settings for the database.
static sanitize($path, $append_slash=true)
Sanitise file paths ensuring that they begin and end with slashes etc.
static getMock()
Get an isolated ElggSession that does not persist between requests.
batchInstall(array $params, $create_htaccess=false)
A batch install of Elgg.
connectToDatabase()
Bootstrap database connection before entire engine is available.
setAutoLogin($flag)
Set the auto login flag.
createAdminAccount($submissionVars, $login=false)
Create a user account for the admin.
saveSiteSettings($submissionVars)
Initialize the site including site entity, plugins, and configuration.
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
_elgg_generate_plugin_entities()
Elgg plugins library Contains functions for managing plugins.
get_entity($guid)
Loads and returns an entity object from a guid.
static fromDatabase(Config $config, Database $db)
Create a session stored in the DB.
validateAdminVars($submissionVars, $formVars)
Validate account form variables.