mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Update installer to not use global databaseConfig
This commit is contained in:
parent
f9b2ba4755
commit
5c90d53a84
@ -16,7 +16,15 @@ use SilverStripe\Core\TempFolder;
|
||||
*/
|
||||
class InstallRequirements
|
||||
{
|
||||
var $errors, $warnings, $tests;
|
||||
protected $errors = [];
|
||||
protected $warnings = [];
|
||||
protected $tests = [];
|
||||
|
||||
/**
|
||||
* Backup of original ini settings
|
||||
* @var array
|
||||
*/
|
||||
protected $originalIni = [];
|
||||
|
||||
/**
|
||||
* Check the database configuration. These are done one after another
|
||||
@ -172,7 +180,7 @@ class InstallRequirements
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$this->errors = null;
|
||||
$this->errors = [];
|
||||
$isApache = $this->isApache();
|
||||
$isIIS = $this->isIIS();
|
||||
$webserver = $this->findWebserver();
|
||||
@ -376,7 +384,7 @@ class InstallRequirements
|
||||
'PHP Configuration',
|
||||
'date.timezone setting and validity',
|
||||
'date.timezone option in php.ini must be set correctly.',
|
||||
ini_get('date.timezone')
|
||||
$this->getOriginalIni('date.timezone')
|
||||
));
|
||||
|
||||
$this->suggestClass('finfo', array(
|
||||
@ -441,24 +449,33 @@ class InstallRequirements
|
||||
"PHP Configuration",
|
||||
"Memory allocation (PHP config option 'memory_limit')",
|
||||
"SilverStripe needs a minimum of 32M allocated to PHP, but recommends 64M.",
|
||||
ini_get("memory_limit")
|
||||
$this->getOriginalIni("memory_limit")
|
||||
));
|
||||
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ini setting
|
||||
*
|
||||
* @param string $settingName
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getOriginalIni($settingName)
|
||||
{
|
||||
if (isset($this->originalIni[$settingName])) {
|
||||
return $this->originalIni[$settingName];
|
||||
}
|
||||
return ini_get($settingName);
|
||||
}
|
||||
|
||||
public function suggestPHPSetting($settingName, $settingValues, $testDetails)
|
||||
{
|
||||
$this->testing($testDetails);
|
||||
|
||||
// special case for display_errors, check the original value before
|
||||
// it was changed at the start of this script.
|
||||
if ($settingName == 'display_errors') {
|
||||
global $originalDisplayErrorsValue;
|
||||
$val = $originalDisplayErrorsValue;
|
||||
} else {
|
||||
$val = ini_get($settingName);
|
||||
}
|
||||
$val = $this->getOriginalIni($settingName);
|
||||
|
||||
if (!in_array($val, $settingValues) && $val != $settingValues) {
|
||||
$this->warning($testDetails, "$settingName is set to '$val' in php.ini. $testDetails[2]");
|
||||
@ -469,7 +486,7 @@ class InstallRequirements
|
||||
{
|
||||
$this->testing($testDetails);
|
||||
|
||||
$val = ini_get($settingName);
|
||||
$val = $this->getOriginalIni($settingName);
|
||||
if (!in_array($val, $settingValues) && $val != $settingValues) {
|
||||
$this->error($testDetails, "$settingName is set to '$val' in php.ini. $testDetails[2]");
|
||||
}
|
||||
@ -496,8 +513,8 @@ class InstallRequirements
|
||||
public function requireDateTimezone($testDetails)
|
||||
{
|
||||
$this->testing($testDetails);
|
||||
|
||||
$result = ini_get('date.timezone') && in_array(ini_get('date.timezone'), timezone_identifiers_list());
|
||||
$val = $this->getOriginalIni('date.timezone');
|
||||
$result = $val && in_array($val, timezone_identifiers_list());
|
||||
if (!$result) {
|
||||
$this->error($testDetails);
|
||||
}
|
||||
@ -508,20 +525,21 @@ class InstallRequirements
|
||||
$_SESSION['forcemem'] = false;
|
||||
|
||||
$mem = $this->getPHPMemory();
|
||||
$memLimit = $this->getOriginalIni("memory_limit");
|
||||
if ($mem < (64 * 1024 * 1024)) {
|
||||
ini_set('memory_limit', '64M');
|
||||
$mem = $this->getPHPMemory();
|
||||
$testDetails[3] = ini_get("memory_limit");
|
||||
$testDetails[3] = $memLimit;
|
||||
}
|
||||
|
||||
$this->testing($testDetails);
|
||||
|
||||
if ($mem < $min && $mem > 0) {
|
||||
$message = $testDetails[2] . " You only have " . ini_get("memory_limit") . " allocated";
|
||||
$message = $testDetails[2] . " You only have " . $memLimit . " allocated";
|
||||
$this->error($testDetails, $message);
|
||||
return false;
|
||||
} elseif ($mem < $recommended && $mem > 0) {
|
||||
$message = $testDetails[2] . " You only have " . ini_get("memory_limit") . " allocated";
|
||||
$message = $testDetails[2] . " You only have " . $memLimit . " allocated";
|
||||
$this->warning($testDetails, $message);
|
||||
return false;
|
||||
} elseif ($mem == 0) {
|
||||
@ -535,7 +553,7 @@ class InstallRequirements
|
||||
|
||||
public function getPHPMemory()
|
||||
{
|
||||
$memString = ini_get("memory_limit");
|
||||
$memString = $this->getOriginalIni("memory_limit");
|
||||
|
||||
switch (strtolower(substr($memString, -1))) {
|
||||
case "k":
|
||||
|
@ -13,6 +13,10 @@ use SilverStripe\ORM\DatabaseAdmin;
|
||||
use SilverStripe\Security\DefaultAdminService;
|
||||
use SilverStripe\Security\Security;
|
||||
|
||||
/**
|
||||
* SilverStripe CMS SilverStripe\Dev\Install\Installer
|
||||
* This installer doesn't use any of the fancy SilverStripe stuff in case it's unsupported.
|
||||
*/
|
||||
class Installer extends InstallRequirements
|
||||
{
|
||||
public function __construct()
|
||||
@ -126,39 +130,25 @@ class Installer extends InstallRequirements
|
||||
global $usingEnv;
|
||||
if ($usingEnv) {
|
||||
$this->statusMessage("Setting up 'mysite/_config.php' for use with environment variables...");
|
||||
$this->writeToFile("mysite/_config.php", <<<PHP
|
||||
<?php
|
||||
|
||||
global \$project;
|
||||
\$project = 'mysite';
|
||||
|
||||
global \$database;
|
||||
\$database = '{$dbConfig['database']}';
|
||||
|
||||
require_once('conf/ConfigureFromEnv.php');
|
||||
|
||||
PHP
|
||||
);
|
||||
$this->writeToFile("mysite/_config.php", "<?php\n ");
|
||||
} else {
|
||||
$this->statusMessage("Setting up 'mysite/_config.php'...");
|
||||
// Create databaseConfig
|
||||
$lines = array(
|
||||
$lines[] = "\t'type' => '$type'"
|
||||
$lines[] = " 'type' => '$type'"
|
||||
);
|
||||
foreach ($dbConfig as $key => $value) {
|
||||
$lines[] = "\t'{$key}' => '$value'";
|
||||
$lines[] = " '{$key}' => '$value'";
|
||||
}
|
||||
$databaseConfigContent = implode(",\n", $lines);
|
||||
$this->writeToFile("mysite/_config.php", <<<PHP
|
||||
<?php
|
||||
|
||||
global \$project;
|
||||
\$project = 'mysite';
|
||||
use SilverStripe\\ORM\\DB;
|
||||
|
||||
global \$databaseConfig;
|
||||
\$databaseConfig = array(
|
||||
DB::setConfig([
|
||||
{$databaseConfigContent}
|
||||
);
|
||||
]);
|
||||
|
||||
PHP
|
||||
);
|
||||
|
BIN
src/Dev/Install/client/images/logo.gif
Normal file
BIN
src/Dev/Install/client/images/logo.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
@ -6,7 +6,7 @@
|
||||
<head>
|
||||
<title>SilverStripe CMS / Framework Installation</title>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||
<script type="application/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
|
||||
<script type="application/javascript" src="//code.jquery.com/jquery-1.7.2.min.js"></script>
|
||||
<script type="application/javascript" src="<?=FRAMEWORK_NAME; ?>/src/Dev/Install/client/js/install.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="<?=FRAMEWORK_NAME; ?>/src/Dev/Install/client/styles/install.css">
|
||||
<link rel="shortcut icon" href="favicon.ico">
|
||||
@ -29,13 +29,13 @@
|
||||
<div id="Layout">
|
||||
<div class="typography">
|
||||
<form action="install.php" method="post">
|
||||
<?php if(isset($hasErrorOtherThanDatabase)): ?>
|
||||
<?php if($hasErrorOtherThanDatabase): ?>
|
||||
<p class="message error">
|
||||
You aren't currently able to install the software. Please <a href="#requirements">see below</a> for details.<br>
|
||||
If you are having problems meeting the requirements, see the <a href="http://doc.silverstripe.org/framework/en/installation/server-requirements" target="_blank">server requirements</a>.
|
||||
</p>
|
||||
<?php if (isset($phpIniLocation)): ?>
|
||||
<p>Your php.ini file is located at <?=$phpIniLocation; ?></p>
|
||||
<?php if ($phpIniLocation): ?>
|
||||
<p class="message warning">Your php.ini file is located at <?=$phpIniLocation; ?></p>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<?php if($alreadyInstalled): ?>
|
||||
@ -252,7 +252,7 @@
|
||||
</ul>
|
||||
<h3 class="sectionHeading" id="install">Confirm Install <small>Step 5 of 5</small></h3>
|
||||
|
||||
<?php if(isset($hasErrorOtherThanDatabase)): ?>
|
||||
<?php if($hasErrorOtherThanDatabase): ?>
|
||||
<p class="error">
|
||||
You aren't currently able to install the software. Please <a href="#requirements">see above</a> for details.<br>
|
||||
If you are having problems meeting the requirements, see the <a href="http://doc.silverstripe.org/doku.php?id=server-requirements">server requirements page</a>.
|
||||
|
@ -11,20 +11,23 @@
|
||||
|
||||
namespace SilverStripe\Dev\Install;
|
||||
|
||||
/**
|
||||
* SilverStripe CMS SilverStripe\Dev\Install\Installer
|
||||
* This installer doesn't use any of the fancy SilverStripe stuff in case it's unsupported.
|
||||
*/
|
||||
// Back up original ini config
|
||||
$originalIni = [];
|
||||
$iniSet = function ($name, $value) use (&$originalIni) {
|
||||
if (!isset($originalIni[$name])) {
|
||||
$originalIni[$name] = ini_get($name);
|
||||
}
|
||||
ini_set($name, $value);
|
||||
};
|
||||
|
||||
// speed up mysql_connect timeout if the server can't be found
|
||||
ini_set('mysql.connect_timeout', 5);
|
||||
$iniSet('mysql.connect_timeout', 5);
|
||||
// Don't die half was through installation; that does more harm than good
|
||||
ini_set('max_execution_time', 0);
|
||||
$iniSet('max_execution_time', 0);
|
||||
|
||||
// set display_errors php setting to on to force installer to avoid blank screen of death.
|
||||
// get the original value so it can be used in PHP requirement checks later in this script.
|
||||
$originalDisplayErrorsValue = ini_get('display_errors');
|
||||
ini_set('display_errors', '1');
|
||||
$iniSet('display_errors', '1');
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
|
||||
@ -201,19 +204,22 @@ if (file_exists(FRAMEWORK_NAME . '/silverstripe_version')) {
|
||||
}
|
||||
|
||||
// Check requirements
|
||||
$req = new InstallRequirements();
|
||||
$req = new InstallRequirements($originalIni);
|
||||
$req->check();
|
||||
|
||||
$webserverConfigFile = '';
|
||||
if ($req->isIIS()) {
|
||||
$webserverConfigFile = 'web.config';
|
||||
} else {
|
||||
$webserverConfigFile = '.htaccess';
|
||||
}
|
||||
|
||||
$hasErrorOtherThanDatabase = false;
|
||||
$hasOnlyWarnings = false;
|
||||
$phpIniLocation = php_ini_loaded_file();
|
||||
if ($req->hasErrors()) {
|
||||
$hasErrorOtherThanDatabase = true;
|
||||
$phpIniLocation = php_ini_loaded_file();
|
||||
} elseif ($req->hasWarnings()) {
|
||||
$hasOnlyWarnings = true;
|
||||
}
|
||||
|
||||
$dbReq = new InstallRequirements();
|
||||
@ -237,6 +243,17 @@ if ($installFromCli && ($req->hasErrors() || $dbReq->hasErrors())) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// config-form.html vars (placeholder to prevent deletion)
|
||||
[
|
||||
$defaultLocale,
|
||||
$silverstripe_version,
|
||||
$locales,
|
||||
$webserverConfigFile,
|
||||
$hasErrorOtherThanDatabase,
|
||||
$hasOnlyWarnings, // If warnings but not errors
|
||||
$phpIniLocation
|
||||
];
|
||||
|
||||
if ((isset($_REQUEST['go']) || $installFromCli)
|
||||
&& !$req->hasErrors()
|
||||
&& !$dbReq->hasErrors()
|
||||
@ -262,4 +279,3 @@ if ((isset($_REQUEST['go']) || $installFromCli)
|
||||
} else {
|
||||
include(__DIR__ . '/config-form.html');
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user