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 = Paths::sanitize(sys_get_temp_dir()) .
'elgginstaller/caches/';
124 $config->assetroot = Paths::sanitize(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->boot->getCache()->disable();
142 $app->internal_services->plugins->getCache()->disable();
143 $app->internal_services->sessionCache->disable();
144 $app->internal_services->dataCache->disable();
145 $app->internal_services->autoloadManager->getCache()->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']) {
249 'dbhost' =>
'dbhost',
250 'dbport' =>
'dbport',
251 'dbuser' =>
'dbuser',
252 'dbpassword' =>
'dbpass',
253 'dbname' =>
'dbname',
254 'dataroot' =>
'dataroot',
255 'dbprefix' =>
'dbprefix',
257 foreach ($config_keys as $params_key => $config_key) {
258 if ($params[$params_key] !==
$config->$config_key) {
267 if (!$this->has_completed[
'database']) {
309 return new \Elgg\Http\OkResponse(
$output);
322 return $this->
render(
'welcome');
353 'severity' =>
'notice',
354 'message' =>
elgg_echo(
'install:check:database'),
358 return $this->
render(
'requirements', [
374 protected function runDatabase(array $submissionVars = []): \
Elgg\Http\ResponseBuilder {
385 'type' =>
'password',
396 'value' =>
'localhost',
418 'value' =>
$app->internal_services->config->wwwroot,
422 'type' =>
'dropdown',
424 'options' => \DateTimeZone::listIdentifiers(),
431 $this->is_action =
true;
434 if ($this->is_action) {
435 $getResponse =
function () use (
$app, $submissionVars, $formVars) {
457 $app->internal_services->system_messages->addSuccessMessage(
elgg_echo(
'install:success:database'));
470 $params = [
'variables' => $formVars,];
489 protected function runSettings(array $submissionVars = []): \
Elgg\Http\ResponseBuilder {
496 'value' =>
'My New Community',
511 if ($this->is_action) {
512 $getResponse =
function () use (
$app, $submissionVars, $formVars) {
522 $app->internal_services->system_messages->addSuccessMessage(
elgg_echo(
'install:success:settings'));
535 return $this->
render(
'settings', [
'variables' => $formVars]);
547 protected function runAdmin(array $submissionVars = []): \
Elgg\Http\ResponseBuilder {
567 'type' =>
'password',
570 'pattern' =>
'.{6,}',
573 'type' =>
'password',
579 if ($this->is_action) {
580 $getResponse =
function () use (
$app, $submissionVars, $formVars) {
589 $app->internal_services->system_messages->addSuccessMessage(
elgg_echo(
'install:success:admin'));
603 $lang =
$app->internal_services->translator->getCurrentLanguage();
606 $app->internal_services->translator->addTranslation(
$lang, [
607 'install:admin:help:password1' =>
sprintf(
609 $app->internal_services->config->min_password_length
615 return $this->
render(
'admin', [
'variables' => $formVars]);
673 $this->is_action =
false;
675 return new \Elgg\Http\RedirectResponse($this->
getNextStepUrl($currentStep));
686 $index = 1 + array_search($currentStep, $this->
steps);
702 return $app->internal_services->config->wwwroot .
"install.php?step={$nextStep}";
714 $path = Config::resolvePath();
721 $this->has_completed[
'config'] =
true;
725 $app->internal_services->config->dbuser,
726 $app->internal_services->config->dbpass,
727 $app->internal_services->config->dbname,
728 $app->internal_services->config->dbhost,
729 $app->internal_services->config->dbport
732 if (!$dbSettingsPass) {
736 $db =
$app->internal_services->db;
740 $result =
$db->getConnection(
'read')->executeQuery(
'SHOW TABLES');
746 if (in_array(
"{$db->prefix}config",
$table)) {
747 $this->has_completed[
'database'] =
true;
751 if ($this->has_completed[
'database'] ===
false) {
756 $qb = \Elgg\Database\Select::fromTable(
'config');
757 $qb->select(
'COUNT(*) AS total');
761 $this->has_completed[
'settings'] =
true;
767 $qb = \Elgg\Database\Select::fromTable(
'entities',
'e');
768 $qb->select(
'COUNT(*) AS total')
773 $this->has_completed[
'admin'] =
true;
778 throw new InstallationException(
'Elgg can not connect to the database: ' . $ex->getMessage(), $ex->getCode(), $ex);
791 if ($step ===
'complete') {
795 if (!in_array(
false, $this->has_completed)) {
797 return new \Elgg\Http\RedirectResponse(
'/');
813 if ($step !==
'welcome') {
817 if ($this->has_completed[
'database'] ===
false) {
821 if ($this->has_completed[
'settings'] ===
false) {
822 return new \Elgg\Http\RedirectResponse(
'install.php?step=settings');
825 if ($this->has_completed[
'admin'] ===
false) {
826 return new \Elgg\Http\RedirectResponse(
'install.php?step=admin');
830 return new \Elgg\Http\RedirectResponse(
'install.php?step=complete');
849 $index_db = array_search(
'database', $this->
getSteps());
850 $index_step = array_search($step, $this->
getSteps());
852 if ($index_step > $index_db) {
856 $app->internal_services->config->site = new \ElggSite();
876 $app->internal_services->db->resetConnections(DbConfig::fromElggConfig(
$config));
894 protected function makeFormSticky(array $formVars = [], array $submissionVars = []): array {
912 if (!is_writable(Paths::projectConfig())) {
913 $report[
'settings'] = [
915 'severity' =>
'error',
916 'message' =>
elgg_echo(
'install:check:installdir', [Paths::PATH_TO_CONFIG]),
934 if (!is_file(Config::resolvePath())) {
938 if (!is_readable(Config::resolvePath())) {
941 'severity' =>
'error',
942 'message' =>
elgg_echo(
'install:check:readsettings'),
960 if (version_compare(PHP_VERSION, self::PHP_MINIMAL_VERSION,
'<')) {
962 'severity' =>
'error',
963 'message' =>
elgg_echo(
'install:check:php:version', [self::PHP_MINIMAL_VERSION, PHP_VERSION]),
971 if (
count($phpReport) == 0) {
973 'severity' =>
'success',
974 'message' =>
elgg_echo(
'install:check:php:success'),
978 $report[
'php'] = $phpReport;
999 'severity' =>
'error',
1000 'message' =>
elgg_echo(
'install:check:php:extension', [$extension]),
1011 'severity' =>
'warning',
1012 'message' =>
elgg_echo(
'install:check:php:extension:recommend', [$extension]),
1026 if (ini_get(
'open_basedir')) {
1028 'severity' =>
'warning',
1029 'message' =>
elgg_echo(
'install:check:php:open_basedir'),
1033 if (ini_get(
'safe_mode')) {
1035 'severity' =>
'warning',
1036 'message' =>
elgg_echo(
'install:check:php:safe_mode'),
1040 if (ini_get(
'arg_separator.output') !==
'&') {
1041 $separator = htmlspecialchars(ini_get(
'arg_separator.output'));
1043 'severity' =>
'error',
1048 if (ini_get(
'register_globals')) {
1050 'severity' =>
'error',
1051 'message' =>
elgg_echo(
'install:check:php:register_globals'),
1055 if (ini_get(
'session.auto_start')) {
1057 'severity' =>
'error',
1058 'message' =>
elgg_echo(
'install:check:php:session.auto_start'),
1073 $url = $this->
getApp()->internal_services->config->wwwroot;
1074 $url .= Request::REWRITE_TEST_TOKEN .
'?' . http_build_query([Request::REWRITE_TEST_TOKEN =>
'1']);
1089 foreach ($report as $checks) {
1090 foreach ($checks as $check) {
1091 if ($check[
'severity'] === $condition) {
1117 if (
$info[
'required'] ===
true && !$submissionVars[
$field]) {
1119 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:requiredfield', [
$name]));
1125 if (!empty($submissionVars[
'wwwroot']) && !\
Elgg\Http\Urls::isValidMultiByteUrl($submissionVars[
'wwwroot'])) {
1127 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:wwwroot', [$save_value]));
1133 if (stripos(PHP_OS,
'win') === 0) {
1134 if (
strpos($submissionVars[
'dataroot'],
':') !== 1) {
1136 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:relative_path', [$save_value]));
1141 if (!str_starts_with($submissionVars[
'dataroot'],
'/')) {
1143 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:relative_path', [$save_value]));
1150 if (!is_dir($submissionVars[
'dataroot'])) {
1152 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:datadirectoryexists', [$save_value]));
1158 if (!is_writable($submissionVars[
'dataroot'])) {
1160 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:writedatadirectory', [$save_value]));
1166 if (stripos($submissionVars[
'dataroot'],
Paths::project()) === 0) {
1168 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:locationdatadirectory', [$save_value]));
1178 if (!empty($submissionVars[
'dbprefix']) && !
preg_match(
'/^[a-zA-Z_][\w]*$/', $submissionVars[
'dbprefix'])) {
1179 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:database_prefix'));
1185 $submissionVars[
'dbuser'],
1186 $submissionVars[
'dbpassword'],
1187 $submissionVars[
'dbname'],
1188 $submissionVars[
'dbhost'],
1189 $submissionVars[
'dbport']
1211 'dbpass' => $password,
1212 'dbname' => $dbname,
1213 'dbencoding' =>
'utf8mb4',
1218 $db->getConnection(
'read')->executeQuery(
'SELECT 1');
1220 if (str_starts_with($e->getMessage(),
"Elgg couldn't connect")) {
1221 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:databasesettings'));
1224 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:nodatabase', [$save_value]));
1232 $min_version =
$db->isMariaDB() ? self::MARIADB_MINIMAL_VERSION : self::MYSQL_MINIMAL_VERSION;
1253 $template = Application::elggDir()->getContents(
'elgg-config/settings.example.php');
1255 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:readsettingsphp'));
1260 foreach ($params as $k => $v) {
1264 $v = Paths::sanitize($v);
1267 $v = addslashes($v);
1271 $template =
str_replace(
'{{' . $k .
'}}', $v, $template);
1274 $result = file_put_contents(Config::resolvePath(), $template);
1276 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:writesettingphp'));
1282 'dbhost' =>
elgg_extract(
'dbhost', $params,
'localhost'),
1287 'dbencoding' =>
elgg_extract(
'dbencoding', $params,
'utf8mb4'),
1288 'dbprefix' =>
elgg_extract(
'dbprefix', $params,
'elgg_'),
1292 $this->
getApp()->internal_services->set(
'dbConfig', $dbConfig);
1293 $this->
getApp()->internal_services->db->resetConnections($dbConfig);
1306 $app->internal_services->db->setupConnections();
1308 $app->internal_services->system_messages->addErrorMessage($e->getMessage());
1323 return $this->
getApp()->migrate();
1343 if ($formVars[
'dataroot'][
'type'] !==
'combo') {
1348 if ($submissionVars[
'dataroot'] !==
'dataroot-checkbox') {
1353 if (file_exists($dir) || mkdir($dir, 0755)) {
1354 $submissionVars[
'dataroot'] = $dir;
1355 if (!file_exists(
"{$dir}/.htaccess")) {
1356 $htaccess =
"Order Deny,Allow\nDeny from All\n";
1357 if (!file_put_contents(
"$dir/.htaccess", $htaccess)) {
1381 if (
$info[
'required'] ===
true && $submissionVars[$field] ===
'') {
1383 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:requiredfield', [
$name]));
1390 if ($submissionVars[
'siteemail'] && !
elgg_is_valid_email((
string) $submissionVars[
'siteemail'])) {
1392 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:emailaddress', [$save_value]));
1413 $site = new \ElggSite();
1414 $site->name = strip_tags($submissionVars[
'sitename']);
1416 $site->email = $submissionVars[
'siteemail'];
1420 if (
$site->guid !== 1) {
1421 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:createsite'));
1426 $app->internal_services->config->site =
$site;
1429 'installed' => time(),
1430 'simplecache_enabled' => 1,
1431 'system_cache_enabled' => 1,
1432 'simplecache_minify_js' =>
true,
1433 'simplecache_minify_css' =>
true,
1434 'lastcache' => time(),
1436 'default_access' => $submissionVars[
'siteaccess'],
1437 'allow_registration' =>
false,
1438 'require_admin_validation' =>
false,
1439 'walled_garden' =>
false,
1440 'allow_user_default_access' =>
'',
1441 'default_limit' => 10,
1451 $app->internal_services->reset(
'plugins');
1453 if (
elgg_extract(
'activate_plugins', $submissionVars,
true)) {
1454 $plugins =
$app->internal_services->plugins->find(
'any');
1457 $plugin_config = $plugin->getStaticConfig(
'plugin', []);
1458 if (!
elgg_extract(
'activate_on_install', $plugin_config,
false)) {
1463 $plugin->activate();
1471 $app->internal_services->events->unregisterHandler(
'create:after',
'object', \
Elgg\Upgrade\CreateAdminNoticeHandler::class);
1472 $upgrades =
$app->internal_services->upgradeLocator->locate();
1474 $upgrade->setCompleted();
1477 $app->internal_services->logger->log(\Psr\Log\LogLevel::ERROR, $e);
1496 if (
$info[
'required'] ===
true && !$submissionVars[
$field]) {
1498 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:requiredfield', [
$name]));
1504 if ($submissionVars[
'password1'] !== $submissionVars[
'password2']) {
1505 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:admin:password:mismatch'));
1510 if (
trim($submissionVars[
'password1']) ===
'') {
1511 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:admin:password:empty'));
1516 $minLength =
$app->internal_services->configTable->get(
'min_password_length');
1517 if (
strlen($submissionVars[
'password1']) < $minLength) {
1518 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:admin:password:tooshort'));
1524 if ($submissionVars[
'email'] && !
elgg_is_valid_email((
string) $submissionVars[
'email'])) {
1526 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:emailaddress', [$save_value]));
1547 'username' => $submissionVars[
'username'],
1548 'password' => $submissionVars[
'password1'],
1549 'name' => $submissionVars[
'displayname'],
1550 'email' => $submissionVars[
'email'],
1553 $app->internal_services->system_messages->addErrorMessage($e->getMessage());
1559 if (!
$user->makeAdmin()) {
1560 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:adminaccess'));
1565 $user->validated =
true;
1566 $user->validated_method =
'admin_user';
1575 $app->internal_services->system_messages->addErrorMessage(
elgg_echo(
'install:error:adminlogin'));
1591 if (is_array($input_value)) {
1592 return array_map([$this, __FUNCTION__], $input_value);
1595 if (!is_string($input_value)) {
1596 return $input_value;
1599 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.
checkDatabaseSettings(string $user, string $password, string $dbname, string $host, int $port=null)
Confirm the settings for the database.
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.
if(!$user||!$user->canEdit()) $password
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.
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.