2008-01-21 09:01:30 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2012-03-24 04:38:57 +01:00
|
|
|
* Configure SilverStripe from the _ss_environment.php file.
|
|
|
|
* Usage: Put "require_once('conf/ConfigureFromEnv.php');" into your _config.php file.
|
2008-01-21 09:01:30 +01:00
|
|
|
*
|
|
|
|
* If you include this file, you will be able to use the following defines in _ss_environment.php to control
|
|
|
|
* your site.
|
|
|
|
*
|
|
|
|
* Your database connection will be set up using these defines:
|
2009-05-27 01:45:54 +02:00
|
|
|
* - SS_DATABASE_CLASS: The database class to use, MySQLDatabase, MSSQLDatabase, etc. defaults to
|
|
|
|
* MySQLDatabase
|
|
|
|
* - SS_DATABASE_SERVER: The database server to use, defaulting to localhost
|
2010-10-13 03:28:54 +02:00
|
|
|
* - SS_DATABASE_USERNAME: The database username (mandatory)
|
2008-01-21 09:01:30 +01:00
|
|
|
* - SS_DATABASE_PASSWORD: The database password (mandatory)
|
2009-05-27 01:45:54 +02:00
|
|
|
* - SS_DATABASE_SUFFIX: A suffix to add to the database name.
|
|
|
|
* - SS_DATABASE_PREFIX: A prefix to add to the database name.
|
2012-03-11 20:53:01 +01:00
|
|
|
* - SS_DATABASE_TIMEZONE: Set the database timezone to something other than the system timezone.
|
2008-01-21 09:01:30 +01:00
|
|
|
*
|
2008-11-18 02:48:37 +01:00
|
|
|
* There is one more setting that is intended to be used by people who work on SilverStripe.
|
2012-09-26 23:34:00 +02:00
|
|
|
* - SS_DATABASE_CHOOSE_NAME: Boolean/Int. If set, 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.
|
2008-11-18 02:48:37 +01:00
|
|
|
*
|
2012-09-26 23:34:00 +02:00
|
|
|
* If SS_DATABASE_CHOOSE_NAME is an integer greater than one, then an ancestor folder will be used for the database
|
|
|
|
* name. This is handy for a site that's hosted from /sites/examplesite/www or /buildbot/allmodules-2.3/build. If
|
|
|
|
* it's 2, the parent folder will be chosen; if it's 3 the grandparent, and so on.
|
2009-05-20 00:16:06 +02:00
|
|
|
*
|
2008-01-21 09:01:30 +01:00
|
|
|
* You can configure the environment with this define:
|
2012-09-26 23:34:00 +02:00
|
|
|
*
|
2008-01-21 09:01:30 +01:00
|
|
|
* - SS_ENVIRONMENT_TYPE: The environment type: dev, test or live.
|
|
|
|
*
|
2012-09-26 23:34:00 +02:00
|
|
|
* You can configure the default admin with these defines:
|
|
|
|
*
|
|
|
|
* - SS_DEFAULT_ADMIN_USERNAME: The username of the default admin - this is a non-database user with administrative
|
|
|
|
* privileges.
|
2008-02-10 23:58:58 +01:00
|
|
|
* - SS_DEFAULT_ADMIN_PASSWORD: The password of the default admin.
|
2009-03-04 04:44:11 +01:00
|
|
|
* - SS_USE_BASIC_AUTH: Protect the site with basic auth (good for test sites)
|
2008-02-10 23:58:58 +01:00
|
|
|
*
|
2008-01-21 09:01:30 +01:00
|
|
|
* Email:
|
|
|
|
* - SS_SEND_ALL_EMAILS_TO: If you set this define, all emails will be redirected to this address.
|
2011-03-02 06:23:07 +01:00
|
|
|
* - SS_SEND_ALL_EMAILS_FROM: If you set this define, all emails will be send from this address.
|
2008-01-21 09:01:30 +01:00
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-01-21 09:01:30 +01:00
|
|
|
* @subpackage core
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _ss_environment.php handler
|
|
|
|
*/
|
2008-11-18 02:48:37 +01:00
|
|
|
if(defined('SS_ENVIRONMENT_FILE')) {
|
2012-09-26 23:34:00 +02:00
|
|
|
// Only perform valdiation if SS_ENVIRONMENT_FILE is actually set, which is to say, there is an
|
|
|
|
// _ss_environment.php file
|
2008-11-18 02:48:37 +01:00
|
|
|
foreach(array(
|
|
|
|
'SS_DATABASE_PASSWORD',
|
|
|
|
'SS_DATABASE_USERNAME',
|
|
|
|
'SS_ENVIRONMENT_TYPE',) as $reqDefine) {
|
2012-09-26 23:34:00 +02:00
|
|
|
if(!defined($reqDefine)) {
|
|
|
|
user_error("$reqDefine must be defined in your _ss_environment.php."
|
|
|
|
. "See http://doc.silverstripe.org/framework/en/topics/environment-management for more infomration",
|
|
|
|
E_USER_ERROR);
|
|
|
|
}
|
2008-11-18 02:48:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined('SS_ENVIRONMENT_TYPE')) {
|
|
|
|
Director::set_environment_type(SS_ENVIRONMENT_TYPE);
|
2008-01-21 09:01:30 +01:00
|
|
|
}
|
|
|
|
|
2008-11-18 02:48:37 +01:00
|
|
|
global $database;
|
|
|
|
|
|
|
|
// No database provided
|
|
|
|
if(!isset($database) || !$database) {
|
2013-04-22 14:14:32 +02:00
|
|
|
if(defined('SS_DATABASE_NAME')) {
|
|
|
|
$database = SS_DATABASE_NAME;
|
|
|
|
} else if(defined('SS_DATABASE_CHOOSE_NAME') && SS_DATABASE_CHOOSE_NAME) {
|
2009-05-20 00:16:06 +02:00
|
|
|
$loopCount = (int)SS_DATABASE_CHOOSE_NAME;
|
2010-04-13 01:15:04 +02:00
|
|
|
$databaseDir = BASE_PATH;
|
|
|
|
for($i=0;$i<$loopCount-1;$i++) $databaseDir = dirname($databaseDir);
|
2009-05-20 00:16:06 +02:00
|
|
|
$database = "SS_" . basename($databaseDir);
|
|
|
|
$database = str_replace('.','',$database);
|
2008-11-18 02:48:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined('SS_DATABASE_USERNAME') && defined('SS_DATABASE_PASSWORD')) {
|
|
|
|
global $databaseConfig;
|
|
|
|
$databaseConfig = array(
|
2009-05-27 01:45:54 +02:00
|
|
|
"type" => defined('SS_DATABASE_CLASS') ? SS_DATABASE_CLASS : "MySQLDatabase",
|
2008-11-18 02:48:37 +01:00
|
|
|
"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 : ''),
|
|
|
|
);
|
2012-03-11 20:53:01 +01:00
|
|
|
|
|
|
|
// Set the timezone if called for
|
|
|
|
if (defined('SS_DATABASE_TIMEZONE')) {
|
|
|
|
$databaseConfig['timezone'] = SS_DATABASE_TIMEZONE;
|
|
|
|
}
|
|
|
|
|
2010-11-25 04:50:11 +01:00
|
|
|
// For schema enabled drivers:
|
2012-12-08 12:20:20 +01:00
|
|
|
if(defined('SS_DATABASE_SCHEMA'))
|
|
|
|
$databaseConfig["schema"] = SS_DATABASE_SCHEMA;
|
2008-11-18 02:48:37 +01:00
|
|
|
}
|
2008-01-21 09:01:30 +01:00
|
|
|
|
|
|
|
if(defined('SS_SEND_ALL_EMAILS_TO')) {
|
2013-01-10 00:33:20 +01:00
|
|
|
Config::inst()->update("Email","send_all_emails_to", SS_SEND_ALL_EMAILS_TO);
|
2008-01-21 09:01:30 +01:00
|
|
|
}
|
2011-03-02 06:23:07 +01:00
|
|
|
if(defined('SS_SEND_ALL_EMAILS_FROM')) {
|
|
|
|
Config::inst()->update("Email","send_all_emails_from", SS_SEND_ALL_EMAILS_FROM);
|
|
|
|
}
|
2008-02-10 23:58:58 +01:00
|
|
|
|
|
|
|
if(defined('SS_DEFAULT_ADMIN_USERNAME')) {
|
2012-09-26 23:34:00 +02:00
|
|
|
if(!defined('SS_DEFAULT_ADMIN_PASSWORD')) {
|
|
|
|
user_error("SS_DEFAULT_ADMIN_PASSWORD must be defined in your _ss_environment.php,"
|
|
|
|
. "if SS_DEFAULT_ADMIN_USERNAME is defined. See "
|
|
|
|
. "http://doc.silverstripe.org/framework/en/topics/environment-management for more infomration",
|
|
|
|
E_USER_ERROR);
|
|
|
|
}
|
2008-02-10 23:58:58 +01:00
|
|
|
Security::setDefaultAdmin(SS_DEFAULT_ADMIN_USERNAME, SS_DEFAULT_ADMIN_PASSWORD);
|
|
|
|
}
|
2009-03-04 04:44:11 +01:00
|
|
|
if(defined('SS_USE_BASIC_AUTH') && SS_USE_BASIC_AUTH) {
|
2009-11-15 22:24:58 +01:00
|
|
|
BasicAuth::protect_entire_site();
|
2009-03-04 04:44:11 +01:00
|
|
|
}
|
2008-08-11 06:41:54 +02:00
|
|
|
|
|
|
|
if(defined('SS_ERROR_LOG')) {
|
2010-04-13 01:14:36 +02:00
|
|
|
SS_Log::add_writer(new SS_LogFileWriter(BASE_PATH . '/' . SS_ERROR_LOG), SS_Log::WARN, '<=');
|
2009-03-04 04:44:11 +01:00
|
|
|
}
|