Skip to content

Commit

Permalink
chore(install): coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Oct 25, 2022
1 parent 04bf88c commit 3dc2c7b
Showing 1 changed file with 46 additions and 57 deletions.
103 changes: 46 additions & 57 deletions engine/classes/ElggInstaller.php
Expand Up @@ -162,7 +162,7 @@ protected function getApp() {
$app->internal_services->views->setViewtype('installation');
$app->internal_services->views->registerViewtypeFallback('installation');
$app->internal_services->views->registerPluginViews(Paths::elgg());
$app->internal_services->translator->registerTranslations(Paths::elgg() . "install/languages/", true);
$app->internal_services->translator->registerTranslations(Paths::elgg() . 'install/languages/', true);

return $this->app;
} catch (ConfigurationException $ex) {
Expand Down Expand Up @@ -305,8 +305,8 @@ public function batchInstall(array $params, $create_htaccess = false) {
protected function render($step, $vars = []) {
$vars['next_step'] = $this->getNextStep($step);

$title = elgg_echo("install:$step");
$body = elgg_view("install/pages/$step", $vars);
$title = elgg_echo("install:{$step}");
$body = elgg_view("install/pages/{$step}", $vars);

$output = elgg_view_page(
$title,
Expand Down Expand Up @@ -365,7 +365,7 @@ protected function runRequirements($vars) {
$report['database'] = [
[
'severity' => 'notice',
'message' => elgg_echo('install:check:database')
'message' => elgg_echo('install:check:database'),
]
];

Expand Down Expand Up @@ -710,11 +710,8 @@ protected function continueToNextStep($currentStep) {
*/
protected function getNextStep($currentStep) {
$index = 1 + array_search($currentStep, $this->steps);
if (isset($this->steps[$index])) {
return $this->steps[$index];
} else {
return null;
}

return $this->steps[$index] ?? null;
}

/**
Expand All @@ -728,7 +725,7 @@ protected function getNextStepUrl($currentStep) {
$app = $this->getApp();
$nextStep = $this->getNextStep($currentStep);

return $app->internal_services->config->wwwroot . "install.php?step=$nextStep";
return $app->internal_services->config->wwwroot . "install.php?step={$nextStep}";
}

/**
Expand Down Expand Up @@ -802,7 +799,7 @@ protected function determineInstallStatus() {
return;
}
} catch (DatabaseException $ex) {
throw new InstallationException('Elgg can not connect to the database: ' . $ex->getMessage());
throw new InstallationException('Elgg can not connect to the database: ' . $ex->getMessage(), $ex->getCode(), $ex);
}

return;
Expand All @@ -817,11 +814,13 @@ protected function determineInstallStatus() {
* @return \Elgg\Http\RedirectResponse|null
*/
protected function checkInstallCompletion($step) {
if ($step != 'complete') {
if (!in_array(false, $this->has_completed)) {
// install complete but someone is trying to view an install page
return new \Elgg\Http\RedirectResponse('/');
}
if ($step === 'complete') {
return;
}

if (!in_array(false, $this->has_completed)) {
// install complete but someone is trying to view an install page
return new \Elgg\Http\RedirectResponse('/');
}
}

Expand All @@ -844,15 +843,15 @@ protected function resumeInstall($step) {
}

if ($this->has_completed['settings'] == false) {
return new \Elgg\Http\RedirectResponse("install.php?step=settings");
return new \Elgg\Http\RedirectResponse('install.php?step=settings');
}

if ($this->has_completed['admin'] == false) {
return new \Elgg\Http\RedirectResponse("install.php?step=admin");
return new \Elgg\Http\RedirectResponse('install.php?step=admin');
}

// everything appears to be set up
return new \Elgg\Http\RedirectResponse("install.php?step=complete");
return new \Elgg\Http\RedirectResponse('install.php?step=complete');
}

/**
Expand All @@ -878,7 +877,7 @@ protected function finishBootstrapping($step) {
// once the database has been created, load rest of engine

// dummy site needed to boot
$app->internal_services->config->site = new ElggSite();
$app->internal_services->config->site = new \ElggSite();

$app->bootCore();
}
Expand All @@ -900,8 +899,7 @@ protected function loadSettingsFile() {
// in case the DB instance is already captured in services, we re-inject its settings.
$app->internal_services->db->resetConnections(DbConfig::fromElggConfig($config));
} catch (\Exception $e) {
$msg = elgg_echo('InstallationException:CannotLoadSettings');
throw new InstallationException($msg, 0, $e);
throw new InstallationException(elgg_echo('InstallationException:CannotLoadSettings'), 0, $e);
}
}

Expand Down Expand Up @@ -936,11 +934,10 @@ protected function makeFormSticky($formVars, $submissionVars) {
*/
protected function isInstallDirWritable(&$report) {
if (!is_writable(Paths::projectConfig())) {
$msg = elgg_echo('install:check:installdir', [Paths::PATH_TO_CONFIG]);
$report['settings'] = [
[
'severity' => 'error',
'message' => $msg,
'message' => elgg_echo('install:check:installdir', [Paths::PATH_TO_CONFIG]),
]
];

Expand Down Expand Up @@ -987,7 +984,7 @@ protected function checkPHP(&$report) {
if (version_compare(PHP_VERSION, self::PHP_MINIMAL_VERSION, '<')) {
$phpReport[] = [
'severity' => 'error',
'message' => elgg_echo('install:check:php:version', [self::PHP_MINIMAL_VERSION, PHP_VERSION])
'message' => elgg_echo('install:check:php:version', [self::PHP_MINIMAL_VERSION, PHP_VERSION]),
];
}

Expand All @@ -998,7 +995,7 @@ protected function checkPHP(&$report) {
if (count($phpReport) == 0) {
$phpReport[] = [
'severity' => 'success',
'message' => elgg_echo('install:check:php:success')
'message' => elgg_echo('install:check:php:success'),
];
}

Expand All @@ -1024,7 +1021,7 @@ protected function checkPhpExtensions(&$phpReport) {
if (!in_array($extension, $extensions)) {
$phpReport[] = [
'severity' => 'error',
'message' => elgg_echo('install:check:php:extension', [$extension])
'message' => elgg_echo('install:check:php:extension', [$extension]),
];
}
}
Expand All @@ -1036,7 +1033,7 @@ protected function checkPhpExtensions(&$phpReport) {
if (!in_array($extension, $extensions)) {
$phpReport[] = [
'severity' => 'warning',
'message' => elgg_echo('install:check:php:extension:recommend', [$extension])
'message' => elgg_echo('install:check:php:extension:recommend', [$extension]),
];
}
}
Expand All @@ -1053,37 +1050,36 @@ protected function checkPhpDirectives(&$phpReport) {
if (ini_get('open_basedir')) {
$phpReport[] = [
'severity' => 'warning',
'message' => elgg_echo("install:check:php:open_basedir")
'message' => elgg_echo('install:check:php:open_basedir'),
];
}

if (ini_get('safe_mode')) {
$phpReport[] = [
'severity' => 'warning',
'message' => elgg_echo("install:check:php:safe_mode")
'message' => elgg_echo('install:check:php:safe_mode'),
];
}

if (ini_get('arg_separator.output') !== '&') {
$separator = htmlspecialchars(ini_get('arg_separator.output'));
$msg = elgg_echo("install:check:php:arg_separator", [$separator]);
$phpReport[] = [
'severity' => 'error',
'message' => $msg,
'message' => elgg_echo('install:check:php:arg_separator', [$separator]),
];
}

if (ini_get('register_globals')) {
$phpReport[] = [
'severity' => 'error',
'message' => elgg_echo("install:check:php:register_globals")
'message' => elgg_echo('install:check:php:register_globals'),
];
}

if (ini_get('session.auto_start')) {
$phpReport[] = [
'severity' => 'error',
'message' => elgg_echo("install:check:php:session.auto_start")
'message' => elgg_echo('install:check:php:session.auto_start'),
];
}
}
Expand All @@ -1101,8 +1097,8 @@ protected function checkRewriteRules(&$report) {
$tester = new ElggRewriteTester();
$url = $app->internal_services->config->wwwroot;
$url .= Request::REWRITE_TEST_TOKEN . '?' . http_build_query([
Request::REWRITE_TEST_TOKEN => '1',
]);
Request::REWRITE_TEST_TOKEN => '1',
]);
$report['rewrite'] = [$tester->run($url)];
}

Expand Down Expand Up @@ -1146,7 +1142,7 @@ protected function validateDatabaseVars($submissionVars, $formVars) {

foreach ($formVars as $field => $info) {
if ($info['required'] == true && !$submissionVars[$field]) {
$name = elgg_echo("install:database:label:$field");
$name = elgg_echo("install:database:label:{$field}");
$app->internal_services->system_messages->addErrorMessage(elgg_echo('install:error:requiredfield', [$name]));

return false;
Expand All @@ -1162,40 +1158,35 @@ protected function validateDatabaseVars($submissionVars, $formVars) {
// check that data root is absolute path
if (stripos(PHP_OS, 'win') === 0) {
if (strpos($submissionVars['dataroot'], ':') !== 1) {
$msg = elgg_echo('install:error:relative_path', [$submissionVars['dataroot']]);
$app->internal_services->system_messages->addErrorMessage($msg);
$app->internal_services->system_messages->addErrorMessage(elgg_echo('install:error:relative_path', [$submissionVars['dataroot']]));

return false;
}
} else {
if (strpos($submissionVars['dataroot'], '/') !== 0) {
$msg = elgg_echo('install:error:relative_path', [$submissionVars['dataroot']]);
$app->internal_services->system_messages->addErrorMessage($msg);
$app->internal_services->system_messages->addErrorMessage(elgg_echo('install:error:relative_path', [$submissionVars['dataroot']]));

return false;
}
}

// check that data root exists
if (!is_dir($submissionVars['dataroot'])) {
$msg = elgg_echo('install:error:datadirectoryexists', [$submissionVars['dataroot']]);
$app->internal_services->system_messages->addErrorMessage($msg);
$app->internal_services->system_messages->addErrorMessage(elgg_echo('install:error:datadirectoryexists', [$submissionVars['dataroot']]));

return false;
}

// check that data root is writable
if (!is_writable($submissionVars['dataroot'])) {
$msg = elgg_echo('install:error:writedatadirectory', [$submissionVars['dataroot']]);
$app->internal_services->system_messages->addErrorMessage($msg);
$app->internal_services->system_messages->addErrorMessage(elgg_echo('install:error:writedatadirectory', [$submissionVars['dataroot']]));

return false;
}

// check that data root is not subdirectory of Elgg root
if (stripos($submissionVars['dataroot'], Paths::project()) === 0) {
$msg = elgg_echo('install:error:locationdatadirectory', [$submissionVars['dataroot']]);
$app->internal_services->system_messages->addErrorMessage($msg);
$app->internal_services->system_messages->addErrorMessage(elgg_echo('install:error:locationdatadirectory', [$submissionVars['dataroot']]));

return false;
}
Expand Down Expand Up @@ -1279,7 +1270,7 @@ protected function checkDatabaseSettings($user, $password, $dbname, $host, $port
protected function createSettingsFile($params) {
$app = $this->getApp();

$template = Application::elggDir()->getContents("elgg-config/settings.example.php");
$template = Application::elggDir()->getContents('elgg-config/settings.example.php');
if (!$template) {
$app->internal_services->system_messages->addErrorMessage(elgg_echo('install:error:readsettingsphp'));

Expand Down Expand Up @@ -1381,7 +1372,7 @@ protected function createDataDirectory(&$submissionVars, $formVars) {
$dir = \Elgg\Project\Paths::sanitize($submissionVars['path']) . 'data';
if (file_exists($dir) || mkdir($dir, 0755)) {
$submissionVars['dataroot'] = $dir;
if (!file_exists("$dir/.htaccess")) {
if (!file_exists("{$dir}/.htaccess")) {
$htaccess = "Order Deny,Allow\nDeny from All\n";
if (!file_put_contents("$dir/.htaccess", $htaccess)) {
return false;
Expand All @@ -1408,7 +1399,7 @@ protected function validateSettingsVars($submissionVars, $formVars) {
foreach ($formVars as $field => $info) {
$submissionVars[$field] = trim($submissionVars[$field]);
if ($info['required'] == true && $submissionVars[$field] === '') {
$name = elgg_echo("install:settings:label:$field");
$name = elgg_echo("install:settings:label:{$field}");
$app->internal_services->system_messages->addErrorMessage(elgg_echo('install:error:requiredfield', [$name]));

return false;
Expand All @@ -1417,8 +1408,7 @@ protected function validateSettingsVars($submissionVars, $formVars) {

// check that email address is email address
if ($submissionVars['siteemail'] && !elgg_is_valid_email((string) $submissionVars['siteemail'])) {
$msg = elgg_echo('install:error:emailaddress', [$submissionVars['siteemail']]);
$app->internal_services->system_messages->addErrorMessage($msg);
$app->internal_services->system_messages->addErrorMessage(elgg_echo('install:error:emailaddress', [$submissionVars['siteemail']]));

return false;
}
Expand All @@ -1439,7 +1429,7 @@ protected function saveSiteSettings($submissionVars) {
$site = elgg_get_site_entity();

if (!$site->guid) {
$site = new ElggSite();
$site = new \ElggSite();
$site->name = strip_tags($submissionVars['sitename']);
$site->access_id = ACCESS_PUBLIC;
$site->email = $submissionVars['siteemail'];
Expand Down Expand Up @@ -1500,7 +1490,7 @@ protected function saveSiteSettings($submissionVars) {
foreach ($upgrades as $upgrade) {
$upgrade->setCompleted();
}
} catch (Exception $e) {
} catch (\Exception $e) {
$app->internal_services->logger->log(\Psr\Log\LogLevel::ERROR, $e);
}

Expand All @@ -1521,7 +1511,7 @@ protected function validateAdminVars($submissionVars, $formVars) {

foreach ($formVars as $field => $info) {
if ($info['required'] == true && !$submissionVars[$field]) {
$name = elgg_echo("install:admin:label:$field");
$name = elgg_echo("install:admin:label:{$field}");
$app->internal_services->system_messages->addErrorMessage(elgg_echo('install:error:requiredfield', [$name]));

return false;
Expand Down Expand Up @@ -1549,8 +1539,7 @@ protected function validateAdminVars($submissionVars, $formVars) {

// check that email address is email address
if ($submissionVars['email'] && !elgg_is_valid_email((string) $submissionVars['email'])) {
$msg = elgg_echo('install:error:emailaddress', [$submissionVars['email']]);
$app->internal_services->system_messages->addErrorMessage($msg);
$app->internal_services->system_messages->addErrorMessage(elgg_echo('install:error:emailaddress', [$submissionVars['email']]));

return false;
}
Expand Down

0 comments on commit 3dc2c7b

Please sign in to comment.