Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/site/app/config/database.php
diff options
context:
space:
mode:
Diffstat (limited to 'site/app/config/database.php')
-rw-r--r--site/app/config/database.php48
1 files changed, 45 insertions, 3 deletions
diff --git a/site/app/config/database.php b/site/app/config/database.php
index e5f0815..a34d481 100644
--- a/site/app/config/database.php
+++ b/site/app/config/database.php
@@ -54,10 +54,42 @@
*
* Note: Driver has been changed to amo_mysql to add support for fetching l10n data because of a problem
* caused by a CakePHP bug (https://trac.cakephp.org/ticket/1183) which as of 1.2 is not fixed.
+ *
+ *
+ * How the database is configured:
+
+ * The ConnectionManager is a singleton object that manages loading database
+ * connections according to the named configurations in app/config/database.php.
+ * When it gets instantiated, it creates an instance of our DATABASE_CONFIG so
+ * it can access the configurations as member variables. We have three
+ * configurations: $default, $test, and $shadow.
+ *
+ * cake/libs/model/connection_manager.php:ConnectionManager.__construct:
+ * $this->config = new DATABASE_CONFIG();
+ *
+ * Clients call ConnectionManager::getDataSource($name), which translates into
+ * <DATABASE_CONFIG instance>->$name. All the calls are for 'default' or
+ * 'shadow', never 'test'. Usually the $name comes from $this->useDbConfig.
+ *
+ * Once ConnectionManager has been instantiated, we're stuck with the
+ * configuration since it's bound to the instance. The easiest way to point
+ * tests at the test database is to reconfigure DATABASE_CONFIG before any
+ * instances are created.
+ *
+ * The named configurations are static class variables so they can be
+ * manipulated by the class, but that means they can't be accessed as member
+ * variables. The constructor manually binds each static var to the new
+ * instance so they're accessible on the object.
+ *
+ * AMO has two kinds of tests: unit tests and web tests. Unit tests run in
+ * same process as the test manager so switching to the test config is easy.
+ * Web tests, however, invoke real requests through the server; we can't tell
+ * that tests are running. We send an X-Amo-Test header during web testing to
+ * switch on the test database.
*/
class DATABASE_CONFIG
{
- var $default = array( 'driver' => 'amo_mysql',
+ static $default = array('driver' => 'amo_mysql',
'connect' => 'mysql_connect',
'host' => DB_HOST,
'login' => DB_USER,
@@ -66,7 +98,7 @@ class DATABASE_CONFIG
'prefix' => ''
);
- var $test = array( 'driver' => 'amo_mysql',
+ static $test = array( 'driver' => 'amo_mysql',
'connect' => 'mysql_connect',
'host' => TEST_DB_HOST,
'login' => TEST_DB_USER,
@@ -75,7 +107,7 @@ class DATABASE_CONFIG
'prefix' => ''
);
- var $shadow = array( 'driver' => 'amo_mysql',
+ static $shadow = array( 'driver' => 'amo_mysql',
'connect' => 'mysql_connect',
'host' => SHADOW_DB_HOST,
'login' => SHADOW_DB_USER,
@@ -84,5 +116,15 @@ class DATABASE_CONFIG
'prefix' => '',
'shadow' => true
);
+
+ function __construct() {
+ $this->default = self::$default;
+ $this->test = self::$test;
+ $this->shadow = self::$shadow;
+ }
+
+ function useTestConfig() {
+ self::$default = self::$test;
+ }
}
?>