diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 3453b2a..a95ba44 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -1,7 +1,6 @@ setParameter('database.info', $databases); + } } $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on'; @@ -2241,14 +2243,14 @@ function _drupal_bootstrap_configuration() { drupal_environment_initialize(); // Start a page timer: timer_start('page'); + // Activate the class loader. + drupal_classloader(); // Initialize the configuration, including variables from settings.php. drupal_settings_initialize(); // Make sure we are using the test database prefix in child Drupal sites. _drupal_initialize_db_test_prefix(); - // Activate the class loader. - drupal_classloader(); // Load the procedural configuration system helper functions. require_once DRUPAL_ROOT . '/core/includes/config.inc'; @@ -2323,7 +2325,8 @@ function _drupal_initialize_db_test_prefix() { $test_info['test_run_id'] = $test_prefix; $test_info['in_child_site'] = TRUE; - foreach ($GLOBALS['databases']['default'] as &$value) { + $databases = drupal_container()->getParameter('database.info'); + foreach ($databases['default'] as &$value) { // Extract the current default database prefix. if (!isset($value['prefix'])) { $current_prefix = ''; @@ -2340,6 +2343,7 @@ function _drupal_initialize_db_test_prefix() { 'default' => $current_prefix . $test_prefix, ); } + drupal_container()->setParameter('database.info', $databases); } } @@ -2350,12 +2354,11 @@ function _drupal_bootstrap_database() { // Redirect the user to the installation script if Drupal has not been // installed yet (i.e., if no $databases array has been defined in the // settings.php file) and we are not already installing. - if (empty($GLOBALS['databases']) && !drupal_installation_attempted()) { + if (!drupal_container()->hasParameter('database.info') && !drupal_installation_attempted()) { include_once DRUPAL_ROOT . '/core/includes/install.inc'; install_goto('core/install.php'); } - // Initialize the database system. Note that the connection // won't be initialized until it is actually requested. require_once DRUPAL_ROOT . '/core/includes/database.inc'; @@ -2440,6 +2443,7 @@ function drupal_container(Container $new_container = NULL, $rebuild = FALSE) { $container ->register('config.cachedstorage.storage', 'Drupal\Core\Config\FileStorage') ->addArgument(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY)); + // @todo Replace this with a cache.factory service plus 'config' argument. $container ->register('cache.config') @@ -2447,6 +2451,21 @@ function drupal_container(Container $new_container = NULL, $rebuild = FALSE) { ->setFactoryMethod('get') ->addArgument('config'); + // This will be overridden by settings.php in drupal_settings_initialize(). + $container->setParameter('database.info', array()); + $container->register('database_manager', 'Drupal\Core\Database\Database') + ->addArgument('%database.info%'); + + $container->register('database', 'Drupal\Core\Database\Connection') + ->setFactoryService('database_manager') + ->setFactoryMethod('getConnection') + ->addArgument('default'); + $container->register('database.slave', 'Drupal\Core\Database\Connection') + ->setFactoryService('database_manager') + ->setFactoryMethod('getConnection') + ->addArgument('slave'); + + $container ->register('config.storage', 'Drupal\Core\Config\CachedStorage') ->addArgument(new Reference('config.cachedstorage.storage')) diff --git a/core/includes/common.inc b/core/includes/common.inc index 0f252ca..7ce43db 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -4809,10 +4809,10 @@ function drupal_json_decode($var) { * A salt based on information in settings.php, not in the database. */ function drupal_get_hash_salt() { - global $drupal_hash_salt, $databases; + global $drupal_hash_salt; // If the $drupal_hash_salt variable is empty, a hash of the serialized // database credentials is used as a fallback salt. - return empty($drupal_hash_salt) ? hash('sha256', serialize($databases)) : $drupal_hash_salt; + return empty($drupal_hash_salt) ? hash('sha256', serialize(drupal_container()->getParameter('database.info'))) : $drupal_hash_salt; } /** diff --git a/core/includes/database.inc b/core/includes/database.inc index fc76b6f..aee3d7e 100644 --- a/core/includes/database.inc +++ b/core/includes/database.inc @@ -1,6 +1,5 @@ query($query, $args, $options); + $service = empty($options['target']) || $options['target'] == 'default' ? 'database' : 'database.slave'; + return drupal_container()->get($service)->query($query, $args, $options); } /** @@ -240,11 +236,8 @@ function db_query($query, array $args = array(), array $options = array()) { * @see DatabaseConnection::defaultOptions() */ function db_query_range($query, $from, $count, array $args = array(), array $options = array()) { - if (empty($options['target'])) { - $options['target'] = 'default'; - } - - return Database::getConnection($options['target'])->queryRange($query, $from, $count, $args, $options); + $service = empty($options['target']) || $options['target'] == 'default' ? 'database' : 'database.slave'; + return drupal_container()->get($service)->queryRange($query, $from, $count, $args, $options); } /** @@ -270,11 +263,8 @@ function db_query_range($query, $from, $count, array $args = array(), array $opt * @see DatabaseConnection::defaultOptions() */ function db_query_temporary($query, array $args = array(), array $options = array()) { - if (empty($options['target'])) { - $options['target'] = 'default'; - } - - return Database::getConnection($options['target'])->queryTemporary($query, $args, $options); + $service = empty($options['target']) || $options['target'] == 'default' ? 'database' : 'database.slave'; + return drupal_container()->get($service)->queryTemporary($query, $args, $options); } /** @@ -289,10 +279,8 @@ function db_query_temporary($query, array $args = array(), array $options = arra * A new InsertQuery object for this connection. */ function db_insert($table, array $options = array()) { - if (empty($options['target']) || $options['target'] == 'slave') { - $options['target'] = 'default'; - } - return Database::getConnection($options['target'])->insert($table, $options); + $service = empty($options['target']) || $options['target'] == 'default' ? 'database' : 'database.slave'; + return drupal_container()->get($service)->insert($table, $options); } /** @@ -307,10 +295,8 @@ function db_insert($table, array $options = array()) { * A new MergeQuery object for this connection. */ function db_merge($table, array $options = array()) { - if (empty($options['target']) || $options['target'] == 'slave') { - $options['target'] = 'default'; - } - return Database::getConnection($options['target'])->merge($table, $options); + $service = empty($options['target']) || $options['target'] == 'default' ? 'database' : 'database.slave'; + return drupal_container()->get($service)->merge($table, $options); } /** @@ -325,10 +311,8 @@ function db_merge($table, array $options = array()) { * A new UpdateQuery object for this connection. */ function db_update($table, array $options = array()) { - if (empty($options['target']) || $options['target'] == 'slave') { - $options['target'] = 'default'; - } - return Database::getConnection($options['target'])->update($table, $options); + $service = empty($options['target']) || $options['target'] == 'default' ? 'database' : 'database.slave'; + return drupal_container()->get($service)->update($table, $options); } /** @@ -343,10 +327,8 @@ function db_update($table, array $options = array()) { * A new DeleteQuery object for this connection. */ function db_delete($table, array $options = array()) { - if (empty($options['target']) || $options['target'] == 'slave') { - $options['target'] = 'default'; - } - return Database::getConnection($options['target'])->delete($table, $options); + $service = empty($options['target']) || $options['target'] == 'default' ? 'database' : 'database.slave'; + return drupal_container()->get($service)->delete($table, $options); } /** @@ -361,10 +343,8 @@ function db_delete($table, array $options = array()) { * A new TruncateQuery object for this connection. */ function db_truncate($table, array $options = array()) { - if (empty($options['target']) || $options['target'] == 'slave') { - $options['target'] = 'default'; - } - return Database::getConnection($options['target'])->truncate($table, $options); + $service = empty($options['target']) || $options['target'] == 'default' ? 'database' : 'database.slave'; + return drupal_container()->get($service)->truncate($table, $options); } /** @@ -382,10 +362,8 @@ function db_truncate($table, array $options = array()) { * A new SelectQuery object for this connection. */ function db_select($table, $alias = NULL, array $options = array()) { - if (empty($options['target'])) { - $options['target'] = 'default'; - } - return Database::getConnection($options['target'])->select($table, $alias, $options); + $service = empty($options['target']) || $options['target'] == 'default' ? 'database' : 'database.slave'; + return drupal_container()->get($service)->select($table, $alias, $options); } /** @@ -401,10 +379,8 @@ function db_select($table, $alias = NULL, array $options = array()) { * A new DatabaseTransaction object for this connection. */ function db_transaction($name = NULL, array $options = array()) { - if (empty($options['target'])) { - $options['target'] = 'default'; - } - return Database::getConnection($options['target'])->startTransaction($name); + $service = empty($options['target']) || $options['target'] == 'default' ? 'database' : 'database.slave'; + return drupal_container()->get($service)->startTransaction($name); } /** @@ -417,7 +393,7 @@ function db_transaction($name = NULL, array $options = array()) { * The key of the formerly active database. */ function db_set_active($key = 'default') { - return Database::setActiveConnection($key); + return drupal_container()->get('database_manager')->setActiveConnection($key); } /** @@ -432,7 +408,7 @@ function db_set_active($key = 'default') { * The escaped table name as a string. */ function db_escape_table($table) { - return Database::getConnection()->escapeTable($table); + return drupal_container()->get('database')->escapeTable($table); } /** @@ -447,7 +423,7 @@ function db_escape_table($table) { * The escaped field name as a string. */ function db_escape_field($field) { - return Database::getConnection()->escapeField($field); + return drupal_container()->get('database_manager')->escapeField($field); } /** @@ -481,7 +457,7 @@ function db_escape_field($field) { * The escaped string. */ function db_like($string) { - return Database::getConnection()->escapeLike($string); + return drupal_container()->get('database')->escapeLike($string); } /** @@ -491,7 +467,7 @@ function db_like($string) { * The name of the currently active database driver. */ function db_driver() { - return Database::getConnection()->driver(); + return drupal_container()->get('database')->driver(); } /** @@ -505,7 +481,7 @@ function db_close(array $options = array()) { if (empty($options['target'])) { $options['target'] = NULL; } - Database::closeConnection($options['target']); + drupal_container()->get('database_manager')->closeConnection($options['target']); } /** @@ -524,7 +500,7 @@ function db_close(array $options = array()) { * An integer number larger than any number returned before for this sequence. */ function db_next_id($existing_id = 0) { - return Database::getConnection()->nextId($existing_id); + return drupal_container()->get('database')->nextId($existing_id); } /** @@ -587,7 +563,7 @@ function db_condition($conjunction) { * A Schema API table definition array. */ function db_create_table($name, $table) { - return Database::getConnection()->schema()->createTable($name, $table); + return drupal_container()->get('database')->schema()->createTable($name, $table); } /** @@ -603,7 +579,7 @@ function db_create_table($name, $table) { * An array of field names. */ function db_field_names($fields) { - return Database::getConnection()->schema()->fieldNames($fields); + return drupal_container()->get('database')->schema()->fieldNames($fields); } /** @@ -618,7 +594,7 @@ function db_field_names($fields) { * TRUE if the given index exists, otherwise FALSE. */ function db_index_exists($table, $name) { - return Database::getConnection()->schema()->indexExists($table, $name); + return drupal_container()->get('database')->schema()->indexExists($table, $name); } /** @@ -631,7 +607,7 @@ function db_index_exists($table, $name) { * TRUE if the given table exists, otherwise FALSE. */ function db_table_exists($table) { - return Database::getConnection()->schema()->tableExists($table); + return drupal_container()->get('database')->schema()->tableExists($table); } /** @@ -646,7 +622,7 @@ function db_table_exists($table) { * TRUE if the given column exists, otherwise FALSE. */ function db_field_exists($table, $field) { - return Database::getConnection()->schema()->fieldExists($table, $field); + return drupal_container()->get('database')->schema()->fieldExists($table, $field); } /** @@ -660,11 +636,11 @@ function db_field_exists($table, $field) { * Array, both the keys and the values are the matching tables. */ function db_find_tables($table_expression) { - return Database::getConnection()->schema()->findTables($table_expression); + return drupal_container()->get('database')->schema()->findTables($table_expression); } function _db_create_keys_sql($spec) { - return Database::getConnection()->schema()->createKeysSql($spec); + return drupal_container()->get('database')->schema()->createKeysSql($spec); } /** @@ -676,7 +652,7 @@ function _db_create_keys_sql($spec) { * The new name for the table. */ function db_rename_table($table, $new_name) { - return Database::getConnection()->schema()->renameTable($table, $new_name); + return drupal_container()->get('database')->schema()->renameTable($table, $new_name); } /** @@ -686,7 +662,7 @@ function db_rename_table($table, $new_name) { * The table to be dropped. */ function db_drop_table($table) { - return Database::getConnection()->schema()->dropTable($table); + return drupal_container()->get('database')->schema()->dropTable($table); } /** @@ -711,7 +687,7 @@ function db_drop_table($table) { * @see db_change_field() */ function db_add_field($table, $field, $spec, $keys_new = array()) { - return Database::getConnection()->schema()->addField($table, $field, $spec, $keys_new); + return drupal_container()->get('database')->schema()->addField($table, $field, $spec, $keys_new); } /** @@ -723,7 +699,7 @@ function db_add_field($table, $field, $spec, $keys_new = array()) { * The field to be dropped. */ function db_drop_field($table, $field) { - return Database::getConnection()->schema()->dropField($table, $field); + return drupal_container()->get('database')->schema()->dropField($table, $field); } /** @@ -737,7 +713,7 @@ function db_drop_field($table, $field) { * Default value to be set. NULL for 'default NULL'. */ function db_field_set_default($table, $field, $default) { - return Database::getConnection()->schema()->fieldSetDefault($table, $field, $default); + return drupal_container()->get('database')->schema()->fieldSetDefault($table, $field, $default); } /** @@ -749,7 +725,7 @@ function db_field_set_default($table, $field, $default) { * The field to be altered. */ function db_field_set_no_default($table, $field) { - return Database::getConnection()->schema()->fieldSetNoDefault($table, $field); + return drupal_container()->get('database')->schema()->fieldSetNoDefault($table, $field); } /** @@ -761,7 +737,7 @@ function db_field_set_no_default($table, $field) { * Array of fields for the primary key. */ function db_add_primary_key($table, $fields) { - return Database::getConnection()->schema()->addPrimaryKey($table, $fields); + return drupal_container()->get('database')->schema()->addPrimaryKey($table, $fields); } /** @@ -771,7 +747,7 @@ function db_add_primary_key($table, $fields) { * Name of the table to be altered. */ function db_drop_primary_key($table) { - return Database::getConnection()->schema()->dropPrimaryKey($table); + return drupal_container()->get('database')->schema()->dropPrimaryKey($table); } /** @@ -785,7 +761,7 @@ function db_drop_primary_key($table) { * An array of field names. */ function db_add_unique_key($table, $name, $fields) { - return Database::getConnection()->schema()->addUniqueKey($table, $name, $fields); + return drupal_container()->get('database')->schema()->addUniqueKey($table, $name, $fields); } /** @@ -797,7 +773,7 @@ function db_add_unique_key($table, $name, $fields) { * The name of the key. */ function db_drop_unique_key($table, $name) { - return Database::getConnection()->schema()->dropUniqueKey($table, $name); + return drupal_container()->get('database')->schema()->dropUniqueKey($table, $name); } /** @@ -811,7 +787,7 @@ function db_drop_unique_key($table, $name) { * An array of field names. */ function db_add_index($table, $name, $fields) { - return Database::getConnection()->schema()->addIndex($table, $name, $fields); + return drupal_container()->get('database')->schema()->addIndex($table, $name, $fields); } /** @@ -823,7 +799,7 @@ function db_add_index($table, $name, $fields) { * The name of the index. */ function db_drop_index($table, $name) { - return Database::getConnection()->schema()->dropIndex($table, $name); + return drupal_container()->get('database')->schema()->dropIndex($table, $name); } /** @@ -887,7 +863,7 @@ function db_drop_index($table, $name) { * but without the 'fields' element. */ function db_change_field($table, $field, $field_new, $spec, $keys_new = array()) { - return Database::getConnection()->schema()->changeField($table, $field, $field_new, $spec, $keys_new); + return drupal_container()->get('database')->schema()->changeField($table, $field, $field_new, $spec, $keys_new); } /** @@ -898,7 +874,7 @@ function db_change_field($table, $field, $field_new, $spec, $keys_new = array()) * Sets a session variable specifying the lag time for ignoring a slave server. */ function db_ignore_slave() { - $connection_info = Database::getConnectionInfo(); + $connection_info = drupal_container()->get('database_manager')->getConnectionInfo(); // Only set ignore_slave_server if there are slave servers being used, which // is assumed if there are more than one. if (count($connection_info) > 1) { diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index da39097..cd47c9b 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -931,8 +931,9 @@ function install_verify_completed_task() { * Verifies that settings.php specifies a valid database connection. */ function install_verify_database_settings() { - global $databases; - if (!empty($databases)) { + $container = drupal_container(); + if ($container->hasParameter('database.info')) { + $databases = $container->getParameter('database.info'); $database = $databases['default']['default']; drupal_static_reset('conf_path'); $settings_file = './' . conf_path(FALSE) . '/settings.php'; @@ -955,13 +956,16 @@ function install_verify_database_settings() { * @ingroup forms */ function install_settings_form($form, &$form_state, &$install_state) { - global $databases; $profile = $install_state['parameters']['profile']; drupal_static_reset('conf_path'); $conf_path = './' . conf_path(FALSE); $settings_file = $conf_path . '/settings.php'; - $database = isset($databases['default']['default']) ? $databases['default']['default'] : array(); + $database = array(); + if (drupal_container()->hasParameter('database.info')) { + $databases = drupal_container()->getParameter('database.info'); + $database = isset($databases['default']['default']) ? $databases['default']['default'] : array(); + } drupal_set_title(st('Database configuration')); @@ -1029,6 +1033,7 @@ function install_settings_form_validate($form, &$form_state) { unset($database['db_prefix']); $form_state['storage']['database'] = $database; + drupal_container()->setParameter('database.info', array('default' => $database)); $errors = install_database_errors($database, $form_state['values']['settings_file']); foreach ($errors as $name => $message) { form_set_error($name, $message); @@ -1039,7 +1044,6 @@ function install_settings_form_validate($form, &$form_state) { * Checks a database connection and returns any errors. */ function install_database_errors($database, $settings_file) { - global $databases; $errors = array(); // Check database type. @@ -1054,14 +1058,24 @@ function install_database_errors($database, $settings_file) { // Run tasks associated with the database type. Any errors are caught in the // calling function. - $databases['default']['default'] = $database; // Just changing the global doesn't get the new information processed. // We need to close any active connections and tell the Database class to // re-parse $databases. - if (Database::isActiveConnection()) { - Database::closeConnection(); + if (!drupal_container()->has('database')) { + $container = drupal_container(); + $container->setParameter('database.info', array('default' => array('default' => $database))); + $container->register('database_manager', 'Drupal\Core\Database\Database') + ->addArgument('%database.info%'); + + $container->register('database', 'Drupal\Core\Database\Connection') + ->setFactoryService('database_manager') + ->setFactoryMethod('getConnection') + ->addArgument('default'); + $container->register('database.slave', 'Drupal\Core\Database\Connection') + ->setFactoryService('database_manager') + ->setFactoryMethod('getConnection') + ->addArgument('slave'); } - Database::parseConnectionInfo(); try { db_run_tasks($driver); @@ -1070,7 +1084,8 @@ function install_database_errors($database, $settings_file) { // These are generic errors, so we do not have any specific key of the // database connection array to attach them to; therefore, we just put // them in the error array with standard numeric keys. - $errors[$driver . '][0'] = $e->getMessage(); + + $errors[$driver . '][0'] = $e->getTraceAsString(); } } return $errors; diff --git a/core/includes/install.inc b/core/includes/install.inc index db92987..047f5ff 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -944,9 +944,9 @@ function db_run_tasks($driver) { * @param $driver * The name of the driver. */ -function db_installer_object($driver) { - // We cannot use Database::getConnection->getDriverClass() here, because +function db_installer_object($driver, $database = NULL) { + // We cannot use Database::getConnection()->getDriverClass() here, because // the connection object is not yet functional. $task_class = "Drupal\\Core\\Database\\Driver\\{$driver}\\Install\\Tasks"; - return new $task_class(); + return new $task_class($database); } diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackend.php b/core/lib/Drupal/Core/Cache/DatabaseBackend.php index 9ab6b11..09691f8 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseBackend.php +++ b/core/lib/Drupal/Core/Cache/DatabaseBackend.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Cache; -use Drupal\Core\Database\Database; use Exception; /** @@ -28,6 +27,8 @@ class DatabaseBackend implements CacheBackendInterface { */ protected static $tagCache = array(); + protected $connection; + /** * Implements Drupal\Core\Cache\CacheBackendInterface::__construct(). */ @@ -38,6 +39,7 @@ public function __construct($bin) { $bin = 'cache_' . $bin; } $this->bin = $bin; + $this->connection = drupal_container()->get('database'); } /** @@ -61,7 +63,7 @@ public function getMultiple(&$cids) { // is used here only due to the performance overhead we would incur // otherwise. When serving an uncached page, the overhead of using // ::select() is a much smaller proportion of the request. - $result = Database::getConnection()->query('SELECT cid, data, created, expire, serialized, tags, checksum FROM {' . Database::getConnection()->escapeTable($this->bin) . '} WHERE cid IN (:cids)', array(':cids' => $cids)); + $result = $this->connection->query('SELECT cid, data, created, expire, serialized, tags, checksum FROM {' . $this->connection->escapeTable($this->bin) . '} WHERE cid IN (:cids)', array(':cids' => $cids)); $cache = array(); foreach ($result as $item) { $item = $this->prepareItem($item); @@ -134,7 +136,7 @@ public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANEN } try { - Database::getConnection()->merge($this->bin) + $this->connection->merge($this->bin) ->key(array('cid' => $cid)) ->fields($fields) ->execute(); @@ -148,7 +150,7 @@ public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANEN * Implements Drupal\Core\Cache\CacheBackendInterface::delete(). */ public function delete($cid) { - Database::getConnection()->delete($this->bin) + $this->connection->delete($this->bin) ->condition('cid', $cid) ->execute(); } @@ -159,7 +161,7 @@ public function delete($cid) { public function deleteMultiple(array $cids) { // Delete in chunks when a large array is passed. do { - Database::getConnection()->delete($this->bin) + $this->connection->delete($this->bin) ->condition('cid', array_splice($cids, 0, 1000), 'IN') ->execute(); } @@ -170,14 +172,14 @@ public function deleteMultiple(array $cids) { * Implements Drupal\Core\Cache\CacheBackendInterface::flush(). */ public function flush() { - Database::getConnection()->truncate($this->bin)->execute(); + $this->connection->truncate($this->bin)->execute(); } /** * Implements Drupal\Core\Cache\CacheBackendInterface::expire(). */ public function expire() { - Database::getConnection()->delete($this->bin) + $this->connection->delete($this->bin) ->condition('expire', CacheBackendInterface::CACHE_PERMANENT, '<>') ->condition('expire', REQUEST_TIME, '<') ->execute(); @@ -240,7 +242,7 @@ protected function flattenTags(array $tags) { public function invalidateTags(array $tags) { foreach ($this->flattenTags($tags) as $tag) { unset(self::$tagCache[$tag]); - Database::getConnection()->merge('cache_tags') + $this->connection->merge('cache_tags') ->key(array('tag' => $tag)) ->fields(array('invalidations' => 1)) ->expression('invalidations', 'invalidations + 1') @@ -271,7 +273,7 @@ protected function checksumTags($tags) { } if ($query_tags) { try { - if ($db_tags = Database::getConnection()->query('SELECT tag, invalidations FROM {cache_tags} WHERE tag IN (:tags)', array(':tags' => $query_tags))->fetchAllKeyed()) { + if ($db_tags = $this->connection->query('SELECT tag, invalidations FROM {cache_tags} WHERE tag IN (:tags)', array(':tags' => $query_tags))->fetchAllKeyed()) { self::$tagCache = array_merge(self::$tagCache, $db_tags); $checksum += array_sum($db_tags); } @@ -288,7 +290,7 @@ protected function checksumTags($tags) { */ public function isEmpty() { $this->garbageCollection(); - $query = Database::getConnection()->select($this->bin); + $query = $this->connection->select($this->bin); $query->addExpression('1'); $result = $query->range(0, 1) ->execute() diff --git a/core/lib/Drupal/Core/Cache/InstallBackend.php b/core/lib/Drupal/Core/Cache/InstallBackend.php index e23294a..7e0dbef 100644 --- a/core/lib/Drupal/Core/Cache/InstallBackend.php +++ b/core/lib/Drupal/Core/Cache/InstallBackend.php @@ -34,6 +34,21 @@ class InstallBackend extends DatabaseBackend { /** + * Overrides Drupal\Core\Cache\DatabaseBackend::__construct(). + */ + public function __construct($bin) { + // All cache tables should be prefixed with 'cache_', except for the + // default 'cache' bin. + if ($bin != 'cache') { + $bin = 'cache_' . $bin; + } + $this->bin = $bin; + if (drupal_container()->has('database')) { + $this->connection = drupal_container()->get('database'); + } + } + + /** * Overrides Drupal\Core\Cache\DatabaseBackend::get(). */ public function get($cid) { @@ -57,7 +72,7 @@ public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANEN */ public function delete($cid) { try { - if (class_exists('Drupal\Core\Database\Database')) { + if ($this->connection) { parent::delete($cid); } } @@ -69,7 +84,7 @@ public function delete($cid) { */ public function deleteMultiple(array $cids) { try { - if (class_exists('Drupal\Core\Database\Database')) { + if ($this->connection) { parent::deleteMultiple($cids); } } @@ -81,7 +96,7 @@ public function deleteMultiple(array $cids) { */ public function invalidateTags(array $tags) { try { - if (class_exists('Drupal\Core\Database\Database')) { + if ($this->connection) { parent::invalidateTags($tags); } } @@ -93,7 +108,7 @@ public function invalidateTags(array $tags) { */ public function flush() { try { - if (class_exists('Drupal\Core\Database\Database')) { + if ($this->connection) { parent::flush(); } } @@ -105,7 +120,7 @@ public function flush() { */ public function expire() { try { - if (class_exists('Drupal\Core\Database\Database')) { + if ($this->connection) { parent::expire(); } } @@ -117,7 +132,7 @@ public function expire() { */ public function garbageCollection() { try { - if (class_exists('Drupal\Core\Database\Database')) { + if ($this->connection) { parent::garbageCollection(); } } @@ -129,7 +144,7 @@ public function garbageCollection() { */ public function isEmpty() { try { - if (class_exists('Drupal\Core\Database\Database')) { + if ($this->connection) { return parent::isEmpty(); } } diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index f1e43d6..89435ad 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -46,14 +46,6 @@ public function build(ContainerBuilder $container) { $container->register('language_manager', 'Drupal\Core\Language\LanguageManager') ->addArgument(new Reference('request')) ->setScope('request'); - $container->register('database', 'Drupal\Core\Database\Connection') - ->setFactoryClass('Drupal\Core\Database\Database') - ->setFactoryMethod('getConnection') - ->addArgument('default'); - $container->register('database.slave', 'Drupal\Core\Database\Connection') - ->setFactoryClass('Drupal\Core\Database\Database') - ->setFactoryMethod('getConnection') - ->addArgument('slave'); $container->register('typed_data', 'Drupal\Core\TypedData\TypedDataManager'); // Add the user's storage for temporary, non-cache data. $container->register('lock', 'Drupal\Core\Lock\DatabaseLockBackend'); @@ -73,7 +65,7 @@ public function build(ContainerBuilder $container) { $matcher->add(new \Drupal\Core\LegacyUrlMatcher()); $nested = new \Drupal\Core\Routing\NestedMatcher(); - $nested->setInitialMatcher(new \Drupal\Core\Routing\PathMatcher(Database::getConnection())); + $nested->setInitialMatcher(new \Drupal\Core\Routing\PathMatcher(drupal_container()->get('database'))); $nested->addPartialMatcher(new \Drupal\Core\Routing\HttpMethodMatcher()); $nested->setFinalMatcher(new \Drupal\Core\Routing\FirstEntryFinalMatcher()); $matcher->add($nested, 5); diff --git a/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php index 25fe8fa..78877ee 100644 --- a/core/lib/Drupal/Core/Database/Database.php +++ b/core/lib/Drupal/Core/Database/Database.php @@ -9,12 +9,8 @@ /** * Primary front-controller for the database system. - * - * This class is uninstantiatable and un-extendable. It acts to encapsulate - * all control and shepherding of database connections into a single location - * without the use of globals. */ -abstract class Database { +class Database { /** * Flag to indicate a query call should simply return NULL. @@ -45,28 +41,28 @@ * * @var array */ - static protected $connections = array(); + protected $connections = array(); /** * A processed copy of the database connection information from settings.php. * * @var array */ - static protected $databaseInfo = NULL; + protected $databaseInfo = NULL; /** * A list of key/target credentials to simply ignore. * * @var array */ - static protected $ignoreTargets = array(); + protected $ignoreTargets = array(); /** * The key of the currently active database connection. * * @var string */ - static protected $activeKey = 'default'; + protected $activeKey = 'default'; /** * An array of active query log objects. @@ -80,7 +76,11 @@ * * @var array */ - static protected $logs = array(); + protected $logs = array(); + + public function __construct(array $database_info) { + $this->parseConnectionInfo($database_info); + } /** * Starts logging a given logging key on the specified connection. @@ -97,21 +97,21 @@ * * @see Drupal\Core\Database\Log */ - final public static function startLog($logging_key, $key = 'default') { - if (empty(self::$logs[$key])) { - self::$logs[$key] = new Log($key); + final public function startLog($logging_key, $key = 'default') { + if (empty($this->logs[$key])) { + $this->logs[$key] = new Log($key); // Every target already active for this connection key needs to have the // logging object associated with it. - if (!empty(self::$connections[$key])) { - foreach (self::$connections[$key] as $connection) { - $connection->setLogger(self::$logs[$key]); + if (!empty($this->connections[$key])) { + foreach ($this->connections[$key] as $connection) { + $connection->setLogger($this->logs[$key]); } } } - self::$logs[$key]->start($logging_key); - return self::$logs[$key]; + $this->logs[$key]->start($logging_key); + return $this->logs[$key]; } /** @@ -132,19 +132,19 @@ * * @see Drupal\Core\Database\Log */ - final public static function getLog($logging_key, $key = 'default') { - if (empty(self::$logs[$key])) { + final public function getLog($logging_key, $key = 'default') { + if (empty($this->logs[$key])) { return NULL; } - $queries = self::$logs[$key]->get($logging_key); - self::$logs[$key]->end($logging_key); + $queries = $this->logs[$key]->get($logging_key); + $this->logs[$key]->end($logging_key); return $queries; } /** * Gets the connection object for the specified database key and target. * - * @param $target + * @param string $target * The database target name. * @param $key * The database connection key. Defaults to NULL which means the active key. @@ -152,25 +152,26 @@ * @return Drupal\Core\Database\Connection * The corresponding connection object. */ - final public static function getConnection($target = 'default', $key = NULL) { + final public function getConnection($target = 'default', $key = NULL) { + if (!isset($key)) { // By default, we want the active connection, set in setActiveConnection. - $key = self::$activeKey; + $key = $this->activeKey; } // If the requested target does not exist, or if it is ignored, we fall back // to the default target. The target is typically either "default" or // "slave", indicating to use a slave SQL server if one is available. If // it's not available, then the default/master server is the correct server // to use. - if (!empty(self::$ignoreTargets[$key][$target]) || !isset(self::$databaseInfo[$key][$target])) { + if (!empty($this->ignoreTargets[$key][$target]) || !isset($this->databaseInfo[$key][$target])) { $target = 'default'; } - if (!isset(self::$connections[$key][$target])) { + if (!isset($this->connections[$key][$target])) { // If necessary, a new connection is opened. - self::$connections[$key][$target] = self::openConnection($key, $target); + $this->connections[$key][$target] = self::openConnection($key, $target); } - return self::$connections[$key][$target]; + return $this->connections[$key][$target]; } /** @@ -183,8 +184,8 @@ * TRUE if there is at least one database connection established, FALSE * otherwise. */ - final public static function isActiveConnection() { - return !empty(self::$activeKey) && !empty(self::$connections) && !empty(self::$connections[self::$activeKey]); + final public function isActiveConnection() { + return !empty($this->activeKey) && !empty($this->connections) && !empty($this->connections[$this->activeKey]); } /** @@ -193,14 +194,10 @@ * @return * The previous database connection key. */ - final public static function setActiveConnection($key = 'default') { - if (empty(self::$databaseInfo)) { - self::parseConnectionInfo(); - } - - if (!empty(self::$databaseInfo[$key])) { - $old_key = self::$activeKey; - self::$activeKey = $key; + final public function setActiveConnection($key = 'default') { + if (!empty($this->databaseInfo[$key])) { + $old_key = $this->activeKey; + $this->activeKey = $key; return $old_key; } } @@ -208,10 +205,7 @@ /** * Process the configuration file for database information. */ - final public static function parseConnectionInfo() { - global $databases; - - $database_info = is_array($databases) ? $databases : array(); + final public function parseConnectionInfo($database_info) { foreach ($database_info as $index => $info) { foreach ($database_info[$index] as $target => $value) { // If there is no "driver" property, then we assume it's an array of @@ -237,8 +231,8 @@ } } - if (!is_array(self::$databaseInfo)) { - self::$databaseInfo = $database_info; + if (!is_array($this->databaseInfo)) { + $this->databaseInfo = $database_info; } // Merge the new $database_info into the existing. @@ -247,7 +241,7 @@ else { foreach ($database_info as $database_key => $database_values) { foreach ($database_values as $target => $target_values) { - self::$databaseInfo[$database_key][$target] = $target_values; + $this->databaseInfo[$database_key][$target] = $target_values; } } } @@ -273,9 +267,9 @@ * settings.php. Note that the structure of this array will depend on the * database driver it is connecting to. */ - public static function addConnectionInfo($key, $target, $info) { - if (empty(self::$databaseInfo[$key][$target])) { - self::$databaseInfo[$key][$target] = $info; + public function addConnectionInfo($key, $target, $info) { + if (empty($this->databaseInfo[$key][$target])) { + $this->databaseInfo[$key][$target] = $info; } } @@ -285,13 +279,9 @@ public static function addConnectionInfo($key, $target, $info) { * @param $connection * The connection key for which we want information. */ - final public static function getConnectionInfo($key = 'default') { - if (empty(self::$databaseInfo)) { - self::parseConnectionInfo(); - } - - if (!empty(self::$databaseInfo[$key])) { - return self::$databaseInfo[$key]; + final public function getConnectionInfo($key = 'default') { + if (!empty($this->databaseInfo[$key])) { + return $this->databaseInfo[$key]; } } @@ -305,20 +295,16 @@ public static function addConnectionInfo($key, $target, $info) { * @return * TRUE in case of success, FALSE otherwise. */ - final public static function renameConnection($old_key, $new_key) { - if (empty(self::$databaseInfo)) { - self::parseConnectionInfo(); - } - - if (!empty(self::$databaseInfo[$old_key]) && empty(self::$databaseInfo[$new_key])) { + final public function renameConnection($old_key, $new_key) { + if (!empty($this->databaseInfo[$old_key]) && empty($this->databaseInfo[$new_key])) { // Migrate the database connection information. - self::$databaseInfo[$new_key] = self::$databaseInfo[$old_key]; - unset(self::$databaseInfo[$old_key]); + $this->databaseInfo[$new_key] = $this->databaseInfo[$old_key]; + unset($this->databaseInfo[$old_key]); // Migrate over the DatabaseConnection object if it exists. - if (isset(self::$connections[$old_key])) { - self::$connections[$new_key] = self::$connections[$old_key]; - unset(self::$connections[$old_key]); + if (isset($this->connections[$old_key])) { + $this->connections[$new_key] = $this->connections[$old_key]; + unset($this->connections[$old_key]); } return TRUE; @@ -336,10 +322,10 @@ public static function addConnectionInfo($key, $target, $info) { * @return * TRUE in case of success, FALSE otherwise. */ - final public static function removeConnection($key) { - if (isset(self::$databaseInfo[$key])) { + final public function removeConnection($key) { + if (isset($this->databaseInfo[$key])) { self::closeConnection(NULL, $key); - unset(self::$databaseInfo[$key]); + unset($this->databaseInfo[$key]); return TRUE; } else { @@ -359,30 +345,30 @@ public static function addConnectionInfo($key, $target, $info) { * @throws Drupal\Core\Database\ConnectionNotDefinedException * @throws Drupal\Core\Database\DriverNotSpecifiedException */ - final protected static function openConnection($key, $target) { - if (empty(self::$databaseInfo)) { - self::parseConnectionInfo(); + final protected function openConnection($key, $target, $database_info = array()) { + if (empty($this->databaseInfo)) { + self::parseConnectionInfo($database_info); } // If the requested database does not exist then it is an unrecoverable // error. - if (!isset(self::$databaseInfo[$key])) { + if (!isset($this->databaseInfo[$key])) { throw new ConnectionNotDefinedException('The specified database connection is not defined: ' . $key); } - if (!$driver = self::$databaseInfo[$key][$target]['driver']) { + if (!$driver = $this->databaseInfo[$key][$target]['driver']) { throw new DriverNotSpecifiedException('Driver not specified for this database connection: ' . $key); } $driver_class = "Drupal\\Core\\Database\\Driver\\{$driver}\\Connection"; - $new_connection = new $driver_class(self::$databaseInfo[$key][$target]); + $new_connection = new $driver_class($this->databaseInfo[$key][$target]); $new_connection->setTarget($target); $new_connection->setKey($key); // If we have any active logging objects for this connection key, we need // to associate them with the connection we just opened. - if (!empty(self::$logs[$key])) { - $new_connection->setLogger(self::$logs[$key]); + if (!empty($this->logs[$key])) { + $new_connection->setLogger($this->logs[$key]); } return $new_connection; @@ -397,30 +383,30 @@ public static function addConnectionInfo($key, $target, $info) { * @param $key * The database connection key. Defaults to NULL which means the active key. */ - public static function closeConnection($target = NULL, $key = NULL) { + public function closeConnection($target = NULL, $key = NULL) { // Gets the active connection by default. if (!isset($key)) { - $key = self::$activeKey; + $key = $this->activeKey; } // To close a connection, it needs to be set to NULL and removed from the - // static variable. In all cases, closeConnection() might be called for a + // variable. In all cases, closeConnection() might be called for a // connection that was not opened yet, in which case the key is not defined // yet and we just ensure that the connection key is undefined. if (isset($target)) { - if (isset(self::$connections[$key][$target])) { - self::$connections[$key][$target]->destroy(); - self::$connections[$key][$target] = NULL; + if (isset($this->connections[$key][$target])) { + $this->connections[$key][$target]->destroy(); + $this->connections[$key][$target] = NULL; } - unset(self::$connections[$key][$target]); + unset($this->connections[$key][$target]); } else { - if (isset(self::$connections[$key])) { - foreach (self::$connections[$key] as $target => $connection) { - self::$connections[$key][$target]->destroy(); - self::$connections[$key][$target] = NULL; + if (isset($this->connections[$key])) { + foreach ($this->connections[$key] as $target => $connection) { + $this->connections[$key][$target]->destroy(); + $this->connections[$key][$target] = NULL; } } - unset(self::$connections[$key]); + unset($this->connections[$key]); } } @@ -436,7 +422,7 @@ public static function closeConnection($target = NULL, $key = NULL) { * @param $target * The target of the specified key to ignore. */ - public static function ignoreTarget($key, $target) { - self::$ignoreTargets[$key][$target] = TRUE; + public function ignoreTarget($key, $target) { + $this->ignoreTargets[$key][$target] = TRUE; } } diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php index d88633f..8788531 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php @@ -48,7 +48,7 @@ protected function getPrefixInfo($table = 'default', $add_prefix = TRUE) { $info['table'] = substr($table, ++$pos); } else { - $db_info = Database::getConnectionInfo(); + $db_info = drupal_container()->get('database_manager')->getConnectionInfo(); $info['database'] = $db_info['default']['database']; $info['table'] = $table; } diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php index 6dc40a2..2ca1270 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php @@ -73,7 +73,7 @@ protected function checkEncoding() { function checkBinaryOutput() { // PostgreSQL < 9 doesn't support bytea_output, so verify we are running // at least PostgreSQL 9. - $database_connection = Database::getConnection(); + $database_connection = drupal_container()->get('database'); if (version_compare($database_connection->version(), '9') >= 0) { if (!$this->checkBinaryOutputSuccess()) { // First try to alter the database. If it fails, raise an error telling diff --git a/core/lib/Drupal/Core/Database/Install/Tasks.php b/core/lib/Drupal/Core/Database/Install/Tasks.php index 5d34a62..d72c744 100644 --- a/core/lib/Drupal/Core/Database/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Install/Tasks.php @@ -7,8 +7,6 @@ namespace Drupal\Core\Database\Install; -use Drupal\Core\Database\Database; - use PDO; use Exception; @@ -160,10 +158,7 @@ public function runTasks() { */ protected function connect() { try { - // This doesn't actually test the connection. - db_set_active(); - // Now actually do a check. - Database::getConnection(); + drupal_container()->get('database'); $this->pass('Drupal can CONNECT to the database ok.'); } catch (Exception $e) { @@ -191,8 +186,8 @@ protected function runTestQuery($query, $pass, $fail, $fatal = FALSE) { * Check the engine version. */ protected function checkEngineVersion() { - if ($this->minimumVersion() && version_compare(Database::getConnection()->version(), $this->minimumVersion(), '<')) { - $this->fail(st("The database version %version is less than the minimum required version %minimum_version.", array('%version' => Database::getConnection()->version(), '%minimum_version' => $this->minimumVersion()))); + if ($this->minimumVersion() && version_compare(drupal_container()->get('database')->version(), $this->minimumVersion(), '<')) { + $this->fail(st("The database version %version is less than the minimum required version %minimum_version.", array('%version' => drupal_container()->get('database')->version(), '%minimum_version' => $this->minimumVersion()))); } } diff --git a/core/lib/Drupal/Core/Database/Query/Query.php b/core/lib/Drupal/Core/Database/Query/Query.php index 95ab4b9..01128d7 100644 --- a/core/lib/Drupal/Core/Database/Query/Query.php +++ b/core/lib/Drupal/Core/Database/Query/Query.php @@ -94,7 +94,7 @@ public function __sleep() { * Implements the magic __wakeup function to reconnect to the database. */ public function __wakeup() { - $this->connection = Database::getConnection($this->connectionTarget, $this->connectionKey); + $this->connection = drupal_container()->get('database_manager')->getConnection($this->connectionTarget, $this->connectionKey); } /** diff --git a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php index 0ce7934..f232414 100644 --- a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php +++ b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php @@ -53,7 +53,7 @@ class DatabaseStorageExpirable extends DatabaseStorage implements KeyValueStoreE */ public function __construct($collection, array $options = array()) { parent::__construct($collection, $options); - $this->connection = isset($options['connection']) ? $options['connection'] : Database::getConnection(); + $this->connection = isset($options['connection']) ? $options['connection'] : drupal_container()->get('database'); $this->table = isset($options['table']) ? $options['table'] : 'key_value_expire'; } diff --git a/core/lib/Drupal/Core/Routing/MatcherDumper.php b/core/lib/Drupal/Core/Routing/MatcherDumper.php index 48b2d8c..946a774 100644 --- a/core/lib/Drupal/Core/Routing/MatcherDumper.php +++ b/core/lib/Drupal/Core/Routing/MatcherDumper.php @@ -47,7 +47,7 @@ class MatcherDumper implements MatcherDumperInterface { /** * Construct the MatcherDumper. * - * @param Drupal\Core\Database\Connection $connection + * @param Drupal\Core\Database\Connection $database * The database connection which will be used to store the route * information. * @param string $table diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index 2e8422f..28c7746 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -146,7 +146,7 @@ function _dblog_get_message_types() { * Note: Some values may be truncated to meet database column size restrictions. */ function dblog_watchdog(array $log_entry) { - Database::getConnection('default', 'default')->insert('watchdog') + drupal_container()->get('database')->insert('watchdog') ->fields(array( 'uid' => $log_entry['uid'], 'type' => substr($log_entry['type'], 0, 64), diff --git a/core/modules/field/modules/field_sql_storage/field_sql_storage.module b/core/modules/field/modules/field_sql_storage/field_sql_storage.module index 26b2ba8..4653b90 100644 --- a/core/modules/field/modules/field_sql_storage/field_sql_storage.module +++ b/core/modules/field/modules/field_sql_storage/field_sql_storage.module @@ -248,7 +248,7 @@ function field_sql_storage_field_storage_update_field($field, $prior_field, $has if (! $has_data) { // There is no data. Re-create the tables completely. - if (Database::getConnection()->supportsTransactionalDDL()) { + if (drupal_container()->get('database')->supportsTransactionalDDL()) { // If the database supports transactional DDL, we can go ahead and rely // on it. If not, we will have to rollback manually if something fails. $transaction = db_transaction(); @@ -265,7 +265,7 @@ function field_sql_storage_field_storage_update_field($field, $prior_field, $has } } catch (Exception $e) { - if (Database::getConnection()->supportsTransactionalDDL()) { + if (drupal_container()->get('database')->supportsTransactionalDDL()) { $transaction->rollback(); } else { diff --git a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php index 2e9070d..7914566 100644 --- a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php +++ b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php @@ -362,8 +362,8 @@ function testFieldUpdateIndexesWithData() { // Verify the indexes we will create do not exist yet. foreach ($tables as $table) { - $this->assertFalse(Database::getConnection()->schema()->indexExists($table, 'value'), t("No index named value exists in $table")); - $this->assertFalse(Database::getConnection()->schema()->indexExists($table, 'value_format'), t("No index named value_format exists in $table")); + $this->assertFalse(drupal_container()->get('database')->schema()->indexExists($table, 'value'), t("No index named value exists in $table")); + $this->assertFalse(drupal_container()->get('database')->schema()->indexExists($table, 'value_format'), t("No index named value_format exists in $table")); } // Add data so the table cannot be dropped. @@ -375,15 +375,15 @@ function testFieldUpdateIndexesWithData() { $field = array('field_name' => $field_name, 'indexes' => array('value' => array('value'))); field_update_field($field); foreach ($tables as $table) { - $this->assertTrue(Database::getConnection()->schema()->indexExists($table, "{$field_name}_value"), t("Index on value created in $table")); + $this->assertTrue(drupal_container()->get('database')->schema()->indexExists($table, "{$field_name}_value"), t("Index on value created in $table")); } // Add a different index, removing the existing custom one. $field = array('field_name' => $field_name, 'indexes' => array('value_format' => array('value', 'format'))); field_update_field($field); foreach ($tables as $table) { - $this->assertTrue(Database::getConnection()->schema()->indexExists($table, "{$field_name}_value_format"), t("Index on value_format created in $table")); - $this->assertFalse(Database::getConnection()->schema()->indexExists($table, "{$field_name}_value"), t("Index on value removed in $table")); + $this->assertTrue(drupal_container()->get('database')->schema()->indexExists($table, "{$field_name}_value_format"), t("Index on value_format created in $table")); + $this->assertFalse(drupal_container()->get('database')->schema()->indexExists($table, "{$field_name}_value"), t("Index on value removed in $table")); } // Verify that the tables were not dropped. diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 3d3ce1f..4b5ecb6 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -357,8 +357,7 @@ function locale_reset() { function locale_storage() { $storage = &drupal_static(__FUNCTION__); if (!isset($storage)) { - $options = array('target' => 'default'); - $storage = new StringDatabaseStorage(Database::getConnection($options['target']), $options); + $storage = new StringDatabaseStorage(drupal_container()->get('database')); } return $storage; } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php index 285e616..f8b1c5a 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php @@ -76,7 +76,7 @@ function testFailedPageCreation() { $this->pass(t('Expected exception has been thrown.')); } - if (Database::getConnection()->supportsTransactions()) { + if (drupal_container()->get('database')->supportsTransactions()) { // Check that the node does not exist in the database. $node = $this->drupalGetNodeByTitle($edit['title']); $this->assertFalse($node, 'Transactions supported, and node not found in database.'); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index 916cb0d..2019b76 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -136,6 +136,8 @@ */ protected $verboseDirectoryUrl; + protected static $originalContainer; + /** * Constructor for Test. * @@ -284,15 +286,12 @@ public static function deleteAssert($message_id) { * The database connection to use for inserting assertions. */ public static function getDatabaseConnection() { - try { - $connection = Database::getConnection('default', 'simpletest_original_default'); + if (!empty(self::$originalContainer)) { + return self::$originalContainer->get('database'); } - catch (ConnectionNotDefinedException $e) { - // If the test was not set up, the simpletest_original_default - // connection does not exist. - $connection = Database::getConnection('default', 'default'); + else { + return drupal_container()->get('database'); } - return $connection; } /** @@ -701,22 +700,15 @@ protected function changeDatabasePrefix() { } // Clone the current connection and replace the current prefix. - $connection_info = Database::getConnectionInfo('default'); - Database::renameConnection('default', 'simpletest_original_default'); - foreach ($connection_info as $target => $value) { - $connection_info[$target]['prefix'] = array( - 'default' => $value['prefix']['default'] . $this->databasePrefix, + $database_info = self::$originalContainer->getParameter('database.info'); + foreach ($database_info['default'] as $target => $value) { + $prefix = is_string($value['prefix']) ? $value['prefix'] : $value['prefix']['default']; + $database_info['default'][$target]['prefix'] = array( + 'default' => $prefix . $this->databasePrefix, ); } - Database::addConnectionInfo('default', 'default', $connection_info['default']); - // Additionally override global $databases, since the installer does not use - // the Database connection info. - // @see install_verify_database_settings() - // @see install_database_errors() - // @todo Fix installer to use Database connection info. - global $databases; - $databases['default']['default'] = $connection_info['default']; + $this->container->setParameter('database.info', $database_info); // Indicate the database prefix was set up correctly. $this->setupDatabasePrefix = TRUE; @@ -749,7 +741,7 @@ protected function prepareEnvironment() { $this->originalConf = $conf; // Backup statics and globals. - $this->originalContainer = clone drupal_container(); + self::$originalContainer = clone drupal_container(); $this->originalLanguage = $language_interface; $this->originalConfigDirectories = $GLOBALS['config_directories']; $this->originalThemeKey = $GLOBALS['theme_key']; @@ -847,15 +839,22 @@ protected function rebuildContainer() { // restores the original container. // @see Drupal\Core\DrupalKernel::initializeContainer() $this->kernel = new DrupalKernel('testing', FALSE); + + // The DrupalKernel does not update the container in drupal_container(), but + // replaces it with a new object. We therefore need to replace the minimal + // boostrap container that has been set up by TestBase::prepareEnvironment(). + $this->container = drupal_container(); + + // The database prefix is stored as a container parameter, rebuilding the + // container means those params are gone, so this step needs to be repeated + // every time the container is rebuilt. + $this->changeDatabasePrefix(); + // Booting the kernel is necessary to initialize the new DIC. While // normally the kernel gets booted on demand in // Symfony\Component\HttpKernel\handle(), this kernel needs manual booting // as it is not used to handle a request. $this->kernel->boot(); - // The DrupalKernel does not update the container in drupal_container(), but - // replaces it with a new object. We therefore need to replace the minimal - // boostrap container that has been set up by TestBase::prepareEnvironment(). - $this->container = drupal_container(); } /** @@ -882,9 +881,9 @@ protected function tearDown() { // entire parent site otherwise. if ($this->setupDatabasePrefix) { // Remove all prefixed tables. - $connection_info = Database::getConnectionInfo('default'); - $tables = db_find_tables($connection_info['default']['prefix']['default'] . '%'); - $prefix_length = strlen($connection_info['default']['prefix']['default']); + $database_info = $this->container->getParameter('database.info'); + $tables = db_find_tables($database_info['default']['default']['prefix']['default'] . '%'); + $prefix_length = strlen($database_info['default']['default']['prefix']['default']); foreach ($tables as $table) { if (db_drop_table(substr($table, $prefix_length))) { unset($tables[$table]); @@ -908,18 +907,14 @@ protected function tearDown() { // Delete temporary files directory. file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10), array($this, 'filePreDeleteCallback')); - // Restore original database connection. - Database::removeConnection('default'); - Database::renameConnection('simpletest_original_default', 'default'); - // @see TestBase::changeDatabasePrefix() - global $databases; - $connection_info = Database::getConnectionInfo('default'); - $databases['default']['default'] = $connection_info['default']; + // Restore the original container. + drupal_container(self::$originalContainer); // Restore original globals. $GLOBALS['theme_key'] = $this->originalThemeKey; $GLOBALS['theme'] = $this->originalTheme; + // Reset all static variables. // All destructors of statically cached objects have been invoked above; // this second reset is guranteed to reset everything to nothing. @@ -936,7 +931,7 @@ protected function tearDown() { $conf = $this->originalConf; // Restore original statics and globals. - drupal_container($this->originalContainer); + $language_interface = $this->originalLanguage; $GLOBALS['config_directories'] = $this->originalConfigDirectories; if (isset($this->originalPrefix)) { drupal_valid_test_ua($this->originalPrefix); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php index 98ed71d..4868736 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php @@ -46,6 +46,16 @@ protected function setUp() { if (!$this->setupEnvironment) { return FALSE; } + + // Change the database prefix. + // All static variables need to be reset before the database prefix is + // changed, since Drupal\Core\Utility\CacheArray implementations attempt to + // write back to persistent caches when they are destructed. + $this->changeDatabasePrefix(); + if (!$this->setupDatabasePrefix) { + return FALSE; + } + $this->originalThemeRegistry = theme_get_registry(FALSE); // Reset all statics and variables to perform tests in a clean environment. @@ -57,15 +67,6 @@ protected function setUp() { $conf['file_public_path'] = $this->public_files_directory; - // Change the database prefix. - // All static variables need to be reset before the database prefix is - // changed, since Drupal\Core\Utility\CacheArray implementations attempt to - // write back to persistent caches when they are destructed. - $this->changeDatabasePrefix(); - if (!$this->setupDatabasePrefix) { - return FALSE; - } - // Set user agent to be consistent with WebTestBase. $_SERVER['HTTP_USER_AGENT'] = $this->databasePrefix; diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index ec800d4..31f7b37 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -632,7 +632,8 @@ protected function setUp() { // Set installer parameters. // @see install.php, install.core.inc - $connection_info = Database::getConnectionInfo('default'); + $database_info = $this->container->getParameter('database.info'); + $connection_info = $database_info['default']; $this->root_user = (object) array( 'name' => 'admin', 'mail' => 'admin@example.com', diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 2388601..8549281 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -443,7 +443,7 @@ function simpletest_clean_environment() { * Removed prefixed tables from the database that are left over from crashed tests. */ function simpletest_clean_database() { - $tables = db_find_tables(Database::getConnection()->prefixTables('{simpletest}') . '%'); + $tables = db_find_tables(drupal_container()->get('database')->prefixTables('{simpletest}') . '%'); $schema = drupal_get_schema_unprocessed('simpletest'); $count = 0; foreach (array_diff_key($tables, $schema) as $table) { diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/SchemaTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/SchemaTest.php index c33d59a..dafdbc4 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/SchemaTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/SchemaTest.php @@ -73,19 +73,19 @@ function testSchema() { $this->assertFalse($this->tryInsert(), 'Insert without a default failed.'); // Test for fake index and test for the boolean result of indexExists(). - $index_exists = Database::getConnection()->schema()->indexExists('test_table', 'test_field'); + $index_exists = drupal_container()->get('database')->schema()->indexExists('test_table', 'test_field'); $this->assertIdentical($index_exists, FALSE, 'Fake index does not exists'); // Add index. db_add_index('test_table', 'test_field', array('test_field')); // Test for created index and test for the boolean result of indexExists(). - $index_exists = Database::getConnection()->schema()->indexExists('test_table', 'test_field'); + $index_exists = drupal_container()->get('database')->schema()->indexExists('test_table', 'test_field'); $this->assertIdentical($index_exists, TRUE, 'Index created.'); // Rename the table. db_rename_table('test_table', 'test_table2'); // Index should be renamed. - $index_exists = Database::getConnection()->schema()->indexExists('test_table2', 'test_field'); + $index_exists = drupal_container()->get('database')->schema()->indexExists('test_table2', 'test_field'); $this->assertTrue($index_exists, 'Index was renamed.'); // We need the default so that we can insert after the rename. @@ -167,8 +167,8 @@ function tryInsert($table = 'test_table') { * Optional column to test. */ function checkSchemaComment($description, $table, $column = NULL) { - if (method_exists(Database::getConnection()->schema(), 'getComment')) { - $comment = Database::getConnection()->schema()->getComment($table, $column); + if (method_exists(drupal_container()->get('database')->schema(), 'getComment')) { + $comment = drupal_container()->get('database')->schema()->getComment($table, $column); $this->assertEqual($comment, $description, 'The comment matches the schema description.'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/InvalidDataTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/InvalidDataTest.php index 90a9e18..92504d6 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Database/InvalidDataTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Database/InvalidDataTest.php @@ -51,7 +51,7 @@ function testInsertDuplicateData() { $name = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 63))->fetchField(); if ($name == 'Elvis') { - if (!Database::getConnection()->supportsTransactions()) { + if (!drupal_container()->get('database')->supportsTransactions()) { // This is an expected fail. // Database engines that don't support transactions can leave partial // inserts in place when an error occurs. This is the case for MySQL diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/TransactionTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/TransactionTest.php index 4d5ecf1..f756dc9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Database/TransactionTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Database/TransactionTest.php @@ -66,7 +66,7 @@ public static function getInfo() { * Whether to execute a DDL statement during the inner transaction. */ protected function transactionOuterLayer($suffix, $rollback = FALSE, $ddl_statement = FALSE) { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $depth = $connection->transactionDepth(); $txn = db_transaction(); @@ -108,7 +108,7 @@ protected function transactionOuterLayer($suffix, $rollback = FALSE, $ddl_statem * Whether to execute a DDL statement during the transaction. */ protected function transactionInnerLayer($suffix, $rollback = FALSE, $ddl_statement = FALSE) { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $depth = $connection->transactionDepth(); // Start a transaction. If we're being called from ->transactionOuterLayer, @@ -162,7 +162,7 @@ protected function transactionInnerLayer($suffix, $rollback = FALSE, $ddl_statem */ function testTransactionRollBackSupported() { // This test won't work right if transactions are not supported. - if (!Database::getConnection()->supportsTransactions()) { + if (!drupal_container()->get('database')->supportsTransactions()) { return; } try { @@ -188,7 +188,7 @@ function testTransactionRollBackSupported() { */ function testTransactionRollBackNotSupported() { // This test won't work right if transactions are supported. - if (Database::getConnection()->supportsTransactions()) { + if (drupal_container()->get('database')->supportsTransactions()) { return; } try { @@ -274,7 +274,7 @@ function testTransactionWithDdlStatement() { $this->assertRowAbsent('row'); // The behavior of a rollback depends on the type of database server. - if (Database::getConnection()->supportsTransactionalDDL()) { + if (drupal_container()->get('database')->supportsTransactionalDDL()) { // For database servers that support transactional DDL, a rollback // of a transaction including DDL statements should be possible. $this->cleanUp(); @@ -394,11 +394,11 @@ function assertRowAbsent($name, $message = NULL) { */ function testTransactionStacking() { // This test won't work right if transactions are not supported. - if (!Database::getConnection()->supportsTransactions()) { + if (!drupal_container()->get('database')->supportsTransactions()) { return; } - $database = Database::getConnection(); + $database = drupal_container()->get('database'); // Standard case: pop the inner transaction before the outer transaction. $transaction = db_transaction(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php index f23204b..00fcb61 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php @@ -42,7 +42,7 @@ function setUp() { * specified base table. Defaults to TRUE. */ function assertTableCount($base_table, $count = TRUE) { - $tables = db_find_tables(Database::getConnection()->prefixTables('{' . $base_table . '}') . '%'); + $tables = db_find_tables(drupal_container()->get('database')->prefixTables('{' . $base_table . '}') . '%'); if ($count) { return $this->assertTrue($tables, format_string('Tables matching "@base_table" found.', array('@base_table' => $base_table))); diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/MatcherDumperTest.php b/core/modules/system/lib/Drupal/system/Tests/Routing/MatcherDumperTest.php index 7f6f312..0c707da 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Routing/MatcherDumperTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Routing/MatcherDumperTest.php @@ -48,7 +48,7 @@ function setUp() { * Confirms that the dumper can be instantiated successfuly. */ function testCreate() { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $dumper= new MatcherDumper($connection); $class_name = 'Drupal\Core\Routing\MatcherDumper'; @@ -59,7 +59,7 @@ function testCreate() { * Confirms that we can add routes to the dumper. */ function testAddRoutes() { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $dumper= new MatcherDumper($connection); $route = new Route('test'); @@ -80,7 +80,7 @@ function testAddRoutes() { * Confirms that we can add routes to the dumper when it already has some. */ function testAddAdditionalRoutes() { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $dumper= new MatcherDumper($connection); $route = new Route('test'); @@ -116,7 +116,7 @@ function testAddAdditionalRoutes() { * Confirm that we can dump a route collection to the database. */ public function testDump() { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $dumper= new MatcherDumper($connection, 'test_routes'); $route = new Route('/test/{my}/path'); diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/PathMatcherTest.php b/core/modules/system/lib/Drupal/system/Tests/Routing/PathMatcherTest.php index 0780250..3c843f3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Routing/PathMatcherTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Routing/PathMatcherTest.php @@ -46,7 +46,7 @@ function __construct($test_id = NULL) { } public function tearDown() { - $this->fixtures->dropTables(Database::getConnection()); + $this->fixtures->dropTables(drupal_container()->get('database')); parent::tearDown(); } @@ -56,7 +56,7 @@ public function tearDown() { */ public function testCandidateOutlines() { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $matcher = new PathMatcher($connection); $parts = array('node', '5', 'edit'); @@ -76,7 +76,7 @@ public function testCandidateOutlines() { * Confirms that we can find routes with the exact incoming path. */ function testExactPathMatch() { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $matcher = new PathMatcher($connection, 'test_routes'); $this->fixtures->createTables($connection); @@ -100,7 +100,7 @@ function testExactPathMatch() { * Confirms that we can find routes whose pattern would match the request. */ function testOutlinePathMatch() { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $matcher = new PathMatcher($connection, 'test_routes'); $this->fixtures->createTables($connection); @@ -129,7 +129,7 @@ function testOutlinePathMatch() { * Confirms that a trailing slash on the request doesn't result in a 404. */ function testOutlinePathMatchTrailingSlash() { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $matcher = new PathMatcher($connection, 'test_routes'); $this->fixtures->createTables($connection); @@ -158,7 +158,7 @@ function testOutlinePathMatchTrailingSlash() { * Confirms that we can find routes whose pattern would match the request. */ function testOutlinePathMatchDefaults() { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $matcher = new PathMatcher($connection, 'test_routes'); $this->fixtures->createTables($connection); @@ -197,7 +197,7 @@ function testOutlinePathMatchDefaults() { * Confirms that we can find routes whose pattern would match the request. */ function testOutlinePathMatchDefaultsCollision() { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $matcher = new PathMatcher($connection, 'test_routes'); $this->fixtures->createTables($connection); @@ -237,7 +237,7 @@ function testOutlinePathMatchDefaultsCollision() { * Confirms that we can find routes whose pattern would match the request. */ function testOutlinePathMatchDefaultsCollision2() { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $matcher = new PathMatcher($connection, 'test_routes'); $this->fixtures->createTables($connection); @@ -276,7 +276,7 @@ function testOutlinePathMatchDefaultsCollision2() { * Confirms that an exception is thrown when no matching path is found. */ function testOutlinePathNoMatch() { - $connection = Database::getConnection(); + $connection = drupal_container()->get('database'); $matcher = new PathMatcher($connection, 'test_routes'); $this->fixtures->createTables($connection); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index bbd6118..14006a5 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -183,7 +183,7 @@ function system_requirements($phase) { } else { // Database information. - $class = Database::getConnection()->getDriverClass('Install\\Tasks'); + $class = drupal_container()->get('database')->getDriverClass('Install\\Tasks'); $tasks = new $class(); $requirements['database_system'] = array( 'title' => $t('Database system'), @@ -191,7 +191,7 @@ function system_requirements($phase) { ); $requirements['database_system_version'] = array( 'title' => $t('Database system version'), - 'value' => Database::getConnection()->version(), + 'value' => drupal_container()->get('database')->version(), ); } @@ -1720,7 +1720,7 @@ function system_update_8006() { */ function system_update_8007() { // Find all potential cache tables. - $tables = db_find_tables(Database::getConnection()->prefixTables('{cache}') . '%'); + $tables = db_find_tables(drupal_container()->get('database')->prefixTables('{cache}') . '%'); foreach ($tables as $table) { // Assume we have a valid cache table if there is both 'cid' and 'data' @@ -2056,7 +2056,7 @@ function system_update_8022() { 'primary key' => array('name'), ); - $schema = Database::getConnection()->schema(); + $schema = drupal_container()->get('database')->schema(); $schema->dropTable('router'); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index ea3dadc..06bb38d 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2322,7 +2322,7 @@ function system_init() { // the timestamp after which the slave can be re-enabled. if (isset($_SESSION['ignore_slave_server'])) { if ($_SESSION['ignore_slave_server'] >= REQUEST_TIME) { - Database::ignoreTarget('default', 'slave'); + drupal_container()->get('database_manager')->ignoreTarget('default', 'slave'); } else { unset($_SESSION['ignore_slave_server']); diff --git a/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php b/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php index 5fb54e3..f8c6a8b 100644 --- a/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php @@ -83,7 +83,7 @@ protected function tearDown() { */ public function testUserTempStore() { // Create a key/value collection. - $factory = new TempStoreFactory(Database::getConnection(), new DatabaseLockBackend()); + $factory = new TempStoreFactory(drupal_container()->get('database'), new DatabaseLockBackend()); $collection = $this->randomName(); // Create two mock users. diff --git a/core/update.php b/core/update.php index 2273b40..ae6546d 100644 --- a/core/update.php +++ b/core/update.php @@ -448,10 +448,6 @@ function update_check_requirements($skip_warnings = FALSE) { // @todo Remove after converting update.php to use DrupalKernel. $container = drupal_container(); -$container->register('database', 'Drupal\Core\Database\Connection') - ->setFactoryClass('Drupal\Core\Database\Database') - ->setFactoryMethod('getConnection') - ->addArgument('default'); $container->register('router.dumper', '\Drupal\Core\Routing\MatcherDumper') ->addArgument(new Reference('database')); $container->register('router.builder', 'Drupal\Core\Routing\RouteBuilder')