55 private $has_completed = [
62 private $is_action =
false;
64 private $autoLogin =
true;
76 public function run() {
79 $this->is_action = $app->internal_services->request->getMethod() ===
'POST';
98 $params = $app->internal_services->request->request->all();
100 $method =
"run" . ucwords(
$step);
102 return $this->$method(
$params);
118 $config->installer_running =
true;
119 $config->dbencoding =
'utf8mb4';
121 $config->system_cache_enabled =
false;
122 $config->simplecache_enabled =
false;
123 $config->debug = \Psr\Log\LogLevel::WARNING;
124 $config->cacheroot = Paths::sanitize(sys_get_temp_dir()) .
'elgginstaller/caches/';
125 $config->assetroot = Paths::sanitize(sys_get_temp_dir()) .
'elgginstaller/assets/';
127 $app = Application::factory([
129 'handle_exceptions' =>
false,
130 'handle_shutdown' =>
false,
138 Application::setInstance($app);
142 $app->internal_services->boot->getCache()->disable();
143 $app->internal_services->plugins->getCache()->disable();
144 $app->internal_services->sessionCache->disable();
145 $app->internal_services->dataCache->disable();
146 $app->internal_services->autoloadManager->getCache()->disable();
149 $index_admin = array_search(
'admin', $this->
getSteps());
150 $index_complete = array_search(
'complete', $this->
getSteps());
155 $use_elgg_session = ($index_step == $index_admin) || ($index_step == $index_complete);
156 if (!$use_elgg_session) {
159 $app->internal_services->set(
'session',
$session);
162 $app->internal_services->views->setViewtype(
'installation');
163 $app->internal_services->views->registerViewtypeFallback(
'installation');
164 $app->internal_services->views->registerPluginViews(
Paths::elgg());
165 $app->internal_services->translator->registerTranslations(
Paths::elgg() .
'install/languages/',
true);
181 $this->autoLogin = (bool) $flag;
203 'dbhost' =>
'localhost',
205 'dbprefix' =>
'elgg_',
209 $params = array_merge(
$defaults, $params);
223 foreach ($required_params as
$key) {
224 if (empty($params[$key])) {
225 $msg =
elgg_echo(
'install:error:requiredfield', [$key]);
231 $params[
'password1'] = $params[
'password2'] = $params[
'password'];
233 if ($create_htaccess) {
235 if (!$rewrite_tester->createHtaccess($params[
'wwwroot'])) {
240 if (!\
Elgg\Http\Urls::isValidMultiByteUrl($params[
'wwwroot'])) {
245 $params[
'dataroot'] = Paths::sanitize($params[
'dataroot']);
249 if (!$this->has_completed[
'config']) {
258 $config = $app->internal_services->config;
261 'dbhost' =>
'dbhost',
262 'dbport' =>
'dbport',
263 'dbuser' =>
'dbuser',
264 'dbpassword' =>
'dbpass',
265 'dbname' =>
'dbname',
266 'dataroot' =>
'dataroot',
267 'dbprefix' =>
'dbprefix',
269 foreach ($config_keys as $params_key => $config_key) {
270 if ($params[$params_key] !==
$config->$config_key) {
279 if (!$this->has_completed[
'database']) {
321 return new \Elgg\Http\OkResponse(
$output);
336 return $this->
render(
'welcome');
367 'severity' =>
'notice',
368 'message' =>
elgg_echo(
'install:check:database'),
381 'num_failures' => $numFailures,
382 'num_warnings' => $numWarnings,
408 'type' =>
'password',
419 'value' =>
'localhost',
441 'value' => $app->internal_services->config->wwwroot,
445 'type' =>
'dropdown',
447 'options' => \DateTimeZone::listIdentifiers(),
454 $this->is_action =
true;
457 if ($this->is_action) {
458 $getResponse =
function () use ($app, $submissionVars, $formVars) {
480 $app->internal_services->system_messages->addSuccessMessage(
elgg_echo(
'install:success:database'));
485 $response = $getResponse();
493 $params = [
'variables' => $formVars,];
519 'value' =>
'My New Community',
534 if ($this->is_action) {
535 $getResponse =
function () use ($app, $submissionVars, $formVars) {
545 $app->internal_services->system_messages->addSuccessMessage(
elgg_echo(
'install:success:settings'));
550 $response = $getResponse();
558 return $this->
render(
'settings', [
'variables' => $formVars]);
590 'type' =>
'password',
593 'pattern' =>
'.{6,}',
596 'type' =>
'password',
602 if ($this->is_action) {
603 $getResponse =
function () use ($app, $submissionVars, $formVars) {
612 $app->internal_services->system_messages->addSuccessMessage(
elgg_echo(
'install:success:admin'));
617 $response = $getResponse();
626 $lang = $app->internal_services->translator->getCurrentLanguage();
627 $translations = $app->internal_services->translator->getLoadedTranslations();
628 $app->internal_services->translator->addTranslation(
$lang, [
629 'install:admin:help:password1' =>
sprintf(
631 $app->internal_services->config->min_password_length
637 return $this->
render(
'admin', [
'variables' => $formVars]);
699 $this->is_action =
false;
701 return new \Elgg\Http\RedirectResponse($this->
getNextStepUrl($currentStep));
712 $index = 1 + array_search($currentStep, $this->
steps);
728 return $app->internal_services->config->wwwroot .
"install.php?step={$nextStep}";
740 $path = Config::resolvePath();
747 $this->has_completed[
'config'] =
true;
751 $app->internal_services->config->dbuser,
752 $app->internal_services->config->dbpass,
753 $app->internal_services->config->dbname,
754 $app->internal_services->config->dbhost,
755 $app->internal_services->config->dbport
758 if (!$dbSettingsPass) {
762 $db = $app->internal_services->db;
766 $result =
$db->getConnection(
'read')->executeQuery(
'SHOW TABLES');
771 if (in_array(
"{$db->prefix}config",
$table)) {
772 $this->has_completed[
'database'] =
true;
775 if ($this->has_completed[
'database'] ==
false) {
780 $qb = \Elgg\Database\Select::fromTable(
'config');
781 $qb->select(
'COUNT(*) AS total');
785 $this->has_completed[
'settings'] =
true;
791 $qb = \Elgg\Database\Select::fromTable(
'entities',
'e');
792 $qb->select(
'COUNT(*) AS total')
797 $this->has_completed[
'admin'] =
true;
802 throw new InstallationException(
'Elgg can not connect to the database: ' . $ex->getMessage(), $ex->getCode(), $ex);
817 if (
$step ===
'complete') {
821 if (!in_array(
false, $this->has_completed)) {
823 return new \Elgg\Http\RedirectResponse(
'/');
837 if (
$step !==
'welcome') {
841 if ($this->has_completed[
'database'] ==
false) {
845 if ($this->has_completed[
'settings'] ==
false) {
846 return new \Elgg\Http\RedirectResponse(
'install.php?step=settings');
849 if ($this->has_completed[
'admin'] ==
false) {
850 return new \Elgg\Http\RedirectResponse(
'install.php?step=admin');
854 return new \Elgg\Http\RedirectResponse(
'install.php?step=complete');
873 $index_db = array_search(
'database', $this->
getSteps());
876 if ($index_step > $index_db) {
880 $app->internal_services->config->site = new \ElggSite();
896 $config = Config::fromFile(Config::resolvePath());
897 $app->internal_services->set(
'config',
$config);
900 $app->internal_services->db->resetConnections(DbConfig::fromElggConfig(
$config));
936 if (!is_writable(Paths::projectConfig())) {
939 'severity' =>
'error',
940 'message' =>
elgg_echo(
'install:check:installdir', [Paths::PATH_TO_CONFIG]),
958 if (!is_file(Config::resolvePath())) {
962 if (!is_readable(Config::resolvePath())) {
965 'severity' =>
'error',
966 'message' =>
elgg_echo(
'install:check:readsettings'),
984 if (version_compare(PHP_VERSION, self::PHP_MINIMAL_VERSION,
'<')) {
986 'severity' =>
'error',
987 'message' =>
elgg_echo(
'install:check:php:version', [self::PHP_MINIMAL_VERSION, PHP_VERSION]),
995 if (
count($phpReport) == 0) {
997 'severity' =>
'success',
998 'message' =>
elgg_echo(
'install:check:php:success'),
1023 'severity' =>
'error',
1024 'message' =>
elgg_echo(
'install:check:php:extension', [$extension]),
1035 'severity' =>
'warning',
1036 'message' =>
elgg_echo(
'install:check:php:extension:recommend', [$extension]),
1050 if (ini_get(
'open_basedir')) {
1052 'severity' =>
'warning',
1053 'message' =>
elgg_echo(
'install:check:php:open_basedir'),
1057 if (ini_get(
'safe_mode')) {
1059 'severity' =>
'warning',
1060 'message' =>
elgg_echo(
'install:check:php:safe_mode'),
1064 if (ini_get(
'arg_separator.output') !==
'&') {
1065 $separator = htmlspecialchars(ini_get(
'arg_separator.output'));
1067 'severity' =>
'error',
1072 if (ini_get(
'register_globals')) {
1074 'severity' =>
'error',
1075 'message' =>
elgg_echo(
'install:check:php:register_globals'),
1079 if (ini_get(
'session.auto_start')) {
1081 'severity' =>
'error',
1082 'message' =>
elgg_echo(
'install:check:php:session.auto_start'),
1098 $url = $app->internal_services->config->wwwroot;
1099 $url .= Request::REWRITE_TEST_TOKEN .
'?' . http_build_query([
1100 Request::REWRITE_TEST_TOKEN =>
'1',
1115 foreach (
$report as $checks) {
1116 foreach ($checks as $check) {
1117 if ($check[
'severity'] === $condition) {
1144 if (
$info[
'required'] ==
true && !$submissionVars[
$field]) {
1146 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:requiredfield', [
$name]));
1152 if (!empty($submissionVars[
'wwwroot']) && !\
Elgg\Http\Urls::isValidMultiByteUrl($submissionVars[
'wwwroot'])) {
1154 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:wwwroot', [$save_value]));
1160 if (stripos(PHP_OS,
'win') === 0) {
1161 if (
strpos($submissionVars[
'dataroot'],
':') !== 1) {
1163 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:relative_path', [$save_value]));
1168 if (
strpos($submissionVars[
'dataroot'],
'/') !== 0) {
1170 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:relative_path', [$save_value]));
1177 if (!is_dir($submissionVars[
'dataroot'])) {
1179 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:datadirectoryexists', [$save_value]));
1185 if (!is_writable($submissionVars[
'dataroot'])) {
1187 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:writedatadirectory', [$save_value]));
1193 if (stripos($submissionVars[
'dataroot'],
Paths::project()) === 0) {
1195 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:locationdatadirectory', [$save_value]));
1205 if (!empty($submissionVars[
'dbprefix']) && !
preg_match(
"/^[a-zA-Z_][\w]*$/", $submissionVars[
'dbprefix'])) {
1206 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:database_prefix'));
1212 $submissionVars[
'dbuser'],
1213 $submissionVars[
'dbpassword'],
1214 $submissionVars[
'dbname'],
1215 $submissionVars[
'dbhost'],
1216 $submissionVars[
'dbport']
1239 'dbname' => $dbname,
1240 'dbencoding' =>
'utf8mb4',
1245 $db->getConnection(
'read')->executeQuery(
'SELECT 1');
1247 if (0 ===
strpos($e->getMessage(),
"Elgg couldn't connect")) {
1248 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:databasesettings'));
1251 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:nodatabase', [$save_value]));
1259 $min_version =
$db->isMariaDB() ? self::MARIADB_MINIMAL_VERSION : self::MYSQL_MINIMAL_VERSION;
1280 $template = Application::elggDir()->getContents(
'elgg-config/settings.example.php');
1282 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:readsettingsphp'));
1287 foreach (
$params as $k => $v) {
1291 $v = Paths::sanitize($v);
1294 $v = addslashes($v);
1298 $template =
str_replace(
"{{" . $k .
"}}", $v, $template);
1301 $result = file_put_contents(Config::resolvePath(), $template);
1303 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:writesettingphp'));
1319 $this->
getApp()->internal_services->set(
'dbConfig', $dbConfig);
1320 $this->
getApp()->internal_services->db->resetConnections($dbConfig);
1333 $app->internal_services->db->setupConnections();
1335 $app->internal_services->system_messages->addErrorMessage($e->getMessage());
1350 return $this->
getApp()->migrate();
1370 if ($formVars[
'dataroot'][
'type'] !=
'combo') {
1375 if ($submissionVars[
'dataroot'] !=
'dataroot-checkbox') {
1380 if (file_exists($dir) || mkdir($dir, 0755)) {
1381 $submissionVars[
'dataroot'] = $dir;
1382 if (!file_exists(
"{$dir}/.htaccess")) {
1383 $htaccess =
"Order Deny,Allow\nDeny from All\n";
1384 if (!file_put_contents(
"$dir/.htaccess", $htaccess)) {
1408 if (
$info[
'required'] ==
true && $submissionVars[$field] ===
'') {
1410 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:requiredfield', [
$name]));
1417 if ($submissionVars[
'siteemail'] && !
elgg_is_valid_email((
string) $submissionVars[
'siteemail'])) {
1419 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:emailaddress', [$save_value]));
1440 $site = new \ElggSite();
1441 $site->name = strip_tags($submissionVars[
'sitename']);
1443 $site->email = $submissionVars[
'siteemail'];
1447 if (
$site->guid !== 1) {
1448 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:createsite'));
1453 $app->internal_services->config->site =
$site;
1456 'installed' => time(),
1457 'simplecache_enabled' => 1,
1458 'system_cache_enabled' => 1,
1459 'simplecache_minify_js' =>
true,
1460 'simplecache_minify_css' =>
true,
1461 'lastcache' => time(),
1463 'default_access' => $submissionVars[
'siteaccess'],
1464 'allow_registration' =>
false,
1465 'require_admin_validation' =>
false,
1466 'walled_garden' =>
false,
1467 'allow_user_default_access' =>
'',
1468 'default_limit' => 10,
1478 $app->internal_services->reset(
'plugins');
1480 $plugins = $app->internal_services->plugins->find(
'any');
1483 $plugin_config = $plugin->getStaticConfig(
'plugin', []);
1484 if (!
elgg_extract(
'activate_on_install', $plugin_config,
false)) {
1489 $plugin->activate();
1496 $app->internal_services->events->unregisterHandler(
'create',
'object', \
Elgg\Upgrade\CreateAdminNoticeHandler::class);
1497 $upgrades = $app->internal_services->upgradeLocator->locate();
1499 $upgrade->setCompleted();
1502 $app->internal_services->logger->log(\Psr\Log\LogLevel::ERROR, $e);
1521 if (
$info[
'required'] ==
true && !$submissionVars[
$field]) {
1523 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:requiredfield', [
$name]));
1529 if ($submissionVars[
'password1'] !== $submissionVars[
'password2']) {
1530 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:admin:password:mismatch'));
1535 if (
trim($submissionVars[
'password1']) ==
"") {
1536 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:admin:password:empty'));
1541 $minLength = $app->internal_services->configTable->get(
'min_password_length');
1542 if (
strlen($submissionVars[
'password1']) < $minLength) {
1543 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:admin:password:tooshort'));
1549 if ($submissionVars[
'email'] && !
elgg_is_valid_email((
string) $submissionVars[
'email'])) {
1551 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:emailaddress', [$save_value]));
1572 'username' => $submissionVars[
'username'],
1573 'password' => $submissionVars[
'password1'],
1574 'name' => $submissionVars[
'displayname'],
1575 'email' => $submissionVars[
'email'],
1578 $app->internal_services->system_messages->addErrorMessage($e->getMessage());
1583 $ia = $app->internal_services->session->setIgnoreAccess(
true);
1584 if (!
$user->makeAdmin()) {
1585 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:adminaccess'));
1587 $app->internal_services->session->setIgnoreAccess($ia);
1590 $user->validated =
true;
1591 $user->validated_method =
'admin_user';
1600 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:adminlogin'));
1616 if (is_array($input_value)) {
1617 return array_map([$this, __FUNCTION__], $input_value);
1620 if (!is_string($input_value)) {
1621 return $input_value;
1624 return htmlspecialchars($input_value);
foreach(array_keys($combine_languages) as $language) $translations
createDataDirectory(&$submissionVars, $formVars)
Site settings support methods.
A generic parent class for Configuration exceptions.
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.
Database configuration service.
countNumConditions($report, $condition)
Count the number of failures in the requirements report.
Elgg registration action.
runAdmin($submissionVars)
Admin account controller.
checkDatabaseSettings($user, $password, $dbname, $host, $port)
Confirm the settings for the database.
Generic parent class for login exceptions.
if(!$user||!$user->canDelete()) $name
checkPhpDirectives(&$phpReport)
Check PHP parameters.
runWelcome($vars)
Step controllers.
elgg_register_user(array $params=[])
Registers a user.
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.
static fromFiles(Config $config)
Create a session stored in files.
Could not register a new user for whatever reason.
getSteps()
Step management.
getApp()
Build the application needed by the installer.
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
sanitizeInputValue($input_value)
Sanitize input to help prevent XSS.
checkPHP(&$report)
Check version of PHP, extensions, and variables.
if(!$item instanceof ElggEntity) $link
const MARIADB_MINIMAL_VERSION
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.
Updates the basic settings for the primary site object.
$upgrades
Lists pending upgrades.
getCurrentStep()
Returns current step.
continueToNextStep($currentStep)
Forwards the browser to the next step.
getNextStepUrl($currentStep)
Get the URL of the next step.
if(empty($guid)) $upgrade
if(!$user||!$user->canEdit()) $password
const MYSQL_MINIMAL_VERSION
finishBootstrapping($step)
Bootstrapping.
render($step, $vars=[])
Renders the data passed by a controller.
foreach($recommendedExtensions as $extension) if(empty(ini_get('session.gc_probability'))||empty(ini_get('session.gc_divisor'))) $db
runComplete()
Controller for last step.
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Thrown when there is a major problem with the installation.
makeFormSticky($formVars, $submissionVars)
Action handling methods.
A generic parent class for database exceptions.
checkPhpExtensions(&$phpReport)
Check the server's PHP extensions.
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.
elgg_delete_directory(string $directory, bool $leave_base_directory=false)
Delete a directory and all its contents.
if(isset($_COOKIE['elggperm'])) $session
checkSettingsFile(&$report=[])
Check that the settings file exists.
elgg_view_url(string $href, string $text=null, array $options=[])
Helper function for outputting urls.
isInstallDirWritable(&$report)
Indicates whether the webserver can add settings.php on its own or not.
loadSettingsFile()
Load settings.
foreach($requiredExtensions as $extension) $recommendedExtensions
elgg_login(\ElggUser $user, bool $persistent=false)
Log in a user.
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
static sanitize($path, $append_slash=true)
Sanitize file paths ensuring that they begin and end with slashes etc.
elgg_add_admin_notice(string $id, string $message)
Write a persistent message to the admin view.
_elgg_services()
Get the global service provider.
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.
Login as the specified user.
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
const PHP_MINIMAL_VERSION
validateAdminVars($submissionVars, $formVars)
Validate account form variables.