mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Update sapphire so that it can run with the default .htaccess and mysite/_config.php files provided in the phpinstaller. If database config is missing, then redirect to install.php
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@65981 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
60eafbcd9d
commit
9a45672aa4
@ -14,6 +14,12 @@
|
||||
* - SS_DATABASE_SUFFIX: A suffix to add to the database name.
|
||||
* - SS_DATABASE_PREFIX: A prefix to add to the database name.
|
||||
*
|
||||
* There is one more setting that is intended to be used by people who work on SilverStripe.
|
||||
* - SS_DATABASE_CHOOSE_NAME: Boolean. If true, then the system will choose a default database name for you if one isn't give
|
||||
* in the $database variable. The database name will be "SS_" followed by the name of the folder into which you have installed
|
||||
* SilverStripe. If this is enabled, it means that the phpinstaller will work out of the box without the installer needing to
|
||||
* alter any files. This helps prevent accidental changes to the environment.
|
||||
*
|
||||
* You can configure the environment with this define:
|
||||
* - SS_ENVIRONMENT_TYPE: The environment type: dev, test or live.
|
||||
*
|
||||
@ -31,25 +37,42 @@
|
||||
/*
|
||||
* _ss_environment.php handler
|
||||
*/
|
||||
foreach(array(
|
||||
'SS_DATABASE_PASSWORD',
|
||||
'SS_DATABASE_USERNAME',
|
||||
'SS_ENVIRONMENT_TYPE',) as $reqDefine) {
|
||||
if(!defined($reqDefine)) user_error("$reqDefine must be defined in your _ss_environment.php. See http://doc.silverstripe.com/doku.php?id=environment-management for more infomration", E_USER_ERROR);
|
||||
if(defined('SS_ENVIRONMENT_FILE')) {
|
||||
// Only perform valdiation if SS_ENVIRONMENT_FILE is actually set, which is to say, there is an _ss_environment.php file
|
||||
foreach(array(
|
||||
'SS_DATABASE_PASSWORD',
|
||||
'SS_DATABASE_USERNAME',
|
||||
'SS_ENVIRONMENT_TYPE',) as $reqDefine) {
|
||||
if(!defined($reqDefine)) user_error("$reqDefine must be defined in your _ss_environment.php. See http://doc.silverstripe.com/doku.php?id=environment-management for more infomration", E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
Director::set_environment_type(SS_ENVIRONMENT_TYPE);
|
||||
|
||||
global $databaseConfig;
|
||||
$databaseConfig = array(
|
||||
"type" => "MySQLDatabase",
|
||||
"server" => defined('SS_DATABASE_SERVER') ? SS_DATABASE_SERVER : 'localhost',
|
||||
"username" => SS_DATABASE_USERNAME,
|
||||
"password" => SS_DATABASE_PASSWORD,
|
||||
"database" => (defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : '')
|
||||
. $database
|
||||
. (defined('SS_DATABASE_SUFFIX') ? SS_DATABASE_SUFFIX : ''),
|
||||
);
|
||||
if(defined('SS_ENVIRONMENT_TYPE')) {
|
||||
Director::set_environment_type(SS_ENVIRONMENT_TYPE);
|
||||
}
|
||||
|
||||
global $database;
|
||||
|
||||
// No database provided
|
||||
if(!isset($database) || !$database) {
|
||||
// if SS_DATABASE_CHOOSE_NAME
|
||||
if(defined('SS_DATABASE_CHOOSE_NAME') && SS_DATABASE_CHOOSE_NAME) {
|
||||
$database = "SS_" . basename(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
|
||||
}
|
||||
}
|
||||
|
||||
if(defined('SS_DATABASE_USERNAME') && defined('SS_DATABASE_PASSWORD')) {
|
||||
global $databaseConfig;
|
||||
$databaseConfig = array(
|
||||
"type" => "MySQLDatabase",
|
||||
"server" => defined('SS_DATABASE_SERVER') ? SS_DATABASE_SERVER : 'localhost',
|
||||
"username" => SS_DATABASE_USERNAME,
|
||||
"password" => SS_DATABASE_PASSWORD,
|
||||
"database" => (defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : '')
|
||||
. $database
|
||||
. (defined('SS_DATABASE_SUFFIX') ? SS_DATABASE_SUFFIX : ''),
|
||||
);
|
||||
}
|
||||
|
||||
if(defined('SS_SEND_ALL_EMAILS_TO')) {
|
||||
Email::send_all_emails_to(SS_SEND_ALL_EMAILS_TO);
|
||||
|
@ -29,6 +29,7 @@ error_reporting(E_ALL);
|
||||
$envFiles = array('../_ss_environment.php', '../../_ss_environment.php', '../../../_ss_environment.php');
|
||||
foreach($envFiles as $envFile) {
|
||||
if(file_exists($envFile)) {
|
||||
define('SS_ENVIRONMENT_FILE', $envFile);
|
||||
include_once($envFile);
|
||||
break;
|
||||
}
|
||||
@ -257,6 +258,7 @@ function getClassFile($className) {
|
||||
function singleton($className) {
|
||||
static $_SINGLETONS;
|
||||
if(!isset($className)) user_error("singleton() Called without a class", E_USER_ERROR);
|
||||
if(!is_string($className)) user_error("singleton() passed bad class_name: " . var_export($className,true), E_USER_ERROR);
|
||||
if(!isset($_SINGLETONS[$className])) {
|
||||
if(!class_exists($className)) user_error("Bad class to singleton() - $className", E_USER_ERROR);
|
||||
$_SINGLETONS[$className] = Object::strong_create($className,null, true);
|
||||
|
7
main.php
7
main.php
@ -78,6 +78,13 @@ if (isset($_GET['debug_profile'])) {
|
||||
// Connect to database
|
||||
require_once("core/model/DB.php");
|
||||
|
||||
// Redirect to the installer if no database is selected
|
||||
if(!isset($databaseConfig) || !isset($databaseConfig['database']) || !$databaseConfig['database']) {
|
||||
$installURL = dirname(dirname($_SERVER['SCRIPT_NAME'])) . '/install.php';
|
||||
header("Location: $installURL");
|
||||
die();
|
||||
}
|
||||
|
||||
if (isset($_GET['debug_profile'])) Profiler::mark('DB::connect');
|
||||
DB::connect($databaseConfig);
|
||||
if (isset($_GET['debug_profile'])) Profiler::unmark('DB::connect');
|
||||
|
Loading…
Reference in New Issue
Block a user