diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index e94f8e1..5ff0246 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -937,7 +937,7 @@ function variable_initialize($conf = array()) { } else { // Proceed with variable rebuild. - $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed()); + $variables = drupal_container()->get('variable.storage')->getAll(); cache('bootstrap')->set('variables', $variables); lock_release($name); } @@ -993,8 +993,7 @@ function variable_get($name, $default = NULL) { function variable_set($name, $value) { global $conf; - db_merge('variable')->key(array('name' => $name))->fields(array('value' => serialize($value)))->execute(); - + drupal_container()->get('variable.storage')->set($name, $value); cache('bootstrap')->delete('variables'); $conf[$name] = $value; @@ -1016,9 +1015,7 @@ function variable_set($name, $value) { function variable_del($name) { global $conf; - db_delete('variable') - ->condition('name', $name) - ->execute(); + drupal_container()->get('variable.storage')->delete($name); cache('bootstrap')->delete('variables'); unset($conf[$name]); @@ -2480,6 +2477,9 @@ function drupal_container(Container $new_container = NULL, $rebuild = FALSE) { $container ->register('config.storage.staging', 'Drupal\Core\Config\FileStorage') ->addArgument(config_get_config_directory(CONFIG_STAGING_DIRECTORY)); + $container + ->register('variable.storage', 'Drupal\Core\KeyValueStore\DatabaseStorage') + ->addArgument('state'); } return $container; } diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 1b6c8a3..8279dd9 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -310,6 +310,9 @@ function install_begin_request(&$install_state) { $container->register('config.factory', 'Drupal\Core\Config\ConfigFactory') ->addArgument(new Reference('config.storage')) ->addArgument(new Reference('dispatcher')); + $container + ->register('variable.storage', 'Drupal\Core\KeyValueStore\DatabaseStorage') + ->addArgument('state'); drupal_container($container); } @@ -896,9 +899,7 @@ function install_base_system(&$install_state) { */ function install_verify_completed_task() { try { - if ($result = db_query("SELECT value FROM {variable} WHERE name = :name", array('name' => 'install_task'))) { - $task = unserialize($result->fetchField()); - } + $task = drupal_container()->get('variable.storage')->get('install_task'); } // Do not trigger an error if the database query fails, since the database // might not be set up yet. diff --git a/core/includes/update.inc b/core/includes/update.inc index 9dd8456..0ba009e 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -130,6 +130,34 @@ function update_prepare_d8_bootstrap() { update_extra_requirements($requirements); if ($has_required_schema) { + $schema['keyvalue'] = array( + 'description' => 'Generic key-value storage table.', + 'fields' => array( + 'name' => array( + 'description' => 'The key.', + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '', + ), + 'collection' => array( + 'description' => 'The collection of the variable.', + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '', + ), + 'value' => array( + 'description' => 'The value.', + 'type' => 'blob', + 'not null' => TRUE, + 'size' => 'big', + 'translatable' => TRUE, + ), + ), + 'primary key' => array('collection', 'name'), + ); + db_create_table('keyvalue', $schema['keyvalue']); // Bootstrap variables so we can update theme while preparing the update // process. drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES); diff --git a/core/lib/Drupal/Core/Cache/CacheFactory.php b/core/lib/Drupal/Core/Cache/CacheFactory.php index da42a26..3558533 100644 --- a/core/lib/Drupal/Core/Cache/CacheFactory.php +++ b/core/lib/Drupal/Core/Cache/CacheFactory.php @@ -43,14 +43,7 @@ class CacheFactory { * value. */ public static function getBackends() { - // @todo Improve how cache backend classes are defined. Cannot be - // configuration, since e.g. the CachedStorage config storage controller - // requires the definition in its constructor already. - global $conf; - $cache_backends = isset($conf['cache_classes']) ? $conf['cache_classes'] : array(); - // Ensure there is a default 'cache' bin definition. - $cache_backends += array('cache' => 'Drupal\Core\Cache\DatabaseBackend'); - return $cache_backends; + return variable_get('cache_classes', array('cache' => 'Drupal\Core\Cache\DatabaseBackend')); } } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index ac983aa..616cb43 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -526,28 +526,35 @@ function system_install() { * Implements hook_schema(). */ function system_schema() { - // NOTE: {variable} needs to be created before all other tables, as + // NOTE: {keyvalue} needs to be created before all other tables, as // some database drivers, e.g. Oracle and DB2, will require variable_get() // and variable_set() for overcoming some database specific limitations. - $schema['variable'] = array( - 'description' => 'Named variable/value pairs created by Drupal core or any other module or theme. All variables are cached in memory at the start of every Drupal request so developers should not be careless about what is stored here.', + $schema['keyvalue'] = array( + 'description' => 'Generic key-value storage table.', 'fields' => array( 'name' => array( - 'description' => 'The name of the variable.', + 'description' => 'The key.', + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '', + ), + 'collection' => array( + 'description' => 'The collection of the variable.', 'type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '', ), 'value' => array( - 'description' => 'The value of the variable.', + 'description' => 'The value.', 'type' => 'blob', 'not null' => TRUE, 'size' => 'big', 'translatable' => TRUE, ), ), - 'primary key' => array('name'), + 'primary key' => array('collection', 'name'), ); $schema['actions'] = array(