75 public function run(): \
Elgg\Http\ResponseBuilder {
78 $this->is_action =
$app->internal_services->request->getMethod() ===
'POST';
97 $params =
$app->internal_services->request->request->all();
99 $method =
'run' . ucwords(
$step);
101 return $this->$method(
$params);
117 $config->installer_running =
true;
118 $config->dbencoding =
'utf8mb4';
120 $config->system_cache_enabled =
false;
121 $config->simplecache_enabled =
false;
122 $config->debug = \Psr\Log\LogLevel::WARNING;
123 $config->cacheroot = sys_get_temp_dir() .
'elgginstaller/caches';
124 $config->assetroot = sys_get_temp_dir() .
'elgginstaller/assets';
126 $app = Application::factory([
128 'handle_exceptions' =>
false,
129 'handle_shutdown' =>
false,
137 Application::setInstance(
$app);
141 $app->internal_services->bootCache->disable();
142 $app->internal_services->pluginsCache->disable();
143 $app->internal_services->accessCache->disable();
144 $app->internal_services->metadataCache->disable();
145 $app->internal_services->serverCache->disable();
148 $index_admin = array_search(
'admin', $this->
getSteps());
149 $index_complete = array_search(
'complete', $this->
getSteps());
154 $use_elgg_session = ($index_step == $index_admin) || ($index_step == $index_complete);
155 if (!$use_elgg_session) {
161 $app->internal_services->views->setViewtype(
'installation');
162 $app->internal_services->views->registerViewtypeFallback(
'installation');
164 $app->internal_services->translator->registerTranslations(
Paths::elgg() .
'install/languages/',
true);
191 'dbhost' =>
'localhost',
193 'dbprefix' =>
'elgg_',
197 $params = array_merge(
$defaults, $params);
211 foreach ($required_params as
$key) {
212 if (empty($params[$key])) {
218 $params[
'password1'] = $params[
'password'];
219 $params[
'password2'] = $params[
'password'];
221 if ($create_htaccess) {
223 if (!$rewrite_tester->createHtaccess($params[
'wwwroot'])) {
228 if (!\
Elgg\Http\Urls::isValidMultiByteUrl($params[
'wwwroot'])) {
233 $params[
'dataroot'] = Paths::sanitize($params[
'dataroot']);
237 if (!$this->has_completed[
'config']) {
247 if ($params[
'dataroot'] !==
$config->dataroot) {
251 $db_config =
$app->internal_services->dbConfig->getConnectionConfig();
257 'dbpassword' =>
'password',
258 'dbname' =>
'database',
259 'dbprefix' =>
'prefix',
261 foreach ($db_config_keys as $params_key => $db_config_key) {
262 if ($params[$params_key] !== (
string) $db_config[$db_config_key]) {
263 throw new InstallationException(
elgg_echo(
'install:error:settings_mismatch', [$db_config_key, $params[$params_key], $db_config[$db_config_key]]));
271 if (!$this->has_completed[
'database']) {
313 return new \Elgg\Http\OkResponse(
$output);
326 return $this->
render(
'welcome');
357 'severity' =>
'notice',
358 'message' =>
elgg_echo(
'install:check:database'),
362 return $this->
render(
'requirements', [
378 protected function runDatabase(array $submissionVars = []): \
Elgg\Http\ResponseBuilder {
389 'type' =>
'password',
400 'value' =>
'localhost',
422 'value' =>
$app->internal_services->config->wwwroot,
426 'type' =>
'dropdown',
428 'options' => \DateTimeZone::listIdentifiers(),
435 $this->is_action =
true;
438 if ($this->is_action) {
439 $getResponse =
function () use (
$app, $submissionVars, $formVars) {
461 $app->internal_services->system_messages->addSuccessMessage(
elgg_echo(
'install:success:database'));
474 $params = [
'variables' => $formVars,];
493 protected function runSettings(array $submissionVars = []): \
Elgg\Http\ResponseBuilder {
500 'value' =>
'My New Community',
515 if ($this->is_action) {
516 $getResponse =
function () use (
$app, $submissionVars, $formVars) {
526 $app->internal_services->system_messages->addSuccessMessage(
elgg_echo(
'install:success:settings'));
539 return $this->
render(
'settings', [
'variables' => $formVars]);
551 protected function runAdmin(array $submissionVars = []): \
Elgg\Http\ResponseBuilder {
571 'type' =>
'password',
574 'pattern' =>
'.{6,}',
577 'type' =>
'password',
583 if ($this->is_action) {
584 $getResponse =
function () use (
$app, $submissionVars, $formVars) {
593 $app->internal_services->system_messages->addSuccessMessage(
elgg_echo(
'install:success:admin'));
607 $lang =
$app->internal_services->translator->getCurrentLanguage();
610 $app->internal_services->translator->addTranslation(
$lang, [
611 'install:admin:help:password1' =>
sprintf(
613 $app->internal_services->config->min_password_length
619 return $this->
render(
'admin', [
'variables' => $formVars]);
677 $this->is_action =
false;
679 return new \Elgg\Http\RedirectResponse($this->
getNextStepUrl($currentStep));
690 $index = 1 + array_search($currentStep, $this->
steps);
706 return $app->internal_services->config->wwwroot .
"install.php?step={$nextStep}";
718 $path = Config::resolvePath();
725 $this->has_completed[
'config'] =
true;
730 if (!$dbSettingsPass) {
734 $db =
$app->internal_services->db;
738 $result =
$db->getConnection(
'read')->executeQuery(
'SHOW TABLES');
744 if (in_array(
"{$db->prefix}config",
$table)) {
745 $this->has_completed[
'database'] =
true;
749 if ($this->has_completed[
'database'] ===
false) {
754 $qb = \Elgg\Database\Select::fromTable(\
Elgg\
Database\ConfigTable::TABLE_NAME);
755 $qb->select(
'COUNT(*) AS total');
759 $this->has_completed[
'settings'] =
true;
766 $qb->select(
'COUNT(*) AS total')
771 $this->has_completed[
'admin'] =
true;
776 throw new InstallationException(
'Elgg can not connect to the database: ' . $ex->getMessage(), $ex->getCode(), $ex);
789 if ($step ===
'complete') {
793 if (!in_array(
false, $this->has_completed)) {
795 return new \Elgg\Http\RedirectResponse(
'/');
811 if ($step !==
'welcome') {
815 if ($this->has_completed[
'database'] ===
false) {
819 if ($this->has_completed[
'settings'] ===
false) {
820 return new \Elgg\Http\RedirectResponse(
'install.php?step=settings');
823 if ($this->has_completed[
'admin'] ===
false) {
824 return new \Elgg\Http\RedirectResponse(
'install.php?step=admin');
828 return new \Elgg\Http\RedirectResponse(
'install.php?step=complete');
847 $index_db = array_search(
'database', $this->
getSteps());
848 $index_step = array_search($step, $this->
getSteps());
850 if ($index_step > $index_db) {
854 $app->internal_services->config->site = new \ElggSite();
871 $app->internal_services->set(
'config',
$app->internal_services->initConfig(
$config));
874 $app->internal_services->db->resetConnections(
$app->internal_services->dbConfig);
875 }
catch (\Exception $e) {
892 protected function makeFormSticky(array $formVars = [], array $submissionVars = []): array {
910 if (!is_writable(Paths::projectConfig())) {
911 $report[
'settings'] = [
913 'severity' =>
'error',
914 'message' =>
elgg_echo(
'install:check:installdir', [Paths::PATH_TO_CONFIG]),
932 if (!is_file(Config::resolvePath())) {
936 if (!is_readable(Config::resolvePath())) {
939 'severity' =>
'error',
940 'message' =>
elgg_echo(
'install:check:readsettings'),
958 if (version_compare(PHP_VERSION, self::PHP_MINIMAL_VERSION,
'<')) {
960 'severity' =>
'error',
961 'message' =>
elgg_echo(
'install:check:php:version', [self::PHP_MINIMAL_VERSION, PHP_VERSION]),
969 if (
count($phpReport) == 0) {
971 'severity' =>
'success',
972 'message' =>
elgg_echo(
'install:check:php:success'),
976 $report[
'php'] = $phpReport;
998 'severity' =>
'error',
999 'message' =>
elgg_echo(
'install:check:php:extension', [$extension]),
1010 'severity' =>
'warning',
1011 'message' =>
elgg_echo(
'install:check:php:extension:recommend', [$extension]),
1025 if (ini_get(
'open_basedir')) {
1027 'severity' =>
'warning',
1028 'message' =>
elgg_echo(
'install:check:php:open_basedir'),
1032 if (ini_get(
'safe_mode')) {
1034 'severity' =>
'warning',
1035 'message' =>
elgg_echo(
'install:check:php:safe_mode'),
1039 if (ini_get(
'arg_separator.output') !==
'&') {
1040 $separator = htmlspecialchars(ini_get(
'arg_separator.output'));
1042 'severity' =>
'error',
1047 if (ini_get(
'register_globals')) {
1049 'severity' =>
'error',
1050 'message' =>
elgg_echo(
'install:check:php:register_globals'),
1054 if (ini_get(
'session.auto_start')) {
1056 'severity' =>
'error',
1057 'message' =>
elgg_echo(
'install:check:php:session.auto_start'),
1072 $url = $this->
getApp()->internal_services->config->wwwroot;
1073 $url .= Request::REWRITE_TEST_TOKEN .
'?' . http_build_query([Request::REWRITE_TEST_TOKEN =>
'1']);
1088 foreach ($report as $checks) {
1089 foreach ($checks as $check) {
1090 if ($check[
'severity'] === $condition) {
1116 if (
$info[
'required'] ===
true && !$submissionVars[
$field]) {
1118 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:requiredfield', [
$name]));
1124 if (!empty($submissionVars[
'wwwroot']) && !\
Elgg\Http\Urls::isValidMultiByteUrl($submissionVars[
'wwwroot'])) {
1126 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:wwwroot', [$save_value]));
1132 if (stripos(PHP_OS,
'win') === 0) {
1133 if (
strpos($submissionVars[
'dataroot'],
':') !== 1) {
1135 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:relative_path', [$save_value]));
1140 if (!str_starts_with($submissionVars[
'dataroot'],
'/')) {
1142 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:relative_path', [$save_value]));
1149 if (!is_dir($submissionVars[
'dataroot'])) {
1151 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:datadirectoryexists', [$save_value]));
1157 if (!is_writable($submissionVars[
'dataroot'])) {
1159 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:writedatadirectory', [$save_value]));
1165 if (stripos($submissionVars[
'dataroot'],
Paths::project()) === 0) {
1167 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:locationdatadirectory', [$save_value]));
1177 if (!empty($submissionVars[
'dbprefix']) && !
preg_match(
'/^[a-zA-Z_][\w]*$/', $submissionVars[
'dbprefix'])) {
1178 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:database_prefix'));
1184 'dbhost' => $submissionVars[
'dbhost'],
1185 'dbport' => $submissionVars[
'dbport'],
1186 'dbuser' => $submissionVars[
'dbuser'],
1187 'dbpass' => $submissionVars[
'dbpassword'],
1188 'dbname' => $submissionVars[
'dbname'],
1189 'dbencoding' =>
'utf8mb4',
1205 $db =
new Database($config,
$app->internal_services->queryCache,
$app->internal_services->config);
1208 $db->getConnection(
'read')->executeQuery(
'SELECT 1');
1210 if (str_starts_with($e->getMessage(),
"Elgg couldn't connect")) {
1211 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:databasesettings'));
1214 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:nodatabase', [$database]));
1222 $min_version =
$db->isMariaDB() ? self::MARIADB_MINIMAL_VERSION : self::MYSQL_MINIMAL_VERSION;
1243 $template = file_get_contents(
Paths::elgg() .
'elgg-config/settings.example.php');
1245 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:readsettingsphp'));
1250 foreach ($params as $k => $v) {
1254 $v = Paths::sanitize($v);
1257 $v = addslashes($v);
1261 $template =
str_replace(
'{{' . $k .
'}}', $v, $template);
1264 $result = file_put_contents(Config::resolvePath(), $template);
1266 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:writesettingphp'));
1272 'dbhost' =>
elgg_extract(
'dbhost', $params,
'localhost'),
1277 'dbencoding' =>
elgg_extract(
'dbencoding', $params,
'utf8mb4'),
1278 'dbprefix' =>
elgg_extract(
'dbprefix', $params,
'elgg_'),
1282 $this->
getApp()->internal_services->set(
'dbConfig', $dbConfig);
1283 $this->
getApp()->internal_services->db->resetConnections($dbConfig);
1296 $app->internal_services->db->setupConnections();
1298 $app->internal_services->system_messages->addErrorMessage($e->getMessage());
1313 return $this->
getApp()->migrate();
1314 }
catch (\Exception $e) {
1333 if ($formVars[
'dataroot'][
'type'] !==
'combo') {
1338 if ($submissionVars[
'dataroot'] !==
'dataroot-checkbox') {
1343 if (file_exists($dir) || mkdir($dir, 0755)) {
1344 $submissionVars[
'dataroot'] = $dir;
1345 if (!file_exists(
"{$dir}/.htaccess")) {
1346 $htaccess =
"Order Deny,Allow\nDeny from All\n";
1347 if (!file_put_contents(
"$dir/.htaccess", $htaccess)) {
1371 if (
$info[
'required'] ===
true && $submissionVars[$field] ===
'') {
1373 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:requiredfield', [
$name]));
1380 if ($submissionVars[
'siteemail'] && !
elgg_is_valid_email((
string) $submissionVars[
'siteemail'])) {
1382 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:emailaddress', [$save_value]));
1403 $site = new \ElggSite();
1404 $site->name = strip_tags($submissionVars[
'sitename']);
1406 $site->email = $submissionVars[
'siteemail'];
1410 if (
$site->guid !== 1) {
1411 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:createsite'));
1416 $app->internal_services->config->site =
$site;
1419 'installed' => time(),
1420 'simplecache_enabled' => 1,
1421 'system_cache_enabled' => 1,
1422 'simplecache_minify_js' =>
true,
1423 'simplecache_minify_css' =>
true,
1424 'lastcache' => time(),
1426 'default_access' => $submissionVars[
'siteaccess'],
1427 'allow_registration' =>
false,
1428 'require_admin_validation' =>
false,
1429 'walled_garden' =>
false,
1430 'allow_user_default_access' =>
'',
1431 'default_limit' => 10,
1441 $app->internal_services->reset(
'plugins');
1443 if (
elgg_extract(
'activate_plugins', $submissionVars,
true)) {
1444 $plugins =
$app->internal_services->plugins->find(
'all');
1446 foreach ($plugins as
$plugin) {
1447 $plugin_config = $plugin->getStaticConfig(
'plugin', []);
1448 if (!
elgg_extract(
'activate_on_install', $plugin_config,
false)) {
1453 $plugin->activate();
1461 $app->internal_services->events->unregisterHandler(
'create:after',
'object', \
Elgg\Upgrade\CreateAdminNoticeHandler::class);
1462 $upgrades =
$app->internal_services->upgradeLocator->locate();
1464 $upgrade->setCompleted();
1466 }
catch (\Exception $e) {
1467 $app->internal_services->logger->log(\Psr\Log\LogLevel::ERROR, $e);
1486 if (
$info[
'required'] ===
true && !$submissionVars[
$field]) {
1488 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:requiredfield', [
$name]));
1494 if ($submissionVars[
'password1'] !== $submissionVars[
'password2']) {
1495 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:admin:password:mismatch'));
1500 if (
trim($submissionVars[
'password1']) ===
'') {
1501 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:admin:password:empty'));
1506 $minLength =
$app->internal_services->configTable->get(
'min_password_length');
1507 if (
strlen($submissionVars[
'password1']) < $minLength) {
1508 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:admin:password:tooshort'));
1514 if ($submissionVars[
'email'] && !
elgg_is_valid_email((
string) $submissionVars[
'email'])) {
1516 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:emailaddress', [$save_value]));
1537 'username' => $submissionVars[
'username'],
1538 'password' => $submissionVars[
'password1'],
1539 'name' => $submissionVars[
'displayname'],
1540 'email' => $submissionVars[
'email'],
1543 $app->internal_services->system_messages->addErrorMessage($e->getMessage());
1549 if (!
$user->makeAdmin()) {
1550 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:adminaccess'));
1555 $user->validated =
true;
1556 $user->validated_method =
'admin_user';
1565 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:adminlogin'));
1581 if (is_array($input_value)) {
1582 return array_map([$this, __FUNCTION__], $input_value);
1585 if (!is_string($input_value)) {
1586 return $input_value;
1589 return htmlspecialchars($input_value);
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
batchInstall(array $params, bool $create_htaccess=false)
A batch install of Elgg.
checkPhpDirectives(array &$phpReport)
Check PHP parameters.
foreach(array_keys($combine_languages) as $language) $translations
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.
runDatabase(array $submissionVars=[])
Database set up controller.
Elgg registration action.
runSettings(array $submissionVars=[])
Site settings controller.
createSettingsFile(array $params)
Writes the settings file to the engine directory.
Generic parent class for login exceptions.
if(!$user||!$user->canDelete()) $name
elgg_register_user(array $params=[])
Registers a user.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
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.
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.
if(!$item instanceof ElggEntity) $link
const MARIADB_MINIMAL_VERSION
runAdmin(array $submissionVars=[])
Admin account controller.
getNextStep(string $currentStep)
Get the next step as a string.
getConnectionConfig(string $type=self::READ_WRITE)
Get the connection configuration.
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.
saveSiteSettings(array $submissionVars)
Initialize the site including site entity, plugins, and configuration.
getCurrentStep()
Returns current step.
const ELGG_IGNORE_ACCESS
elgg_call() flags
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
if(empty($guid)) $upgrade
checkPHP(array &$report)
Check version of PHP, extensions, and variables.
const MYSQL_MINIMAL_VERSION
makeFormSticky(array $formVars=[], array $submissionVars=[])
Action handling methods.
createAdminAccount(array $submissionVars, bool $login=false)
Create a user account for the admin.
elgg_view_page(string $title, string|array $body, string $page_shell= 'default', array $vars=[])
Assembles and outputs a full page.
runWelcome()
Step controllers.
foreach($recommendedExtensions as $extension) if(empty(ini_get('session.gc_probability'))||empty(ini_get('session.gc_divisor'))) $db
runComplete()
Controller for last step.
checkPhpExtensions(array &$phpReport)
Check the server's PHP extensions.
Thrown when there is a major problem with the installation.
elgg_save_config(string $name, $value)
Save a configuration setting.
A generic parent class for database exceptions.
runRequirements(array $vars=[])
Requirements controller.
continueToNextStep(string $currentStep)
Forwards the browser to the next step.
isInstallDirWritable(array &$report)
Indicates whether the webserver can add settings.php on its own or not.
resumeInstall(string $step)
Check if this is a case of a install being resumed and figure out where to continue from...
validateSettingsVars(array $submissionVars, array $formVars)
Validate the site settings form variables.
elgg_get_site_entity()
Get the current site entity.
validateDatabaseVars(array $submissionVars, array $formVars)
Database support methods.
checkRewriteRules(array &$report)
Confirm that the rewrite rules are firing.
countNumConditions(array $report, string $condition)
Count the number of failures in the requirements report.
determineInstallStatus()
Updates $this->has_completed according to the current installation.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
getNextStepUrl(string $currentStep)
Get the URL of the next step.
Load, boot, and implement a front controller for an Elgg application.
elgg_delete_directory(string $directory, bool $leave_base_directory=false)
Delete a directory and all its contents.
if(isset($_COOKIE['elggperm'])) $session
elgg_view_url(string $href, string $text=null, array $options=[])
Helper function for outputting urls.
loadSettingsFile()
Load settings.
checkSettingsFile(array &$report=[])
Check that the settings file exists.
createDataDirectory(array &$submissionVars, array $formVars)
Site settings support methods.
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
checkInstallCompletion(string $step)
Security check to ensure the installer cannot be run after installation has finished.
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.
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.
checkDatabaseSettings(DbConfig $config)
Confirm the settings for the database.
elgg_normalize_url(string $url)
validateAdminVars(array $submissionVars, array $formVars)
Validate account form variables.
Login as the specified user.
render(string $step, array $vars=[])
Renders the data passed by a controller.
const PHP_MINIMAL_VERSION
finishBootstrapping(string $step)
Bootstrapping.