56 private $has_completed = [
63 private $is_action =
false;
65 private $autoLogin =
true;
77 public function run() {
80 $this->is_action = $app->internal_services->request->getMethod() ===
'POST';
99 $params = $app->internal_services->request->request->all();
101 $method =
'run' . ucwords(
$step);
103 return $this->$method(
$params);
119 $config->installer_running =
true;
120 $config->dbencoding =
'utf8mb4';
122 $config->system_cache_enabled =
false;
123 $config->simplecache_enabled =
false;
124 $config->debug = \Psr\Log\LogLevel::WARNING;
125 $config->cacheroot = Paths::sanitize(sys_get_temp_dir()) .
'elgginstaller/caches/';
126 $config->assetroot = Paths::sanitize(sys_get_temp_dir()) .
'elgginstaller/assets/';
128 $app = Application::factory([
130 'handle_exceptions' =>
false,
131 'handle_shutdown' =>
false,
139 Application::setInstance($app);
143 $app->internal_services->boot->getCache()->disable();
144 $app->internal_services->plugins->getCache()->disable();
145 $app->internal_services->sessionCache->disable();
146 $app->internal_services->dataCache->disable();
147 $app->internal_services->autoloadManager->getCache()->disable();
150 $index_admin = array_search(
'admin', $this->
getSteps());
151 $index_complete = array_search(
'complete', $this->
getSteps());
156 $use_elgg_session = ($index_step == $index_admin) || ($index_step == $index_complete);
157 if (!$use_elgg_session) {
160 $app->internal_services->set(
'session',
$session);
163 $app->internal_services->views->setViewtype(
'installation');
164 $app->internal_services->views->registerViewtypeFallback(
'installation');
165 $app->internal_services->views->registerPluginViews(
Paths::elgg());
166 $app->internal_services->translator->registerTranslations(
Paths::elgg() .
'install/languages/',
true);
182 $this->autoLogin = (bool) $flag;
204 'dbhost' =>
'localhost',
206 'dbprefix' =>
'elgg_',
210 $params = array_merge(
$defaults, $params);
224 foreach ($required_params as
$key) {
225 if (empty($params[$key])) {
231 $params[
'password1'] = $params[
'password'];
232 $params[
'password2'] = $params[
'password'];
234 if ($create_htaccess) {
236 if (!$rewrite_tester->createHtaccess($params[
'wwwroot'])) {
241 if (!\
Elgg\Http\Urls::isValidMultiByteUrl($params[
'wwwroot'])) {
246 $params[
'dataroot'] = Paths::sanitize($params[
'dataroot']);
250 if (!$this->has_completed[
'config']) {
259 $config = $app->internal_services->config;
262 'dbhost' =>
'dbhost',
263 'dbport' =>
'dbport',
264 'dbuser' =>
'dbuser',
265 'dbpassword' =>
'dbpass',
266 'dbname' =>
'dbname',
267 'dataroot' =>
'dataroot',
268 'dbprefix' =>
'dbprefix',
270 foreach ($config_keys as $params_key => $config_key) {
271 if ($params[$params_key] !==
$config->$config_key) {
280 if (!$this->has_completed[
'database']) {
322 return new \Elgg\Http\OkResponse(
$output);
337 return $this->
render(
'welcome');
368 'severity' =>
'notice',
369 'message' =>
elgg_echo(
'install:check:database'),
382 'num_failures' => $numFailures,
383 'num_warnings' => $numWarnings,
409 'type' =>
'password',
420 'value' =>
'localhost',
442 'value' => $app->internal_services->config->wwwroot,
446 'type' =>
'dropdown',
448 'options' => \DateTimeZone::listIdentifiers(),
455 $this->is_action =
true;
458 if ($this->is_action) {
459 $getResponse =
function () use ($app, $submissionVars, $formVars) {
481 $app->internal_services->system_messages->addSuccessMessage(
elgg_echo(
'install:success:database'));
494 $params = [
'variables' => $formVars,];
520 'value' =>
'My New Community',
535 if ($this->is_action) {
536 $getResponse =
function () use ($app, $submissionVars, $formVars) {
546 $app->internal_services->system_messages->addSuccessMessage(
elgg_echo(
'install:success:settings'));
559 return $this->
render(
'settings', [
'variables' => $formVars]);
591 'type' =>
'password',
594 'pattern' =>
'.{6,}',
597 'type' =>
'password',
603 if ($this->is_action) {
604 $getResponse =
function () use ($app, $submissionVars, $formVars) {
613 $app->internal_services->system_messages->addSuccessMessage(
elgg_echo(
'install:success:admin'));
627 $lang = $app->internal_services->translator->getCurrentLanguage();
628 $translations = $app->internal_services->translator->getLoadedTranslations();
629 $app->internal_services->translator->addTranslation(
$lang, [
630 'install:admin:help:password1' =>
sprintf(
632 $app->internal_services->config->min_password_length
638 return $this->
render(
'admin', [
'variables' => $formVars]);
700 $this->is_action =
false;
702 return new \Elgg\Http\RedirectResponse($this->
getNextStepUrl($currentStep));
713 $index = 1 + array_search($currentStep, $this->
steps);
729 return $app->internal_services->config->wwwroot .
"install.php?step={$nextStep}";
741 $path = Config::resolvePath();
748 $this->has_completed[
'config'] =
true;
752 $app->internal_services->config->dbuser,
753 $app->internal_services->config->dbpass,
754 $app->internal_services->config->dbname,
755 $app->internal_services->config->dbhost,
756 $app->internal_services->config->dbport
759 if (!$dbSettingsPass) {
763 $db = $app->internal_services->db;
767 $result =
$db->getConnection(
'read')->executeQuery(
'SHOW TABLES');
773 if (in_array(
"{$db->prefix}config",
$table)) {
774 $this->has_completed[
'database'] =
true;
778 if ($this->has_completed[
'database'] ===
false) {
783 $qb = \Elgg\Database\Select::fromTable(
'config');
784 $qb->select(
'COUNT(*) AS total');
788 $this->has_completed[
'settings'] =
true;
794 $qb = \Elgg\Database\Select::fromTable(
'entities',
'e');
795 $qb->select(
'COUNT(*) AS total')
800 $this->has_completed[
'admin'] =
true;
805 throw new InstallationException(
'Elgg can not connect to the database: ' . $ex->getMessage(), $ex->getCode(), $ex);
818 if (
$step ===
'complete') {
822 if (!in_array(
false, $this->has_completed)) {
824 return new \Elgg\Http\RedirectResponse(
'/');
838 if (
$step !==
'welcome') {
842 if ($this->has_completed[
'database'] ===
false) {
846 if ($this->has_completed[
'settings'] ===
false) {
847 return new \Elgg\Http\RedirectResponse(
'install.php?step=settings');
850 if ($this->has_completed[
'admin'] ===
false) {
851 return new \Elgg\Http\RedirectResponse(
'install.php?step=admin');
855 return new \Elgg\Http\RedirectResponse(
'install.php?step=complete');
874 $index_db = array_search(
'database', $this->
getSteps());
877 if ($index_step > $index_db) {
881 $app->internal_services->config->site = new \ElggSite();
898 $app->internal_services->set(
'config',
$config);
901 $app->internal_services->db->resetConnections(DbConfig::fromElggConfig(
$config));
937 if (!is_writable(Paths::projectConfig())) {
940 'severity' =>
'error',
941 'message' =>
elgg_echo(
'install:check:installdir', [Paths::PATH_TO_CONFIG]),
959 if (!is_file(Config::resolvePath())) {
963 if (!is_readable(Config::resolvePath())) {
966 'severity' =>
'error',
967 'message' =>
elgg_echo(
'install:check:readsettings'),
985 if (version_compare(PHP_VERSION, self::PHP_MINIMAL_VERSION,
'<')) {
987 'severity' =>
'error',
988 'message' =>
elgg_echo(
'install:check:php:version', [self::PHP_MINIMAL_VERSION, PHP_VERSION]),
996 if (
count($phpReport) == 0) {
998 'severity' =>
'success',
999 'message' =>
elgg_echo(
'install:check:php:success'),
1024 'severity' =>
'error',
1025 'message' =>
elgg_echo(
'install:check:php:extension', [$extension]),
1036 'severity' =>
'warning',
1037 'message' =>
elgg_echo(
'install:check:php:extension:recommend', [$extension]),
1051 if (ini_get(
'open_basedir')) {
1053 'severity' =>
'warning',
1054 'message' =>
elgg_echo(
'install:check:php:open_basedir'),
1058 if (ini_get(
'safe_mode')) {
1060 'severity' =>
'warning',
1061 'message' =>
elgg_echo(
'install:check:php:safe_mode'),
1065 if (ini_get(
'arg_separator.output') !==
'&') {
1066 $separator = htmlspecialchars(ini_get(
'arg_separator.output'));
1068 'severity' =>
'error',
1073 if (ini_get(
'register_globals')) {
1075 'severity' =>
'error',
1076 'message' =>
elgg_echo(
'install:check:php:register_globals'),
1080 if (ini_get(
'session.auto_start')) {
1082 'severity' =>
'error',
1083 'message' =>
elgg_echo(
'install:check:php:session.auto_start'),
1099 $url = $app->internal_services->config->wwwroot;
1100 $url .= Request::REWRITE_TEST_TOKEN .
'?' . http_build_query([
1101 Request::REWRITE_TEST_TOKEN =>
'1',
1116 foreach (
$report as $checks) {
1117 foreach ($checks as $check) {
1118 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 (!str_starts_with($submissionVars[
'dataroot'],
'/')) {
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 (str_starts_with($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:after',
'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_manager->setIgnoreAccess(
true);
1584 if (!
$user->makeAdmin()) {
1585 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:adminaccess'));
1588 $app->internal_services->session_manager->setIgnoreAccess($ia);
1591 $user->validated =
true;
1592 $user->validated_method =
'admin_user';
1601 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:adminlogin'));
1617 if (is_array($input_value)) {
1618 return array_map([$this, __FUNCTION__], $input_value);
1621 if (!is_string($input_value)) {
1622 return $input_value;
1625 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.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
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.
Test if URL rewriting is working.
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.
validateSettingsVars($submissionVars, $formVars)
Validate the site settings form variables.
resumeInstall($step)
Check if this is a case of a install being resumed and figure out where to continue from...
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
$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.
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
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.
elgg_view_page(string $title, string|array $body, string $page_shell= 'default', array $vars=[])
Assembles and outputs a full page.
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.
Thrown when there is a major problem with the installation.
makeFormSticky($formVars, $submissionVars)
Action handling methods.
elgg_save_config(string $name, $value)
Save a configuration setting.
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.
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.
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
setAutoLogin($flag)
Set the auto login flag.
createAdminAccount($submissionVars, $login=false)
Create a user account for the admin.
elgg_normalize_url(string $url)
saveSiteSettings($submissionVars)
Initialize the site including site entity, plugins, and configuration.
Login as the specified user.
const PHP_MINIMAL_VERSION
validateAdminVars($submissionVars, $formVars)
Validate account form variables.