formatted install.php5 according to SilverStripe coding conventions (tabs instead of spaces, no 1 line if with else, ...)

This commit is contained in:
zauberfisch 2013-10-16 21:11:06 +01:00
parent c4810b8e0f
commit 0b4c3946ff

View File

@ -51,34 +51,33 @@ if ($dirsToCheck[0] == $dirsToCheck[1]) {
foreach ($dirsToCheck as $dir) { foreach ($dirsToCheck as $dir) {
//check this dir and every parent dir (until we hit the base of the drive) //check this dir and every parent dir (until we hit the base of the drive)
// or until we hit a dir we can't read // or until we hit a dir we can't read
do { do {
//add the trailing slash we need to concatenate properly //add the trailing slash we need to concatenate properly
$dir .= DIRECTORY_SEPARATOR; $dir .= DIRECTORY_SEPARATOR;
//if it's readable, go ahead //if it's readable, go ahead
if (@is_readable($dir)) { if (@is_readable($dir)) {
//if the file exists, then we include it, set relevant vars and break out //if the file exists, then we include it, set relevant vars and break out
if (file_exists($dir . $envFile)) { if (file_exists($dir . $envFile)) {
include_once($dir . $envFile); include_once($dir . $envFile);
$envFileExists = true; $envFileExists = true;
//legacy variable assignment //legacy variable assignment
$usingEnv = true; $usingEnv = true;
//break out of BOTH loops because we found the $envFile //break out of BOTH loops because we found the $envFile
break(2); break(2);
} }
} } else {
else {
//break out of the while loop, we can't read the dir //break out of the while loop, we can't read the dir
break; break;
} }
//go up a directory //go up a directory
$dir = dirname($dir); $dir = dirname($dir);
//here we need to check that the path of the last dir and the next one are //here we need to check that the path of the last dir and the next one are
// not the same, if they are, we have hit the root of the drive // not the same, if they are, we have hit the root of the drive
} while (dirname($dir) != $dir); } while (dirname($dir) != $dir);
} }
if($envFileExists) { if ($envFileExists) {
if(!empty($_REQUEST['useEnv'])) { if (!empty($_REQUEST['useEnv'])) {
$usingEnv = true; $usingEnv = true;
} else { } else {
$usingEnv = false; $usingEnv = false;
@ -91,71 +90,71 @@ require_once FRAMEWORK_NAME . '/dev/install/DatabaseAdapterRegistry.php';
// Set default locale, but try and sniff from the user agent // Set default locale, but try and sniff from the user agent
$defaultLocale = 'en_US'; $defaultLocale = 'en_US';
$locales = array( $locales = array(
'af_ZA' => 'Afrikaans (South Africa)', 'af_ZA' => 'Afrikaans (South Africa)',
'ar_EG' => 'Arabic (Egypt)', 'ar_EG' => 'Arabic (Egypt)',
'hy_AM' => 'Armenian (Armenia)', 'hy_AM' => 'Armenian (Armenia)',
'ast_ES' => 'Asturian (Spain)', 'ast_ES' => 'Asturian (Spain)',
'az_AZ' => 'Azerbaijani (Azerbaijan)', 'az_AZ' => 'Azerbaijani (Azerbaijan)',
'bs_BA' => 'Bosnian (Bosnia and Herzegovina)', 'bs_BA' => 'Bosnian (Bosnia and Herzegovina)',
'bg_BG' => 'Bulgarian (Bulgaria)', 'bg_BG' => 'Bulgarian (Bulgaria)',
'ca_ES' => 'Catalan (Spain)', 'ca_ES' => 'Catalan (Spain)',
'zh_CN' => 'Chinese (China)', 'zh_CN' => 'Chinese (China)',
'zh_TW' => 'Chinese (Taiwan)', 'zh_TW' => 'Chinese (Taiwan)',
'hr_HR' => 'Croatian (Croatia)', 'hr_HR' => 'Croatian (Croatia)',
'cs_CZ' => 'Czech (Czech Republic)', 'cs_CZ' => 'Czech (Czech Republic)',
'da_DK' => 'Danish (Denmark)', 'da_DK' => 'Danish (Denmark)',
'nl_NL' => 'Dutch (Netherlands)', 'nl_NL' => 'Dutch (Netherlands)',
'en_GB' => 'English (United Kingdom)', 'en_GB' => 'English (United Kingdom)',
'en_US' => 'English (United States)', 'en_US' => 'English (United States)',
'eo_XX' => 'Esperanto', 'eo_XX' => 'Esperanto',
'et_EE' => 'Estonian (Estonia)', 'et_EE' => 'Estonian (Estonia)',
'fo_FO' => 'Faroese (Faroe Islands)', 'fo_FO' => 'Faroese (Faroe Islands)',
'fi_FI' => 'Finnish (Finland)', 'fi_FI' => 'Finnish (Finland)',
'fr_FR' => 'French (France)', 'fr_FR' => 'French (France)',
'de_DE' => 'German (Germany)', 'de_DE' => 'German (Germany)',
'el_GR' => 'Greek (Greece)', 'el_GR' => 'Greek (Greece)',
'he_IL' => 'Hebrew (Israel)', 'he_IL' => 'Hebrew (Israel)',
'hu_HU' => 'Hungarian (Hungary)', 'hu_HU' => 'Hungarian (Hungary)',
'is_IS' => 'Icelandic (Iceland)', 'is_IS' => 'Icelandic (Iceland)',
'id_ID' => 'Indonesian (Indonesia)', 'id_ID' => 'Indonesian (Indonesia)',
'it_IT' => 'Italian (Italy)', 'it_IT' => 'Italian (Italy)',
'ja_JP' => 'Japanese (Japan)', 'ja_JP' => 'Japanese (Japan)',
'km_KH' => 'Khmer (Cambodia)', 'km_KH' => 'Khmer (Cambodia)',
'lc_XX' => 'LOLCAT', 'lc_XX' => 'LOLCAT',
'lv_LV' => 'Latvian (Latvia)', 'lv_LV' => 'Latvian (Latvia)',
'lt_LT' => 'Lithuanian (Lithuania)', 'lt_LT' => 'Lithuanian (Lithuania)',
'ms_MY' => 'Malay (Malaysia)', 'ms_MY' => 'Malay (Malaysia)',
'mi_NZ' => 'Maori (New Zealand)', 'mi_NZ' => 'Maori (New Zealand)',
'ne_NP' => 'Nepali (Nepal)', 'ne_NP' => 'Nepali (Nepal)',
'nb_NO' => 'Norwegian', 'nb_NO' => 'Norwegian',
'fa_IR' => 'Persian (Iran)', 'fa_IR' => 'Persian (Iran)',
'pl_PL' => 'Polish (Poland)', 'pl_PL' => 'Polish (Poland)',
'pt_BR' => 'Portuguese (Brazil)', 'pt_BR' => 'Portuguese (Brazil)',
'pa_IN' => 'Punjabi (India)', 'pa_IN' => 'Punjabi (India)',
'ro_RO' => 'Romanian (Romania)', 'ro_RO' => 'Romanian (Romania)',
'ru_RU' => 'Russian (Russia)', 'ru_RU' => 'Russian (Russia)',
'sr_RS' => 'Serbian (Serbia)', 'sr_RS' => 'Serbian (Serbia)',
'si_LK' => 'Sinhalese (Sri Lanka)', 'si_LK' => 'Sinhalese (Sri Lanka)',
'sk_SK' => 'Slovak (Slovakia)', 'sk_SK' => 'Slovak (Slovakia)',
'sl_SI' => 'Slovenian (Slovenia)', 'sl_SI' => 'Slovenian (Slovenia)',
'es_AR' => 'Spanish (Argentina)', 'es_AR' => 'Spanish (Argentina)',
'es_MX' => 'Spanish (Mexico)', 'es_MX' => 'Spanish (Mexico)',
'es_ES' => 'Spanish (Spain)', 'es_ES' => 'Spanish (Spain)',
'sv_SE' => 'Swedish (Sweden)', 'sv_SE' => 'Swedish (Sweden)',
'th_TH' => 'Thai (Thailand)', 'th_TH' => 'Thai (Thailand)',
'tr_TR' => 'Turkish (Turkey)', 'tr_TR' => 'Turkish (Turkey)',
'uk_UA' => 'Ukrainian (Ukraine)', 'uk_UA' => 'Ukrainian (Ukraine)',
'uz_UZ' => 'Uzbek (Uzbekistan)', 'uz_UZ' => 'Uzbek (Uzbekistan)',
'vi_VN' => 'Vietnamese (Vietnam)', 'vi_VN' => 'Vietnamese (Vietnam)',
); );
// Discover which databases are available // Discover which databases are available
DatabaseAdapterRegistry::autodiscover(); DatabaseAdapterRegistry::autodiscover();
// Determine which external database modules are USABLE // Determine which external database modules are USABLE
foreach(DatabaseAdapterRegistry::get_adapters() as $class => $details) { foreach (DatabaseAdapterRegistry::get_adapters() as $class => $details) {
$databaseClasses[$class] = $details; $databaseClasses[$class] = $details;
if(file_exists($details['helperPath'])) { if (file_exists($details['helperPath'])) {
$databaseClasses[$class]['hasModule'] = true; $databaseClasses[$class]['hasModule'] = true;
include_once($details['helperPath']); include_once($details['helperPath']);
} else { } else {
@ -164,12 +163,12 @@ foreach(DatabaseAdapterRegistry::get_adapters() as $class => $details) {
} }
// Load database config // Load database config
if(isset($_REQUEST['db'])) { if (isset($_REQUEST['db'])) {
if(isset($_REQUEST['db']['type'])) $type = $_REQUEST['db']['type']; if (isset($_REQUEST['db']['type'])) $type = $_REQUEST['db']['type'];
else $type = $_REQUEST['db']['type'] = defined('SS_DATABASE_CLASS') ? SS_DATABASE_CLASS : 'MySQLDatabase'; else $type = $_REQUEST['db']['type'] = defined('SS_DATABASE_CLASS') ? SS_DATABASE_CLASS : 'MySQLDatabase';
// Disabled inputs don't submit anything - we need to use the environment (except the database name) // Disabled inputs don't submit anything - we need to use the environment (except the database name)
if($usingEnv) { if ($usingEnv) {
$_REQUEST['db'][$type] = $databaseConfig = array( $_REQUEST['db'][$type] = $databaseConfig = array(
"type" => defined('SS_DATABASE_CLASS') ? SS_DATABASE_CLASS : $type, "type" => defined('SS_DATABASE_CLASS') ? SS_DATABASE_CLASS : $type,
"server" => defined('SS_DATABASE_SERVER') ? SS_DATABASE_SERVER : "localhost", "server" => defined('SS_DATABASE_SERVER') ? SS_DATABASE_SERVER : "localhost",
@ -194,9 +193,9 @@ if(isset($_REQUEST['db'])) {
); );
} }
if(isset($_REQUEST['admin'])) { if (isset($_REQUEST['admin'])) {
// Disabled inputs don't submit anything - we need to use the environment (except the database name) // Disabled inputs don't submit anything - we need to use the environment (except the database name)
if($usingEnv) { if ($usingEnv) {
$_REQUEST['admin'] = $adminConfig = array( $_REQUEST['admin'] = $adminConfig = array(
'username' => defined('SS_DEFAULT_ADMIN_USERNAME') ? SS_DEFAULT_ADMIN_USERNAME : 'admin', 'username' => defined('SS_DEFAULT_ADMIN_USERNAME') ? SS_DEFAULT_ADMIN_USERNAME : 'admin',
'password' => defined('SS_DEFAULT_ADMIN_PASSWORD') ? SS_DEFAULT_ADMIN_PASSWORD : '', 'password' => defined('SS_DEFAULT_ADMIN_PASSWORD') ? SS_DEFAULT_ADMIN_PASSWORD : '',
@ -212,19 +211,19 @@ if(isset($_REQUEST['admin'])) {
} }
$alreadyInstalled = false; $alreadyInstalled = false;
if(file_exists('mysite/_config.php')) { if (file_exists('mysite/_config.php')) {
// Find the $database variable in the relevant config file without having to execute the config file // Find the $database variable in the relevant config file without having to execute the config file
if(preg_match("/\\\$database\s*=\s*[^\n\r]+[\n\r]/", file_get_contents("mysite/_config.php"), $parts)) { if (preg_match("/\\\$database\s*=\s*[^\n\r]+[\n\r]/", file_get_contents("mysite/_config.php"), $parts)) {
eval($parts[0]); eval($parts[0]);
if($database) $alreadyInstalled = true; if ($database) $alreadyInstalled = true;
// Assume that if $databaseConfig is defined in mysite/_config.php, then a non-environment-based installation has // Assume that if $databaseConfig is defined in mysite/_config.php, then a non-environment-based installation has
// already gone ahead // already gone ahead
} else if(preg_match("/\\\$databaseConfig\s*=\s*[^\n\r]+[\n\r]/", file_get_contents("mysite/_config.php"), $parts)) { } else if (preg_match("/\\\$databaseConfig\s*=\s*[^\n\r]+[\n\r]/", file_get_contents("mysite/_config.php"), $parts)) {
$alreadyInstalled = true; $alreadyInstalled = true;
} }
} }
if(file_exists(FRAMEWORK_NAME . '/silverstripe_version')) { if (file_exists(FRAMEWORK_NAME . '/silverstripe_version')) {
$silverstripe_version = file_get_contents(FRAMEWORK_NAME . '/silverstripe_version'); $silverstripe_version = file_get_contents(FRAMEWORK_NAME . '/silverstripe_version');
} else { } else {
$silverstripe_version = "unknown"; $silverstripe_version = "unknown";
@ -235,23 +234,23 @@ $req = new InstallRequirements();
$req->check(); $req->check();
$webserverConfigFile = ''; $webserverConfigFile = '';
if($req->isIIS()) { if ($req->isIIS()) {
$webserverConfigFile = 'web.config'; $webserverConfigFile = 'web.config';
} else { } else {
$webserverConfigFile = '.htaccess'; $webserverConfigFile = '.htaccess';
} }
if($req->hasErrors()) { if ($req->hasErrors()) {
$hasErrorOtherThanDatabase = true; $hasErrorOtherThanDatabase = true;
$phpIniLocation = php_ini_loaded_file(); $phpIniLocation = php_ini_loaded_file();
} }
if($databaseConfig) { if ($databaseConfig) {
$dbReq = new InstallRequirements(); $dbReq = new InstallRequirements();
$dbReq->checkDatabase($databaseConfig); $dbReq->checkDatabase($databaseConfig);
} }
if($adminConfig) { if ($adminConfig) {
$adminReq = new InstallRequirements(); $adminReq = new InstallRequirements();
$adminReq->checkAdminConfig($adminConfig); $adminReq->checkAdminConfig($adminConfig);
} }
@ -260,21 +259,21 @@ if($adminConfig) {
$installFromCli = (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'install'); $installFromCli = (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'install');
// CLI-install error message. exit(1) will halt any makefile. // CLI-install error message. exit(1) will halt any makefile.
if($installFromCli && ($req->hasErrors() || $dbReq->hasErrors())) { if ($installFromCli && ($req->hasErrors() || $dbReq->hasErrors())) {
echo "Cannot install due to errors:\n"; echo "Cannot install due to errors:\n";
$req->listErrors(); $req->listErrors();
$dbReq->listErrors(); $dbReq->listErrors();
exit(1); exit(1);
} }
if((isset($_REQUEST['go']) || $installFromCli) && !$req->hasErrors() && !$dbReq->hasErrors() && $adminConfig['username'] && $adminConfig['password']) { if ((isset($_REQUEST['go']) || $installFromCli) && !$req->hasErrors() && !$dbReq->hasErrors() && $adminConfig['username'] && $adminConfig['password']) {
// Confirm before reinstalling // Confirm before reinstalling
if(!$installFromCli && $alreadyInstalled) { if (!$installFromCli && $alreadyInstalled) {
include(FRAMEWORK_NAME . '/dev/install/config-form.html'); include(FRAMEWORK_NAME . '/dev/install/config-form.html');
} else { } else {
$inst = new Installer(); $inst = new Installer();
if($_REQUEST) $inst->install($_REQUEST); if ($_REQUEST) $inst->install($_REQUEST);
else $inst->install(array( else $inst->install(array(
'db' => $databaseConfig, 'db' => $databaseConfig,
'admin' => $adminConfig, 'admin' => $adminConfig,
@ -303,7 +302,7 @@ class InstallRequirements {
* continuing onto more difficult checks like database permissions. * continuing onto more difficult checks like database permissions.
*/ */
function checkDatabase($databaseConfig) { function checkDatabase($databaseConfig) {
if($this->requireDatabaseFunctions( if ($this->requireDatabaseFunctions(
$databaseConfig, $databaseConfig,
array( array(
"Database Configuration", "Database Configuration",
@ -312,7 +311,7 @@ class InstallRequirements {
$this->getDatabaseTypeNice($databaseConfig['type']) $this->getDatabaseTypeNice($databaseConfig['type'])
) )
)) { )) {
if($this->requireDatabaseServer( if ($this->requireDatabaseServer(
$databaseConfig, $databaseConfig,
array( array(
"Database Configuration", "Database Configuration",
@ -321,7 +320,7 @@ class InstallRequirements {
$databaseConfig['type'] == 'SQLiteDatabase' ? $databaseConfig['path'] : $databaseConfig['server'] $databaseConfig['type'] == 'SQLiteDatabase' ? $databaseConfig['path'] : $databaseConfig['server']
) )
)) { )) {
if($this->requireDatabaseConnection( if ($this->requireDatabaseConnection(
$databaseConfig, $databaseConfig,
array( array(
"Database Configuration", "Database Configuration",
@ -329,7 +328,7 @@ class InstallRequirements {
"That username/password doesn't work" "That username/password doesn't work"
) )
)) { )) {
if($this->requireDatabaseVersion( if ($this->requireDatabaseVersion(
$databaseConfig, $databaseConfig,
array( array(
"Database Configuration", "Database Configuration",
@ -353,10 +352,10 @@ class InstallRequirements {
} }
function checkAdminConfig($adminConfig) { function checkAdminConfig($adminConfig) {
if(!$adminConfig['username']) { if (!$adminConfig['username']) {
$this->error(array('', 'Please enter a username!')); $this->error(array('', 'Please enter a username!'));
} }
if(!$adminConfig['password']) { if (!$adminConfig['password']) {
$this->error(array('', 'Please enter a password!')); $this->error(array('', 'Please enter a password!'));
} }
} }
@ -366,7 +365,7 @@ class InstallRequirements {
* @return boolean * @return boolean
*/ */
function isIIS($version = 7) { function isIIS($version = 7) {
if(strpos($this->findWebserver(), 'IIS/' . $version) !== false) { if (strpos($this->findWebserver(), 'IIS/' . $version) !== false) {
return true; return true;
} else { } else {
return false; return false;
@ -374,7 +373,7 @@ class InstallRequirements {
} }
function isApache() { function isApache() {
if(strpos($this->findWebserver(), 'Apache') !== false) { if (strpos($this->findWebserver(), 'Apache') !== false) {
return true; return true;
} else { } else {
return false; return false;
@ -388,9 +387,9 @@ class InstallRequirements {
function findWebserver() { function findWebserver() {
// Try finding from SERVER_SIGNATURE or SERVER_SOFTWARE // Try finding from SERVER_SIGNATURE or SERVER_SOFTWARE
$webserver = @$_SERVER['SERVER_SIGNATURE']; $webserver = @$_SERVER['SERVER_SIGNATURE'];
if(!$webserver) $webserver = @$_SERVER['SERVER_SOFTWARE']; if (!$webserver) $webserver = @$_SERVER['SERVER_SOFTWARE'];
if($webserver) return strip_tags(trim($webserver)); if ($webserver) return strip_tags(trim($webserver));
else return false; else return false;
} }
@ -404,13 +403,13 @@ class InstallRequirements {
$webserver = $this->findWebserver(); $webserver = $this->findWebserver();
$this->requirePHPVersion('5.3.4', '5.3.2', array( $this->requirePHPVersion('5.3.4', '5.3.2', array(
"PHP Configuration", "PHP Configuration",
"PHP5 installed", "PHP5 installed",
null, null,
"PHP version " . phpversion() "PHP version " . phpversion()
)); ));
// Check that we can identify the root folder successfully // Check that we can identify the root folder successfully
$this->requireFile(FRAMEWORK_NAME . '/dev/install/config-form.html', array("File permissions", $this->requireFile(FRAMEWORK_NAME . '/dev/install/config-form.html', array("File permissions",
"Does the webserver know where files are stored?", "Does the webserver know where files are stored?",
"The webserver isn't letting me identify where files are stored.", "The webserver isn't letting me identify where files are stored.",
@ -420,222 +419,222 @@ class InstallRequirements {
$this->requireModule('mysite', array("File permissions", "mysite/ directory exists?")); $this->requireModule('mysite', array("File permissions", "mysite/ directory exists?"));
$this->requireModule(FRAMEWORK_NAME, array("File permissions", FRAMEWORK_NAME . "/ directory exists?")); $this->requireModule(FRAMEWORK_NAME, array("File permissions", FRAMEWORK_NAME . "/ directory exists?"));
if($isApache) { if ($isApache) {
$this->checkApacheVersion(array( $this->checkApacheVersion(array(
"Webserver Configuration", "Webserver Configuration",
"Webserver is not Apache 1.x", "SilverStripe requires Apache version 2 or greater", "Webserver is not Apache 1.x", "SilverStripe requires Apache version 2 or greater",
$webserver $webserver
)); ));
$this->requireWriteable('.htaccess', array("File permissions", "Is the .htaccess file writeable?", null)); $this->requireWriteable('.htaccess', array("File permissions", "Is the .htaccess file writeable?", null));
} elseif($isIIS) { } elseif ($isIIS) {
$this->requireWriteable('web.config', array("File permissions", "Is the web.config file writeable?", null)); $this->requireWriteable('web.config', array("File permissions", "Is the web.config file writeable?", null));
} }
$this->requireWriteable('mysite/_config.php', array( $this->requireWriteable('mysite/_config.php', array(
"File permissions", "File permissions",
"Is the mysite/_config.php file writeable?", "Is the mysite/_config.php file writeable?",
null null
)); ));
if (!$this->checkModuleExists('cms')) { if (!$this->checkModuleExists('cms')) {
$this->requireWriteable('mysite/code/RootURLController.php', array( $this->requireWriteable('mysite/code/RootURLController.php', array(
"File permissions", "File permissions",
"Is the mysite/code/RootURLController.php file writeable?", "Is the mysite/code/RootURLController.php file writeable?",
null null
)); ));
} }
$this->requireWriteable('assets', array("File permissions", "Is the assets/ directory writeable?", null)); $this->requireWriteable('assets', array("File permissions", "Is the assets/ directory writeable?", null));
$tempFolder = $this->getTempFolder(); $tempFolder = $this->getTempFolder();
$this->requireTempFolder(array('File permissions', 'Is a temporary directory available?', null, $tempFolder)); $this->requireTempFolder(array('File permissions', 'Is a temporary directory available?', null, $tempFolder));
if($tempFolder) { if ($tempFolder) {
// in addition to the temp folder being available, check it is writable // in addition to the temp folder being available, check it is writable
$this->requireWriteable($tempFolder, array( $this->requireWriteable($tempFolder, array(
"File permissions", "File permissions",
sprintf("Is the temporary directory writeable?", $tempFolder), sprintf("Is the temporary directory writeable?", $tempFolder),
null null
), true); ), true);
} }
// Check for web server, unless we're calling the installer from the command-line // Check for web server, unless we're calling the installer from the command-line
$this->isRunningWebServer(array("Webserver Configuration", "Server software", "Unknown", $webserver)); $this->isRunningWebServer(array("Webserver Configuration", "Server software", "Unknown", $webserver));
if($isApache) { if ($isApache) {
$this->requireApacheRewriteModule('mod_rewrite', array( $this->requireApacheRewriteModule('mod_rewrite', array(
"Webserver Configuration", "Webserver Configuration",
"URL rewriting support", "URL rewriting support",
"You need mod_rewrite to use friendly URLs with SilverStripe, but it is not enabled." "You need mod_rewrite to use friendly URLs with SilverStripe, but it is not enabled."
)); ));
} elseif($isIIS) { } elseif ($isIIS) {
$this->requireIISRewriteModule('IIS_UrlRewriteModule', array( $this->requireIISRewriteModule('IIS_UrlRewriteModule', array(
"Webserver Configuration", "Webserver Configuration",
"URL rewriting support", "URL rewriting support",
"You need to enable the IIS URL Rewrite Module to use friendly URLs with SilverStripe, " "You need to enable the IIS URL Rewrite Module to use friendly URLs with SilverStripe, "
. "but it is not installed or enabled. Download it for IIS 7 from http://www.iis.net/expand/URLRewrite" . "but it is not installed or enabled. Download it for IIS 7 from http://www.iis.net/expand/URLRewrite"
)); ));
} else { } else {
$this->warning(array( $this->warning(array(
"Webserver Configuration", "Webserver Configuration",
"URL rewriting support", "URL rewriting support",
"I can't tell whether any rewriting module is running. You may need to configure a rewriting rule yourself.")); "I can't tell whether any rewriting module is running. You may need to configure a rewriting rule yourself."));
} }
$this->requireServerVariables(array('SCRIPT_NAME','HTTP_HOST','SCRIPT_FILENAME'), array( $this->requireServerVariables(array('SCRIPT_NAME', 'HTTP_HOST', 'SCRIPT_FILENAME'), array(
"Webserver Configuration", "Webserver Configuration",
"Recognised webserver", "Recognised webserver",
"You seem to be using an unsupported webserver. " "You seem to be using an unsupported webserver. "
. "The server variables SCRIPT_NAME, HTTP_HOST, SCRIPT_FILENAME need to be set." . "The server variables SCRIPT_NAME, HTTP_HOST, SCRIPT_FILENAME need to be set."
)); ));
$this->requirePostSupport(array( $this->requirePostSupport(array(
"Webserver Configuration", "Webserver Configuration",
"POST Support", "POST Support",
'I can\'t find $_POST, make sure POST is enabled.' 'I can\'t find $_POST, make sure POST is enabled.'
)); ));
// Check for GD support // Check for GD support
if(!$this->requireFunction("imagecreatetruecolor", array( if (!$this->requireFunction("imagecreatetruecolor", array(
"PHP Configuration", "PHP Configuration",
"GD2 support", "GD2 support",
"PHP must have GD version 2." "PHP must have GD version 2."
))) { ))) {
$this->requireFunction("imagecreate", array( $this->requireFunction("imagecreate", array(
"PHP Configuration", "PHP Configuration",
"GD2 support", "GD2 support",
"GD support for PHP not included." "GD support for PHP not included."
)); ));
} }
// Check for XML support // Check for XML support
$this->requireFunction('xml_set_object', array( $this->requireFunction('xml_set_object', array(
"PHP Configuration", "PHP Configuration",
"XML support", "XML support",
"XML support not included in PHP." "XML support not included in PHP."
)); ));
$this->requireClass('DOMDocument', array( $this->requireClass('DOMDocument', array(
"PHP Configuration", "PHP Configuration",
"DOM/XML support", "DOM/XML support",
"DOM/XML support not included in PHP." "DOM/XML support not included in PHP."
)); ));
$this->requireFunction('simplexml_load_file', array( $this->requireFunction('simplexml_load_file', array(
'PHP Configuration', 'PHP Configuration',
'SimpleXML support', 'SimpleXML support',
'SimpleXML support not included in PHP.' 'SimpleXML support not included in PHP.'
)); ));
// Check for token_get_all // Check for token_get_all
$this->requireFunction('token_get_all', array( $this->requireFunction('token_get_all', array(
"PHP Configuration", "PHP Configuration",
"Tokenizer support", "Tokenizer support",
"Tokenizer support not included in PHP." "Tokenizer support not included in PHP."
)); ));
// Check for CType support // Check for CType support
$this->requireFunction('ctype_digit', array( $this->requireFunction('ctype_digit', array(
'PHP Configuration', 'PHP Configuration',
'CType support', 'CType support',
'CType support not included in PHP.' 'CType support not included in PHP.'
)); ));
// Check for session support // Check for session support
$this->requireFunction('session_start', array( $this->requireFunction('session_start', array(
'PHP Configuration', 'PHP Configuration',
'Session support', 'Session support',
'Session support not included in PHP.' 'Session support not included in PHP.'
)); ));
// Check for iconv support // Check for iconv support
$this->requireFunction('iconv', array( $this->requireFunction('iconv', array(
'PHP Configuration', 'PHP Configuration',
'iconv support', 'iconv support',
'iconv support not included in PHP.' 'iconv support not included in PHP.'
)); ));
// Check for hash support // Check for hash support
$this->requireFunction('hash', array('PHP Configuration', 'hash support', 'hash support not included in PHP.')); $this->requireFunction('hash', array('PHP Configuration', 'hash support', 'hash support not included in PHP.'));
// Check for mbstring support // Check for mbstring support
$this->requireFunction('mb_internal_encoding', array( $this->requireFunction('mb_internal_encoding', array(
'PHP Configuration', 'PHP Configuration',
'mbstring support', 'mbstring support',
'mbstring support not included in PHP.' 'mbstring support not included in PHP.'
)); ));
// Check for Reflection support // Check for Reflection support
$this->requireClass('ReflectionClass', array( $this->requireClass('ReflectionClass', array(
'PHP Configuration', 'PHP Configuration',
'Reflection support', 'Reflection support',
'Reflection support not included in PHP.' 'Reflection support not included in PHP.'
)); ));
// Check for Standard PHP Library (SPL) support // Check for Standard PHP Library (SPL) support
$this->requireFunction('spl_classes', array( $this->requireFunction('spl_classes', array(
'PHP Configuration', 'PHP Configuration',
'SPL support', 'SPL support',
'Standard PHP Library (SPL) not included in PHP.' 'Standard PHP Library (SPL) not included in PHP.'
)); ));
$this->requireDateTimezone(array( $this->requireDateTimezone(array(
'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') ini_get('date.timezone')
)); ));
$this->suggestClass('finfo', array( $this->suggestClass('finfo', array(
'PHP Configuration', 'PHP Configuration',
'fileinfo support', 'fileinfo support',
'fileinfo should be enabled in PHP. SilverStripe uses it for MIME type detection of files. ' 'fileinfo should be enabled in PHP. SilverStripe uses it for MIME type detection of files. '
. 'SilverStripe will still operate, but email attachments and sending files to browser ' . 'SilverStripe will still operate, but email attachments and sending files to browser '
. '(e.g. export data to CSV) may not work correctly without finfo.' . '(e.g. export data to CSV) may not work correctly without finfo.'
)); ));
$this->suggestFunction('curl_init', array( $this->suggestFunction('curl_init', array(
'PHP Configuration', 'PHP Configuration',
'curl support', 'curl support',
'curl should be enabled in PHP. SilverStripe uses it for consuming web services' 'curl should be enabled in PHP. SilverStripe uses it for consuming web services'
. ' via the RestfulService class and many modules rely on it.' . ' via the RestfulService class and many modules rely on it.'
)); ));
$this->suggestClass('tidy', array( $this->suggestClass('tidy', array(
'PHP Configuration', 'PHP Configuration',
'tidy support', 'tidy support',
'Tidy provides a library of code to clean up your html. ' 'Tidy provides a library of code to clean up your html. '
. 'SilverStripe will operate fine without tidy but HTMLCleaner will not be effective.' . 'SilverStripe will operate fine without tidy but HTMLCleaner will not be effective.'
)); ));
$this->suggestPHPSetting('asp_tags', array(false), array( $this->suggestPHPSetting('asp_tags', array(false), array(
'PHP Configuration', 'PHP Configuration',
'asp_tags option', 'asp_tags option',
'This should be turned off as it can cause issues with SilverStripe' 'This should be turned off as it can cause issues with SilverStripe'
)); ));
$this->requirePHPSetting('magic_quotes_gpc', array(false), array( $this->requirePHPSetting('magic_quotes_gpc', array(false), array(
'PHP Configuration', 'PHP Configuration',
'magic_quotes_gpc option', 'magic_quotes_gpc option',
'This should be turned off, as it can cause issues with cookies. ' 'This should be turned off, as it can cause issues with cookies. '
. 'More specifically, unserializing data stored in cookies.' . 'More specifically, unserializing data stored in cookies.'
)); ));
$this->suggestPHPSetting('display_errors', array(false), array( $this->suggestPHPSetting('display_errors', array(false), array(
'PHP Configuration', 'PHP Configuration',
'display_errors option', 'display_errors option',
'Unless you\'re in a development environment, this should be turned off, ' 'Unless you\'re in a development environment, this should be turned off, '
. 'as it can expose sensitive data to website users.' . 'as it can expose sensitive data to website users.'
)); ));
// on some weirdly configured webservers arg_separator.output is set to & // on some weirdly configured webservers arg_separator.output is set to &
// which will results in links like ?param=value&foo=bar which will not be i // which will results in links like ?param=value&foo=bar which will not be i
$this->suggestPHPSetting('arg_separator.output', array('&', ''), array( $this->suggestPHPSetting('arg_separator.output', array('&', ''), array(
'PHP Configuration', 'PHP Configuration',
'arg_separator.output option', 'arg_separator.output option',
'This option defines how URL parameters are concatenated. ' 'This option defines how URL parameters are concatenated. '
. 'If not set to \'&\' this may cause issues with URL GET parameters' . 'If not set to \'&\' this may cause issues with URL GET parameters'
)); ));
// Check memory allocation // Check memory allocation
$this->requireMemory(32*1024*1024, 64*1024*1024, array( $this->requireMemory(32 * 1024 * 1024, 64 * 1024 * 1024, array(
"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") ini_get("memory_limit")
)); ));
return $this->errors; return $this->errors;
} }
@ -645,14 +644,14 @@ class InstallRequirements {
// 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') { if ($settingName = 'display_errors') {
global $originalDisplayErrorsValue; global $originalDisplayErrorsValue;
$val = $originalDisplayErrorsValue; $val = $originalDisplayErrorsValue;
} else { } else {
$val = ini_get($settingName); $val = ini_get($settingName);
} }
if(!in_array($val, $settingValues) && $val != $settingValues) { if (!in_array($val, $settingValues) && $val != $settingValues) {
$testDetails[2] = "$settingName is set to '$val' in php.ini. $testDetails[2]"; $testDetails[2] = "$settingName is set to '$val' in php.ini. $testDetails[2]";
$this->warning($testDetails); $this->warning($testDetails);
} }
@ -662,7 +661,7 @@ class InstallRequirements {
$this->testing($testDetails); $this->testing($testDetails);
$val = ini_get($settingName); $val = ini_get($settingName);
if(!in_array($val, $settingValues) && $val != $settingValues) { if (!in_array($val, $settingValues) && $val != $settingValues) {
$testDetails[2] = "$settingName is set to '$val' in php.ini. $testDetails[2]"; $testDetails[2] = "$settingName is set to '$val' in php.ini. $testDetails[2]";
$this->error($testDetails); $this->error($testDetails);
} }
@ -671,7 +670,7 @@ class InstallRequirements {
function suggestClass($class, $testDetails) { function suggestClass($class, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
if(!class_exists($class)) { if (!class_exists($class)) {
$this->warning($testDetails); $this->warning($testDetails);
} }
} }
@ -679,7 +678,7 @@ class InstallRequirements {
function suggestFunction($class, $testDetails) { function suggestFunction($class, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
if(!function_exists($class)) { if (!function_exists($class)) {
$this->warning($testDetails); $this->warning($testDetails);
} }
} }
@ -688,7 +687,7 @@ class InstallRequirements {
$this->testing($testDetails); $this->testing($testDetails);
$result = ini_get('date.timezone') && in_array(ini_get('date.timezone'), timezone_identifiers_list()); $result = ini_get('date.timezone') && in_array(ini_get('date.timezone'), timezone_identifiers_list());
if(!$result) { if (!$result) {
$this->error($testDetails); $this->error($testDetails);
} }
} }
@ -697,7 +696,7 @@ class InstallRequirements {
$_SESSION['forcemem'] = false; $_SESSION['forcemem'] = false;
$mem = $this->getPHPMemory(); $mem = $this->getPHPMemory();
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] = ini_get("memory_limit");
@ -705,15 +704,15 @@ class InstallRequirements {
$this->testing($testDetails); $this->testing($testDetails);
if($mem < $min && $mem > 0) { if ($mem < $min && $mem > 0) {
$testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated"; $testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
$this->error($testDetails); $this->error($testDetails);
} else if($mem < $recommended && $mem > 0) { } else if ($mem < $recommended && $mem > 0) {
$testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated"; $testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
$this->warning($testDetails); $this->warning($testDetails);
} elseif($mem == 0) { } elseif ($mem == 0) {
$testDetails[2] .= " We can't determine how much memory you have allocated. " $testDetails[2] .= " We can't determine how much memory you have allocated. "
. "Install only if you're sure you've allocated at least 20 MB."; . "Install only if you're sure you've allocated at least 20 MB.";
$this->warning($testDetails); $this->warning($testDetails);
} }
} }
@ -721,15 +720,15 @@ class InstallRequirements {
function getPHPMemory() { function getPHPMemory() {
$memString = ini_get("memory_limit"); $memString = ini_get("memory_limit");
switch(strtolower(substr($memString,-1))) { switch (strtolower(substr($memString, -1))) {
case "k": case "k":
return round(substr($memString,0,-1)*1024); return round(substr($memString, 0, -1) * 1024);
case "m": case "m":
return round(substr($memString,0,-1)*1024*1024); return round(substr($memString, 0, -1) * 1024 * 1024);
case "g": case "g":
return round(substr($memString,0,-1)*1024*1024*1024); return round(substr($memString, 0, -1) * 1024 * 1024 * 1024);
default: default:
return round($memString); return round($memString);
@ -737,35 +736,35 @@ class InstallRequirements {
} }
function listErrors() { function listErrors() {
if($this->errors) { if ($this->errors) {
echo "<p>The following problems are preventing me from installing SilverStripe CMS:</p>\n\n"; echo "<p>The following problems are preventing me from installing SilverStripe CMS:</p>\n\n";
foreach($this->errors as $error) { foreach ($this->errors as $error) {
echo "<li>" . htmlentities(implode(", ", $error), ENT_COMPAT, 'UTF-8') . "</li>\n"; echo "<li>" . htmlentities(implode(", ", $error), ENT_COMPAT, 'UTF-8') . "</li>\n";
} }
} }
} }
function showTable($section = null) { function showTable($section = null) {
if($section) { if ($section) {
$tests = $this->tests[$section]; $tests = $this->tests[$section];
$id = strtolower(str_replace(' ', '_', $section)); $id = strtolower(str_replace(' ', '_', $section));
echo "<table id=\"{$id}_results\" class=\"testResults\" width=\"100%\">"; echo "<table id=\"{$id}_results\" class=\"testResults\" width=\"100%\">";
foreach($tests as $test => $result) { foreach ($tests as $test => $result) {
echo "<tr class=\"$result[0]\"><td>$test</td><td>" echo "<tr class=\"$result[0]\"><td>$test</td><td>"
. nl2br(htmlentities($result[1], ENT_COMPAT, 'UTF-8')) . "</td></tr>"; . nl2br(htmlentities($result[1], ENT_COMPAT, 'UTF-8')) . "</td></tr>";
} }
echo "</table>"; echo "</table>";
} else { } else {
foreach($this->tests as $section => $tests) { foreach ($this->tests as $section => $tests) {
$failedRequirements = 0; $failedRequirements = 0;
$warningRequirements = 0; $warningRequirements = 0;
$output = ""; $output = "";
foreach($tests as $test => $result) { foreach ($tests as $test => $result) {
if(isset($result['0'])) { if (isset($result['0'])) {
switch($result['0']) { switch ($result['0']) {
case 'error': case 'error':
$failedRequirements++; $failedRequirements++;
break; break;
@ -775,21 +774,20 @@ class InstallRequirements {
} }
} }
$output .= "<tr class=\"$result[0]\"><td>$test</td><td>" $output .= "<tr class=\"$result[0]\"><td>$test</td><td>"
. nl2br(htmlentities($result[1], ENT_COMPAT, 'UTF-8')) . "</td></tr>"; . nl2br(htmlentities($result[1], ENT_COMPAT, 'UTF-8')) . "</td></tr>";
} }
$className = "good"; $className = "good";
$text = "All Requirements Pass"; $text = "All Requirements Pass";
$pluralWarnings = ($warningRequirements == 1) ? 'Warning' : 'Warnings'; $pluralWarnings = ($warningRequirements == 1) ? 'Warning' : 'Warnings';
if($failedRequirements > 0) { if ($failedRequirements > 0) {
$className = "error"; $className = "error";
$pluralWarnings = ($warningRequirements == 1) ? 'Warning' : 'Warnings'; $pluralWarnings = ($warningRequirements == 1) ? 'Warning' : 'Warnings';
$text = $failedRequirements . ' Failed and '. $warningRequirements . ' '. $pluralWarnings; $text = $failedRequirements . ' Failed and ' . $warningRequirements . ' ' . $pluralWarnings;
} } else if ($warningRequirements > 0) {
else if($warningRequirements > 0) {
$className = "warning"; $className = "warning";
$text = "All Requirements Pass but ". $warningRequirements . ' '. $pluralWarnings; $text = "All Requirements Pass but " . $warningRequirements . ' ' . $pluralWarnings;
} }
echo "<h5 class='requirement $className'>$section <a href='#'>Show All Requirements</a> <span>$text</span></h5>"; echo "<h5 class='requirement $className'>$section <a href='#'>Show All Requirements</a> <span>$text</span></h5>";
@ -803,16 +801,20 @@ class InstallRequirements {
function requireFunction($funcName, $testDetails) { function requireFunction($funcName, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
if(!function_exists($funcName)) { if (!function_exists($funcName)) {
$this->error($testDetails); $this->error($testDetails);
} else {
return true;
} }
else return true;
} }
function requireClass($className, $testDetails) { function requireClass($className, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
if(!class_exists($className)) $this->error($testDetails); if (!class_exists($className)) {
else return false; $this->error($testDetails);
} else {
return false;
}
} }
/** /**
@ -821,21 +823,22 @@ class InstallRequirements {
function requireNoClasses($classNames, $testDetails) { function requireNoClasses($classNames, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
$badClasses = array(); $badClasses = array();
foreach($classNames as $className) { foreach ($classNames as $className) {
if(class_exists($className)) $badClasses[] = $className; if (class_exists($className)) $badClasses[] = $className;
} }
if($badClasses) { if ($badClasses) {
$testDetails[2] .= ". The following classes are at fault: " . implode(', ', $badClasses); $testDetails[2] .= ". The following classes are at fault: " . implode(', ', $badClasses);
$this->error($testDetails); $this->error($testDetails);
} else {
return true;
} }
else return true;
} }
function checkApacheVersion($testDetails) { function checkApacheVersion($testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
$is1pointx = preg_match('#Apache[/ ]1\.#', $testDetails[3]); $is1pointx = preg_match('#Apache[/ ]1\.#', $testDetails[3]);
if($is1pointx) { if ($is1pointx) {
$this->error($testDetails); $this->error($testDetails);
} }
@ -847,7 +850,7 @@ class InstallRequirements {
$installedVersion = phpversion(); $installedVersion = phpversion();
if(version_compare($installedVersion, $requiredVersion, '<')) { if (version_compare($installedVersion, $requiredVersion, '<')) {
$testDetails[2] = "SilverStripe requires PHP version $requiredVersion or later.\n $testDetails[2] = "SilverStripe requires PHP version $requiredVersion or later.\n
PHP version $installedVersion is currently installed.\n PHP version $installedVersion is currently installed.\n
While SilverStripe requires at least PHP version $requiredVersion, upgrading to $recommendedVersion or later is recommended.\n While SilverStripe requires at least PHP version $requiredVersion, upgrading to $recommendedVersion or later is recommended.\n
@ -856,7 +859,7 @@ class InstallRequirements {
return; return;
} }
if(version_compare($installedVersion, $recommendedVersion, '<')) { if (version_compare($installedVersion, $recommendedVersion, '<')) {
$testDetails[2] = "PHP version $installedVersion is currently installed.\n $testDetails[2] = "PHP version $installedVersion is currently installed.\n
Upgrading to at least PHP version $recommendedVersion is recommended.\n Upgrading to at least PHP version $recommendedVersion is recommended.\n
SilverStripe should run, but you may run into issues. Future releases may require a later version of PHP.\n"; SilverStripe should run, but you may run into issues. Future releases may require a later version of PHP.\n";
@ -882,12 +885,12 @@ class InstallRequirements {
function requireModule($dirname, $testDetails) { function requireModule($dirname, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
$path = $this->getBaseDir() . $dirname; $path = $this->getBaseDir() . $dirname;
if(!file_exists($path)) { if (!file_exists($path)) {
$testDetails[2] .= " Directory '$path' not found. Please make sure you have uploaded the SilverStripe files to your webserver correctly."; $testDetails[2] .= " Directory '$path' not found. Please make sure you have uploaded the SilverStripe files to your webserver correctly.";
$this->error($testDetails); $this->error($testDetails);
} elseif(!file_exists($path . '/_config.php') && $dirname != 'mysite') { } elseif (!file_exists($path . '/_config.php') && $dirname != 'mysite') {
$testDetails[2] .= " Directory '$path' exists, but is missing files. Please make sure you have uploaded " $testDetails[2] .= " Directory '$path' exists, but is missing files. Please make sure you have uploaded "
. "the SilverStripe files to your webserver correctly."; . "the SilverStripe files to your webserver correctly.";
$this->error($testDetails); $this->error($testDetails);
} }
} }
@ -895,7 +898,7 @@ class InstallRequirements {
function requireFile($filename, $testDetails) { function requireFile($filename, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
$filename = $this->getBaseDir() . $filename; $filename = $this->getBaseDir() . $filename;
if(!file_exists($filename)) { if (!file_exists($filename)) {
$testDetails[2] .= " (file '$filename' not found)"; $testDetails[2] .= " (file '$filename' not found)";
$this->error($testDetails); $this->error($testDetails);
} }
@ -904,44 +907,44 @@ class InstallRequirements {
function requireWriteable($filename, $testDetails, $absolute = false) { function requireWriteable($filename, $testDetails, $absolute = false) {
$this->testing($testDetails); $this->testing($testDetails);
if($absolute) { if ($absolute) {
$filename = str_replace('/', DIRECTORY_SEPARATOR, $filename); $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename);
} else { } else {
$filename = $this->getBaseDir() . str_replace('/', DIRECTORY_SEPARATOR, $filename); $filename = $this->getBaseDir() . str_replace('/', DIRECTORY_SEPARATOR, $filename);
} }
if(file_exists($filename)) $isWriteable = is_writeable($filename); if (file_exists($filename)) $isWriteable = is_writeable($filename);
else $isWriteable = is_writeable(dirname($filename)); else $isWriteable = is_writeable(dirname($filename));
if(!$isWriteable) { if (!$isWriteable) {
if(function_exists('posix_getgroups')) { if (function_exists('posix_getgroups')) {
$userID = posix_geteuid(); $userID = posix_geteuid();
$user = posix_getpwuid($userID); $user = posix_getpwuid($userID);
$currentOwnerID = fileowner(file_exists($filename) ? $filename : dirname($filename) ); $currentOwnerID = fileowner(file_exists($filename) ? $filename : dirname($filename));
$currentOwner = posix_getpwuid($currentOwnerID); $currentOwner = posix_getpwuid($currentOwnerID);
$testDetails[2] .= "User '$user[name]' needs to be able to write to this file:\n$filename\n\nThe " $testDetails[2] .= "User '$user[name]' needs to be able to write to this file:\n$filename\n\nThe "
. "file is currently owned by '$currentOwner[name]'. "; . "file is currently owned by '$currentOwner[name]'. ";
if($user['name'] == $currentOwner['name']) { if ($user['name'] == $currentOwner['name']) {
$testDetails[2] .= "We recommend that you make the file writeable."; $testDetails[2] .= "We recommend that you make the file writeable.";
} else { } else {
$groups = posix_getgroups(); $groups = posix_getgroups();
$groupList = array(); $groupList = array();
foreach($groups as $group) { foreach ($groups as $group) {
$groupInfo = posix_getgrgid($group); $groupInfo = posix_getgrgid($group);
if(in_array($currentOwner['name'], $groupInfo['members'])) $groupList[] = $groupInfo['name']; if (in_array($currentOwner['name'], $groupInfo['members'])) $groupList[] = $groupInfo['name'];
} }
if($groupList) { if ($groupList) {
$testDetails[2] .= " We recommend that you make the file group-writeable " $testDetails[2] .= " We recommend that you make the file group-writeable "
. "and change the group to one of these groups:\n - ". implode("\n - ", $groupList) . "and change the group to one of these groups:\n - " . implode("\n - ", $groupList)
. "\n\nFor example:\nchmod g+w $filename\nchgrp " . $groupList[0] . " $filename"; . "\n\nFor example:\nchmod g+w $filename\nchgrp " . $groupList[0] . " $filename";
} else { } else {
$testDetails[2] .= " There is no user-group that contains both the web-server user and the " $testDetails[2] .= " There is no user-group that contains both the web-server user and the "
. "owner of this file. Change the ownership of the file, create a new group, or " . "owner of this file. Change the ownership of the file, create a new group, or "
. "temporarily make the file writeable by everyone during the install process."; . "temporarily make the file writeable by everyone during the install process.";
} }
} }
@ -958,19 +961,19 @@ class InstallRequirements {
$worked = true; $worked = true;
$ssTmp = "$sysTmp/silverstripe-cache"; $ssTmp = "$sysTmp/silverstripe-cache";
if(!@file_exists($ssTmp)) { if (!@file_exists($ssTmp)) {
$worked = @mkdir($ssTmp); $worked = @mkdir($ssTmp);
} }
if(!$worked) { if (!$worked) {
$ssTmp = dirname($_SERVER['SCRIPT_FILENAME']) . '/silverstripe-cache'; $ssTmp = dirname($_SERVER['SCRIPT_FILENAME']) . '/silverstripe-cache';
$worked = true; $worked = true;
if(!@file_exists($ssTmp)) { if (!@file_exists($ssTmp)) {
$worked = @mkdir($ssTmp); $worked = @mkdir($ssTmp);
} }
} }
if($worked) return $ssTmp; if ($worked) return $ssTmp;
return false; return false;
} }
@ -979,7 +982,7 @@ class InstallRequirements {
$this->testing($testDetails); $this->testing($testDetails);
$tempFolder = $this->getTempFolder(); $tempFolder = $this->getTempFolder();
if(!$tempFolder) { if (!$tempFolder) {
$testDetails[2] = "Permission problem gaining access to a temp directory. " . $testDetails[2] = "Permission problem gaining access to a temp directory. " .
"Please create a folder named silverstripe-cache in the base directory " . "Please create a folder named silverstripe-cache in the base directory " .
"of the installation and ensure it has the adequate permissions."; "of the installation and ensure it has the adequate permissions.";
@ -989,7 +992,7 @@ class InstallRequirements {
function requireApacheModule($moduleName, $testDetails) { function requireApacheModule($moduleName, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
if(!in_array($moduleName, apache_get_modules())) { if (!in_array($moduleName, apache_get_modules())) {
$this->error($testDetails); $this->error($testDetails);
return false; return false;
} else { } else {
@ -998,9 +1001,9 @@ class InstallRequirements {
} }
function testApacheRewriteExists($moduleName = 'mod_rewrite') { function testApacheRewriteExists($moduleName = 'mod_rewrite') {
if(function_exists('apache_get_modules') && in_array($moduleName, apache_get_modules())) { if (function_exists('apache_get_modules') && in_array($moduleName, apache_get_modules())) {
return true; return true;
} elseif(isset($_SERVER['HTTP_MOD_REWRITE']) && $_SERVER['HTTP_MOD_REWRITE'] == 'On') { } elseif (isset($_SERVER['HTTP_MOD_REWRITE']) && $_SERVER['HTTP_MOD_REWRITE'] == 'On') {
return true; return true;
} else { } else {
return false; return false;
@ -1008,7 +1011,7 @@ class InstallRequirements {
} }
function testIISRewriteModuleExists($moduleName = 'IIS_UrlRewriteModule') { function testIISRewriteModuleExists($moduleName = 'IIS_UrlRewriteModule') {
if(isset($_SERVER[$moduleName]) && $_SERVER[$moduleName]) { if (isset($_SERVER[$moduleName]) && $_SERVER[$moduleName]) {
return true; return true;
} else { } else {
return false; return false;
@ -1017,7 +1020,7 @@ class InstallRequirements {
function requireApacheRewriteModule($moduleName, $testDetails) { function requireApacheRewriteModule($moduleName, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
if($this->testApacheRewriteExists()) { if ($this->testApacheRewriteExists()) {
return true; return true;
} else { } else {
$this->warning($testDetails); $this->warning($testDetails);
@ -1035,7 +1038,7 @@ class InstallRequirements {
function requireIISRewriteModule($moduleName, $testDetails) { function requireIISRewriteModule($moduleName, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
if($this->testIISRewriteModuleExists()) { if ($this->testIISRewriteModuleExists()) {
return true; return true;
} else { } else {
$this->warning($testDetails); $this->warning($testDetails);
@ -1053,7 +1056,7 @@ class InstallRequirements {
*/ */
function getDatabaseConfigurationHelper($databaseClass) { function getDatabaseConfigurationHelper($databaseClass) {
$adapters = DatabaseAdapterRegistry::get_adapters(); $adapters = DatabaseAdapterRegistry::get_adapters();
if(isset($adapters[$databaseClass])) { if (isset($adapters[$databaseClass])) {
$helperPath = $adapters[$databaseClass]['helperPath']; $helperPath = $adapters[$databaseClass]['helperPath'];
$class = str_replace('.php', '', basename($helperPath)); $class = str_replace('.php', '', basename($helperPath));
} }
@ -1064,7 +1067,7 @@ class InstallRequirements {
$this->testing($testDetails); $this->testing($testDetails);
$helper = $this->getDatabaseConfigurationHelper($databaseConfig['type']); $helper = $this->getDatabaseConfigurationHelper($databaseConfig['type']);
$result = $helper->requireDatabaseFunctions($databaseConfig); $result = $helper->requireDatabaseFunctions($databaseConfig);
if($result) { if ($result) {
return true; return true;
} else { } else {
$this->error($testDetails); $this->error($testDetails);
@ -1076,7 +1079,7 @@ class InstallRequirements {
$this->testing($testDetails); $this->testing($testDetails);
$helper = $this->getDatabaseConfigurationHelper($databaseConfig['type']); $helper = $this->getDatabaseConfigurationHelper($databaseConfig['type']);
$result = $helper->requireDatabaseConnection($databaseConfig); $result = $helper->requireDatabaseConnection($databaseConfig);
if($result['success']) { if ($result['success']) {
return true; return true;
} else { } else {
$testDetails[2] .= ": " . $result['error']; $testDetails[2] .= ": " . $result['error'];
@ -1088,9 +1091,9 @@ class InstallRequirements {
function requireDatabaseVersion($databaseConfig, $testDetails) { function requireDatabaseVersion($databaseConfig, $testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
$helper = $this->getDatabaseConfigurationHelper($databaseConfig['type']); $helper = $this->getDatabaseConfigurationHelper($databaseConfig['type']);
if(method_exists($helper, 'requireDatabaseVersion')) { if (method_exists($helper, 'requireDatabaseVersion')) {
$result = $helper->requireDatabaseVersion($databaseConfig); $result = $helper->requireDatabaseVersion($databaseConfig);
if($result['success']) { if ($result['success']) {
return true; return true;
} else { } else {
$testDetails[2] .= $result['error']; $testDetails[2] .= $result['error'];
@ -1106,7 +1109,7 @@ class InstallRequirements {
$this->testing($testDetails); $this->testing($testDetails);
$helper = $this->getDatabaseConfigurationHelper($databaseConfig['type']); $helper = $this->getDatabaseConfigurationHelper($databaseConfig['type']);
$result = $helper->requireDatabaseServer($databaseConfig); $result = $helper->requireDatabaseServer($databaseConfig);
if($result['success']) { if ($result['success']) {
return true; return true;
} else { } else {
$testDetails[2] .= ": " . $result['error']; $testDetails[2] .= ": " . $result['error'];
@ -1119,13 +1122,13 @@ class InstallRequirements {
$this->testing($testDetails); $this->testing($testDetails);
$helper = $this->getDatabaseConfigurationHelper($databaseConfig['type']); $helper = $this->getDatabaseConfigurationHelper($databaseConfig['type']);
$result = $helper->requireDatabaseOrCreatePermissions($databaseConfig); $result = $helper->requireDatabaseOrCreatePermissions($databaseConfig);
if($result['success']) { if ($result['success']) {
if($result['alreadyExists']) $testDetails[3] = "Database $databaseConfig[database]"; if ($result['alreadyExists']) $testDetails[3] = "Database $databaseConfig[database]";
else $testDetails[3] = "Able to create a new database"; else $testDetails[3] = "Able to create a new database";
$this->testing($testDetails); $this->testing($testDetails);
return true; return true;
} else { } else {
if(!@$result['cannotCreate']) { if (!@$result['cannotCreate']) {
$testDetails[2] .= ". Please create the database manually."; $testDetails[2] .= ". Please create the database manually.";
} else { } else {
$testDetails[2] .= " (user '$databaseConfig[username]' doesn't have CREATE DATABASE permissions.)"; $testDetails[2] .= " (user '$databaseConfig[username]' doesn't have CREATE DATABASE permissions.)";
@ -1140,13 +1143,13 @@ class InstallRequirements {
$this->testing($testDetails); $this->testing($testDetails);
$missing = array(); $missing = array();
foreach($varNames as $varName) { foreach ($varNames as $varName) {
if(!isset($_SERVER[$varName]) || !$_SERVER[$varName]) { if (!isset($_SERVER[$varName]) || !$_SERVER[$varName]) {
$missing[] = '$_SERVER[' . $varName . ']'; $missing[] = '$_SERVER[' . $varName . ']';
} }
} }
if(!$missing) { if (!$missing) {
return true; return true;
} else { } else {
$testDetails[2] .= " (the following PHP variables are missing: " . implode(", ", $missing) . ")"; $testDetails[2] .= " (the following PHP variables are missing: " . implode(", ", $missing) . ")";
@ -1158,7 +1161,7 @@ class InstallRequirements {
function requirePostSupport($testDetails) { function requirePostSupport($testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
if(!isset($_POST)) { if (!isset($_POST)) {
$this->error($testDetails); $this->error($testDetails);
return false; return false;
@ -1169,7 +1172,7 @@ class InstallRequirements {
function isRunningWebServer($testDetails) { function isRunningWebServer($testDetails) {
$this->testing($testDetails); $this->testing($testDetails);
if($testDetails[3]) { if ($testDetails[3]) {
return true; return true;
} else { } else {
$this->warning($testDetails); $this->warning($testDetails);
@ -1179,21 +1182,22 @@ class InstallRequirements {
// Must be PHP4 compatible // Must be PHP4 compatible
var $baseDir; var $baseDir;
function getBaseDir() { function getBaseDir() {
// Cache the value so that when the installer mucks with SCRIPT_FILENAME half way through, this method // Cache the value so that when the installer mucks with SCRIPT_FILENAME half way through, this method
// still returns the correct value. // still returns the correct value.
if(!$this->baseDir) $this->baseDir = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) . DIRECTORY_SEPARATOR; if (!$this->baseDir) $this->baseDir = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) . DIRECTORY_SEPARATOR;
return $this->baseDir; return $this->baseDir;
} }
function testing($testDetails) { function testing($testDetails) {
if(!$testDetails) return; if (!$testDetails) return;
$section = $testDetails[0]; $section = $testDetails[0];
$test = $testDetails[1]; $test = $testDetails[1];
$message = "OK"; $message = "OK";
if(isset($testDetails[3])) $message .= " ($testDetails[3])"; if (isset($testDetails[3])) $message .= " ($testDetails[3])";
$this->tests[$section][$test] = array("good", $message); $this->tests[$section][$test] = array("good", $message);
} }
@ -1231,19 +1235,20 @@ class Installer extends InstallRequirements {
} }
function install($config) { function install($config) {
?> ?>
<html> <html>
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8"/>
<title>Installing SilverStripe...</title> <title>Installing SilverStripe...</title>
<link rel="stylesheet" type="text/css" href="<?php echo FRAMEWORK_NAME; ?>/dev/install/css/install.css" /> <link rel="stylesheet" type="text/css" href="<?php echo FRAMEWORK_NAME; ?>/dev/install/css/install.css"/>
<script src="<?php echo FRAMEWORK_NAME; ?>/thirdparty/jquery/jquery.js"></script> <script src="<?php echo FRAMEWORK_NAME; ?>/thirdparty/jquery/jquery.js"></script>
</head> </head>
<body> <body>
<div class="install-header"> <div class="install-header">
<div class="inner"> <div class="inner">
<div class="brand"> <div class="brand">
<span class="logo"></span> <span class="logo"></span>
<h1>SilverStripe</h1> <h1>SilverStripe</h1>
</div> </div>
</div> </div>
@ -1255,7 +1260,9 @@ class Installer extends InstallRequirements {
<div class="main"> <div class="main">
<div class="inner"> <div class="inner">
<h2>Installing SilverStripe...</h2> <h2>Installing SilverStripe...</h2>
<p>I am now running through the installation steps (this should take about 30 seconds)</p> <p>I am now running through the installation steps (this should take about 30 seconds)</p>
<p>If you receive a fatal error, refresh this page to continue the installation</p> <p>If you receive a fatal error, refresh this page to continue the installation</p>
<ul> <ul>
<?php <?php
@ -1266,8 +1273,8 @@ class Installer extends InstallRequirements {
flush(); flush();
if(isset($config['stats'])) { if (isset($config['stats'])) {
if(file_exists(FRAMEWORK_NAME . '/silverstripe_version')) { if (file_exists(FRAMEWORK_NAME . '/silverstripe_version')) {
$silverstripe_version = file_get_contents(FRAMEWORK_NAME . '/silverstripe_version'); $silverstripe_version = file_get_contents(FRAMEWORK_NAME . '/silverstripe_version');
} else { } else {
$silverstripe_version = "unknown"; $silverstripe_version = "unknown";
@ -1280,20 +1287,20 @@ class Installer extends InstallRequirements {
// Try to determine the database version from the helper // Try to determine the database version from the helper
$databaseVersion = $config['db']['type']; $databaseVersion = $config['db']['type'];
$helper = $this->getDatabaseConfigurationHelper($dbType); $helper = $this->getDatabaseConfigurationHelper($dbType);
if($helper && method_exists($helper, 'getDatabaseVersion')) { if ($helper && method_exists($helper, 'getDatabaseVersion')) {
$databaseVersion = urlencode($dbType . ': ' . $helper->getDatabaseVersion($config['db'][$dbType])); $databaseVersion = urlencode($dbType . ': ' . $helper->getDatabaseVersion($config['db'][$dbType]));
} }
$url = "http://ss2stat.silverstripe.com/Installation/add?SilverStripe=$silverstripe_version&PHP=$phpVersion&Database=$databaseVersion&WebServer=$encWebserver"; $url = "http://ss2stat.silverstripe.com/Installation/add?SilverStripe=$silverstripe_version&PHP=$phpVersion&Database=$databaseVersion&WebServer=$encWebserver";
if(isset($_SESSION['StatsID']) && $_SESSION['StatsID']) { if (isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
$url .= '&ID=' . $_SESSION['StatsID']; $url .= '&ID=' . $_SESSION['StatsID'];
} }
@$_SESSION['StatsID'] = file_get_contents($url); @$_SESSION['StatsID'] = file_get_contents($url);
} }
if(file_exists('mysite/_config.php')) { if (file_exists('mysite/_config.php')) {
// Truncate the contents of _config instead of deleting it - we can't re-create it because Windows handles permissions slightly // Truncate the contents of _config instead of deleting it - we can't re-create it because Windows handles permissions slightly
// differently to UNIX based filesystems - it takes the permissions from the parent directory instead of retaining them // differently to UNIX based filesystems - it takes the permissions from the parent directory instead of retaining them
$fh = fopen('mysite/_config.php', 'wb'); $fh = fopen('mysite/_config.php', 'wb');
@ -1306,8 +1313,8 @@ class Installer extends InstallRequirements {
$type = addcslashes($config['db']['type'], "\'"); $type = addcslashes($config['db']['type'], "\'");
$dbConfig = $config['db'][$type]; $dbConfig = $config['db'][$type];
$dbConfig = array_map(create_function('$v', 'return addcslashes($v, "\\\'");'), $dbConfig); $dbConfig = array_map(create_function('$v', 'return addcslashes($v, "\\\'");'), $dbConfig);
if(!isset($dbConfig['path'])) $dbConfig['path'] = ''; if (!isset($dbConfig['path'])) $dbConfig['path'] = '';
if(!$dbConfig) { if (!$dbConfig) {
echo "<p style=\"color: red\">Bad config submitted</p><pre>"; echo "<p style=\"color: red\">Bad config submitted</p><pre>";
print_r($config); print_r($config);
echo "</pre>"; echo "</pre>";
@ -1316,7 +1323,7 @@ class Installer extends InstallRequirements {
// Write the config file // Write the config file
global $usingEnv; global $usingEnv;
if($usingEnv) { if ($usingEnv) {
$this->statusMessage("Setting up 'mysite/_config.php' for use with _ss_environment.php..."); $this->statusMessage("Setting up 'mysite/_config.php' for use with _ss_environment.php...");
$this->writeToFile("mysite/_config.php", <<<PHP $this->writeToFile("mysite/_config.php", <<<PHP
@ -1376,11 +1383,11 @@ PHP
} }
// Write the appropriate web server configuration file for rewriting support // Write the appropriate web server configuration file for rewriting support
if($this->hasRewritingCapability()) { if ($this->hasRewritingCapability()) {
if($isApache) { if ($isApache) {
$this->statusMessage("Setting up '.htaccess' file..."); $this->statusMessage("Setting up '.htaccess' file...");
$this->createHtaccess(); $this->createHtaccess();
} elseif($isIIS) { } elseif ($isIIS) {
$this->statusMessage("Setting up 'web.config' file..."); $this->statusMessage("Setting up 'web.config' file...");
$this->createWebConfig(); $this->createWebConfig();
} }
@ -1421,7 +1428,7 @@ PHP
try { try {
$this->statusMessage('Creating default CMS admin account...'); $this->statusMessage('Creating default CMS admin account...');
$adminMember->write(); $adminMember->write();
} catch(Exception $e) { } catch (Exception $e) {
$this->statusMessage( $this->statusMessage(
sprintf('Warning: Default CMS admin account could not be created (error: %s)', $e->getMessage()) sprintf('Warning: Default CMS admin account could not be created (error: %s)', $e->getMessage())
); );
@ -1432,7 +1439,7 @@ PHP
try { try {
$this->statusMessage('Creating initial filesystem assets...'); $this->statusMessage('Creating initial filesystem assets...');
Filesystem::sync(); Filesystem::sync();
} catch(Exception $e) { } catch (Exception $e) {
$this->statusMessage( $this->statusMessage(
sprintf('Warning: Creating initial filesystem assets failed (error: %s)', $e->getMessage()) sprintf('Warning: Creating initial filesystem assets failed (error: %s)', $e->getMessage())
); );
@ -1441,8 +1448,8 @@ PHP
$_SESSION['username'] = $config['admin']['username']; $_SESSION['username'] = $config['admin']['username'];
$_SESSION['password'] = $config['admin']['password']; $_SESSION['password'] = $config['admin']['password'];
if(!$this->errors) { if (!$this->errors) {
if(isset($_SERVER['HTTP_HOST']) && $this->hasRewritingCapability()) { if (isset($_SERVER['HTTP_HOST']) && $this->hasRewritingCapability()) {
$this->statusMessage("Checking that friendly URLs work..."); $this->statusMessage("Checking that friendly URLs work...");
$this->checkRewrite(); $this->checkRewrite();
} else { } else {
@ -1474,7 +1481,7 @@ HTML;
$base = $this->getBaseDir(); $base = $this->getBaseDir();
$this->statusMessage("Setting up $base$filename"); $this->statusMessage("Setting up $base$filename");
if((@$fh = fopen($base . $filename, 'wb')) && fwrite($fh, $content) && fclose($fh)) { if ((@$fh = fopen($base . $filename, 'wb')) && fwrite($fh, $content) && fclose($fh)) {
return true; return true;
} else { } else {
$this->error("Couldn't write to file $base$filename"); $this->error("Couldn't write to file $base$filename");
@ -1486,10 +1493,10 @@ HTML;
$end = "\n### SILVERSTRIPE END ###"; $end = "\n### SILVERSTRIPE END ###";
$base = dirname($_SERVER['SCRIPT_NAME']); $base = dirname($_SERVER['SCRIPT_NAME']);
if(defined('DIRECTORY_SEPARATOR')) $base = str_replace(DIRECTORY_SEPARATOR, '/', $base); if (defined('DIRECTORY_SEPARATOR')) $base = str_replace(DIRECTORY_SEPARATOR, '/', $base);
else $base = str_replace("\\", '/', $base); else $base = str_replace("\\", '/', $base);
if($base != '.') $baseClause = "RewriteBase '$base'\n"; if ($base != '.') $baseClause = "RewriteBase '$base'\n";
else $baseClause = ""; else $baseClause = "";
$modulePath = FRAMEWORK_NAME; $modulePath = FRAMEWORK_NAME;
$rewrite = <<<TEXT $rewrite = <<<TEXT
@ -1530,14 +1537,14 @@ ErrorDocument 500 /assets/error-500.html
</IfModule> </IfModule>
TEXT; TEXT;
if(file_exists('.htaccess')) { if (file_exists('.htaccess')) {
$htaccess = file_get_contents('.htaccess'); $htaccess = file_get_contents('.htaccess');
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) { if (strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
$htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n"; $htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n";
} }
if(strpos($htaccess, '### SILVERSTRIPE START ###') !== false && strpos($htaccess, '### SILVERSTRIPE END ###') !== false) { if (strpos($htaccess, '### SILVERSTRIPE START ###') !== false && strpos($htaccess, '### SILVERSTRIPE END ###') !== false) {
$start = substr($htaccess, 0, strpos($htaccess, '### SILVERSTRIPE START ###')) . "### SILVERSTRIPE START ###\n"; $start = substr($htaccess, 0, strpos($htaccess, '### SILVERSTRIPE START ###')) . "### SILVERSTRIPE START ###\n";
$end = "\n" . substr($htaccess, strpos($htaccess, '### SILVERSTRIPE END ###')); $end = "\n" . substr($htaccess, strpos($htaccess, '### SILVERSTRIPE END ###'));
} }
@ -1635,7 +1642,7 @@ HTML;
function var_export_array_nokeys($array) { function var_export_array_nokeys($array) {
$retval = "array(\n"; $retval = "array(\n";
foreach($array as $item) { foreach ($array as $item) {
$retval .= "\t'"; $retval .= "\t'";
$retval .= trim($item); $retval .= trim($item);
$retval .= "',\n"; $retval .= "',\n";