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
|
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
|
* Check the database configuration. These are done one after another
|
||||||
@ -172,7 +180,7 @@ class InstallRequirements
|
|||||||
*/
|
*/
|
||||||
public function check()
|
public function check()
|
||||||
{
|
{
|
||||||
$this->errors = null;
|
$this->errors = [];
|
||||||
$isApache = $this->isApache();
|
$isApache = $this->isApache();
|
||||||
$isIIS = $this->isIIS();
|
$isIIS = $this->isIIS();
|
||||||
$webserver = $this->findWebserver();
|
$webserver = $this->findWebserver();
|
||||||
@ -376,7 +384,7 @@ class InstallRequirements
|
|||||||
'PHP Configuration',
|
'PHP Configuration',
|
||||||
'date.timezone setting and validity',
|
'date.timezone setting and validity',
|
||||||
'date.timezone option in php.ini must be set correctly.',
|
'date.timezone option in php.ini must be set correctly.',
|
||||||
ini_get('date.timezone')
|
$this->getOriginalIni('date.timezone')
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->suggestClass('finfo', array(
|
$this->suggestClass('finfo', array(
|
||||||
@ -441,24 +449,33 @@ class InstallRequirements
|
|||||||
"PHP Configuration",
|
"PHP Configuration",
|
||||||
"Memory allocation (PHP config option 'memory_limit')",
|
"Memory allocation (PHP config option 'memory_limit')",
|
||||||
"SilverStripe needs a minimum of 32M allocated to PHP, but recommends 64M.",
|
"SilverStripe needs a minimum of 32M allocated to PHP, but recommends 64M.",
|
||||||
ini_get("memory_limit")
|
$this->getOriginalIni("memory_limit")
|
||||||
));
|
));
|
||||||
|
|
||||||
return $this->errors;
|
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)
|
public function suggestPHPSetting($settingName, $settingValues, $testDetails)
|
||||||
{
|
{
|
||||||
$this->testing($testDetails);
|
$this->testing($testDetails);
|
||||||
|
|
||||||
// special case for display_errors, check the original value before
|
// special case for display_errors, check the original value before
|
||||||
// it was changed at the start of this script.
|
// it was changed at the start of this script.
|
||||||
if ($settingName == 'display_errors') {
|
$val = $this->getOriginalIni($settingName);
|
||||||
global $originalDisplayErrorsValue;
|
|
||||||
$val = $originalDisplayErrorsValue;
|
|
||||||
} else {
|
|
||||||
$val = ini_get($settingName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array($val, $settingValues) && $val != $settingValues) {
|
if (!in_array($val, $settingValues) && $val != $settingValues) {
|
||||||
$this->warning($testDetails, "$settingName is set to '$val' in php.ini. $testDetails[2]");
|
$this->warning($testDetails, "$settingName is set to '$val' in php.ini. $testDetails[2]");
|
||||||
@ -469,7 +486,7 @@ class InstallRequirements
|
|||||||
{
|
{
|
||||||
$this->testing($testDetails);
|
$this->testing($testDetails);
|
||||||
|
|
||||||
$val = ini_get($settingName);
|
$val = $this->getOriginalIni($settingName);
|
||||||
if (!in_array($val, $settingValues) && $val != $settingValues) {
|
if (!in_array($val, $settingValues) && $val != $settingValues) {
|
||||||
$this->error($testDetails, "$settingName is set to '$val' in php.ini. $testDetails[2]");
|
$this->error($testDetails, "$settingName is set to '$val' in php.ini. $testDetails[2]");
|
||||||
}
|
}
|
||||||
@ -496,8 +513,8 @@ class InstallRequirements
|
|||||||
public function requireDateTimezone($testDetails)
|
public function requireDateTimezone($testDetails)
|
||||||
{
|
{
|
||||||
$this->testing($testDetails);
|
$this->testing($testDetails);
|
||||||
|
$val = $this->getOriginalIni('date.timezone');
|
||||||
$result = ini_get('date.timezone') && in_array(ini_get('date.timezone'), timezone_identifiers_list());
|
$result = $val && in_array($val, timezone_identifiers_list());
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
$this->error($testDetails);
|
$this->error($testDetails);
|
||||||
}
|
}
|
||||||
@ -508,20 +525,21 @@ class InstallRequirements
|
|||||||
$_SESSION['forcemem'] = false;
|
$_SESSION['forcemem'] = false;
|
||||||
|
|
||||||
$mem = $this->getPHPMemory();
|
$mem = $this->getPHPMemory();
|
||||||
|
$memLimit = $this->getOriginalIni("memory_limit");
|
||||||
if ($mem < (64 * 1024 * 1024)) {
|
if ($mem < (64 * 1024 * 1024)) {
|
||||||
ini_set('memory_limit', '64M');
|
ini_set('memory_limit', '64M');
|
||||||
$mem = $this->getPHPMemory();
|
$mem = $this->getPHPMemory();
|
||||||
$testDetails[3] = ini_get("memory_limit");
|
$testDetails[3] = $memLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->testing($testDetails);
|
$this->testing($testDetails);
|
||||||
|
|
||||||
if ($mem < $min && $mem > 0) {
|
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);
|
$this->error($testDetails, $message);
|
||||||
return false;
|
return false;
|
||||||
} elseif ($mem < $recommended && $mem > 0) {
|
} 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);
|
$this->warning($testDetails, $message);
|
||||||
return false;
|
return false;
|
||||||
} elseif ($mem == 0) {
|
} elseif ($mem == 0) {
|
||||||
@ -535,7 +553,7 @@ class InstallRequirements
|
|||||||
|
|
||||||
public function getPHPMemory()
|
public function getPHPMemory()
|
||||||
{
|
{
|
||||||
$memString = ini_get("memory_limit");
|
$memString = $this->getOriginalIni("memory_limit");
|
||||||
|
|
||||||
switch (strtolower(substr($memString, -1))) {
|
switch (strtolower(substr($memString, -1))) {
|
||||||
case "k":
|
case "k":
|
||||||
|
@ -13,6 +13,10 @@ use SilverStripe\ORM\DatabaseAdmin;
|
|||||||
use SilverStripe\Security\DefaultAdminService;
|
use SilverStripe\Security\DefaultAdminService;
|
||||||
use SilverStripe\Security\Security;
|
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
|
class Installer extends InstallRequirements
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
@ -126,39 +130,25 @@ class Installer extends InstallRequirements
|
|||||||
global $usingEnv;
|
global $usingEnv;
|
||||||
if ($usingEnv) {
|
if ($usingEnv) {
|
||||||
$this->statusMessage("Setting up 'mysite/_config.php' for use with environment variables...");
|
$this->statusMessage("Setting up 'mysite/_config.php' for use with environment variables...");
|
||||||
$this->writeToFile("mysite/_config.php", <<<PHP
|
$this->writeToFile("mysite/_config.php", "<?php\n ");
|
||||||
<?php
|
|
||||||
|
|
||||||
global \$project;
|
|
||||||
\$project = 'mysite';
|
|
||||||
|
|
||||||
global \$database;
|
|
||||||
\$database = '{$dbConfig['database']}';
|
|
||||||
|
|
||||||
require_once('conf/ConfigureFromEnv.php');
|
|
||||||
|
|
||||||
PHP
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
$this->statusMessage("Setting up 'mysite/_config.php'...");
|
$this->statusMessage("Setting up 'mysite/_config.php'...");
|
||||||
// Create databaseConfig
|
// Create databaseConfig
|
||||||
$lines = array(
|
$lines = array(
|
||||||
$lines[] = "\t'type' => '$type'"
|
$lines[] = " 'type' => '$type'"
|
||||||
);
|
);
|
||||||
foreach ($dbConfig as $key => $value) {
|
foreach ($dbConfig as $key => $value) {
|
||||||
$lines[] = "\t'{$key}' => '$value'";
|
$lines[] = " '{$key}' => '$value'";
|
||||||
}
|
}
|
||||||
$databaseConfigContent = implode(",\n", $lines);
|
$databaseConfigContent = implode(",\n", $lines);
|
||||||
$this->writeToFile("mysite/_config.php", <<<PHP
|
$this->writeToFile("mysite/_config.php", <<<PHP
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
global \$project;
|
use SilverStripe\\ORM\\DB;
|
||||||
\$project = 'mysite';
|
|
||||||
|
|
||||||
global \$databaseConfig;
|
DB::setConfig([
|
||||||
\$databaseConfig = array(
|
|
||||||
{$databaseConfigContent}
|
{$databaseConfigContent}
|
||||||
);
|
]);
|
||||||
|
|
||||||
PHP
|
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>
|
<head>
|
||||||
<title>SilverStripe CMS / Framework Installation</title>
|
<title>SilverStripe CMS / Framework Installation</title>
|
||||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
<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>
|
<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="stylesheet" type="text/css" href="<?=FRAMEWORK_NAME; ?>/src/Dev/Install/client/styles/install.css">
|
||||||
<link rel="shortcut icon" href="favicon.ico">
|
<link rel="shortcut icon" href="favicon.ico">
|
||||||
@ -29,13 +29,13 @@
|
|||||||
<div id="Layout">
|
<div id="Layout">
|
||||||
<div class="typography">
|
<div class="typography">
|
||||||
<form action="install.php" method="post">
|
<form action="install.php" method="post">
|
||||||
<?php if(isset($hasErrorOtherThanDatabase)): ?>
|
<?php if($hasErrorOtherThanDatabase): ?>
|
||||||
<p class="message error">
|
<p class="message error">
|
||||||
You aren't currently able to install the software. Please <a href="#requirements">see below</a> for details.<br>
|
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>.
|
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>
|
</p>
|
||||||
<?php if (isset($phpIniLocation)): ?>
|
<?php if ($phpIniLocation): ?>
|
||||||
<p>Your php.ini file is located at <?=$phpIniLocation; ?></p>
|
<p class="message warning">Your php.ini file is located at <?=$phpIniLocation; ?></p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<?php if($alreadyInstalled): ?>
|
<?php if($alreadyInstalled): ?>
|
||||||
@ -252,7 +252,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<h3 class="sectionHeading" id="install">Confirm Install <small>Step 5 of 5</small></h3>
|
<h3 class="sectionHeading" id="install">Confirm Install <small>Step 5 of 5</small></h3>
|
||||||
|
|
||||||
<?php if(isset($hasErrorOtherThanDatabase)): ?>
|
<?php if($hasErrorOtherThanDatabase): ?>
|
||||||
<p class="error">
|
<p class="error">
|
||||||
You aren't currently able to install the software. Please <a href="#requirements">see above</a> for details.<br>
|
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>.
|
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;
|
namespace SilverStripe\Dev\Install;
|
||||||
|
|
||||||
/**
|
// Back up original ini config
|
||||||
* SilverStripe CMS SilverStripe\Dev\Install\Installer
|
$originalIni = [];
|
||||||
* This installer doesn't use any of the fancy SilverStripe stuff in case it's unsupported.
|
$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
|
// 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
|
// 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.
|
// 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.
|
// get the original value so it can be used in PHP requirement checks later in this script.
|
||||||
$originalDisplayErrorsValue = ini_get('display_errors');
|
$iniSet('display_errors', '1');
|
||||||
ini_set('display_errors', '1');
|
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT);
|
error_reporting(E_ALL | E_STRICT);
|
||||||
|
|
||||||
@ -201,19 +204,22 @@ if (file_exists(FRAMEWORK_NAME . '/silverstripe_version')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check requirements
|
// Check requirements
|
||||||
$req = new InstallRequirements();
|
$req = new InstallRequirements($originalIni);
|
||||||
$req->check();
|
$req->check();
|
||||||
|
|
||||||
$webserverConfigFile = '';
|
|
||||||
if ($req->isIIS()) {
|
if ($req->isIIS()) {
|
||||||
$webserverConfigFile = 'web.config';
|
$webserverConfigFile = 'web.config';
|
||||||
} else {
|
} else {
|
||||||
$webserverConfigFile = '.htaccess';
|
$webserverConfigFile = '.htaccess';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$hasErrorOtherThanDatabase = false;
|
||||||
|
$hasOnlyWarnings = false;
|
||||||
|
$phpIniLocation = php_ini_loaded_file();
|
||||||
if ($req->hasErrors()) {
|
if ($req->hasErrors()) {
|
||||||
$hasErrorOtherThanDatabase = true;
|
$hasErrorOtherThanDatabase = true;
|
||||||
$phpIniLocation = php_ini_loaded_file();
|
} elseif ($req->hasWarnings()) {
|
||||||
|
$hasOnlyWarnings = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbReq = new InstallRequirements();
|
$dbReq = new InstallRequirements();
|
||||||
@ -237,6 +243,17 @@ if ($installFromCli && ($req->hasErrors() || $dbReq->hasErrors())) {
|
|||||||
exit(1);
|
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)
|
if ((isset($_REQUEST['go']) || $installFromCli)
|
||||||
&& !$req->hasErrors()
|
&& !$req->hasErrors()
|
||||||
&& !$dbReq->hasErrors()
|
&& !$dbReq->hasErrors()
|
||||||
@ -262,4 +279,3 @@ if ((isset($_REQUEST['go']) || $installFromCli)
|
|||||||
} else {
|
} else {
|
||||||
include(__DIR__ . '/config-form.html');
|
include(__DIR__ . '/config-form.html');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user