diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 77458a1..b5e9f94 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2461,9 +2461,8 @@ 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('state.storage', 'Drupal\Core\KeyValueStore\DatabaseStorage') - ->addArgument('state'); + $container->register('keyvaluestore', 'Drupal\Core\KeyValueStore\KeyValueStoreFactory') + ->addArgument(new Reference('database')); } return $container; } @@ -2480,7 +2479,7 @@ function drupal_container(Container $new_container = NULL, $rebuild = FALSE) { * @return Drupal\Core\KeyValueStore\KeyValueStoreInterface */ function state() { - return drupal_container()->get('state.storage'); + return drupal_container()->get('keyvaluestore')->get('state'); } /** diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index ed15dd5..84a28ff 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -54,6 +54,9 @@ public function build(ContainerBuilder $container) { ->setFactoryClass('Drupal\Core\Database\Database') ->setFactoryMethod('getConnection') ->addArgument('slave'); + $container + ->register('keyvaluestore.expirable', 'Drupal\Core\KeyValueStore\KeyValueStoreExpirableFactory') + ->addArgument(new Reference('database')); $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'); diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreExpirableFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreExpirableFactory.php new file mode 100644 index 0000000..35ef604 --- /dev/null +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreExpirableFactory.php @@ -0,0 +1,47 @@ +connection = $connection; + } + + /** + * Creates a Drupal\Core\KeyValueStore\DatabaseStorageExpirable object. + * + * @param string $collection + * The collection to use for this key/value store. + * + * @return Drupal\Core\KeyValueStore\DatabaseStorageExpirable + * An instance of the the key/value store. + */ + function get($collection) { + return new DatabaseStorageExpirable($collection, array('connection' => $this->connection)); + } + +} diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreFactory.php new file mode 100644 index 0000000..83d990b --- /dev/null +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreFactory.php @@ -0,0 +1,47 @@ +connection = $connection; + } + + /** + * Creates a Drupal\Core\KeyValueStore\DatabaseStorage object. + * + * @param string $collection + * The collection to use for this key/value store. + * + * @return Drupal\Core\KeyValueStore\DatabaseStorage + * An instance of the the key/value store. + */ + function get($collection) { + return new DatabaseStorage($collection, array('connection' => $this->connection)); + } + +} diff --git a/core/modules/update/update.authorize.inc b/core/modules/update/update.authorize.inc index 396fa75..b56ca0d 100644 --- a/core/modules/update/update.authorize.inc +++ b/core/modules/update/update.authorize.inc @@ -327,6 +327,6 @@ function _update_batch_create_message(&$project_results, $message, $success = TR * @see update_storage_clear() */ function _update_authorize_clear_update_status() { - DatabaseStorageExpirable('update', array('connection' => Database::getConnection()))->deleteAll(); - DatabaseStorageExpirable('update_available_releases', array('connection' => Database::getConnection()))->deleteAll(); + drupal_container()->get('keyvaluestore.expirable')->get('update')->deleteAll(); + drupal_container()->get('keyvaluestore.expirable')->get('update_available_releases')->deleteAll(); } diff --git a/core/modules/update/update.compare.inc b/core/modules/update/update.compare.inc index 9d0aa4b..6510bb6 100644 --- a/core/modules/update/update.compare.inc +++ b/core/modules/update/update.compare.inc @@ -70,7 +70,7 @@ function update_get_projects() { // Allow other modules to alter projects before fetching and comparing. drupal_alter('update_projects', $projects); // Store the site's project data for at most 1 hour. - update_storage()->setWithExpire('update_project_projects', $projects, 3600); + drupal_container()->get('keyvaluestore.expirable')->get('update')->setWithExpire('update_project_projects', $projects, 3600); } } return $projects; @@ -358,7 +358,7 @@ function update_calculate_project_data($available) { drupal_alter('update_status', $projects); // Store the site's update status for at most 1 hour. - update_storage()->setWithExpire('update_project_data', $projects, 3600); + drupal_container()->get('keyvaluestore.expirable')->get('update')->setWithExpire('update_project_data', $projects, 3600); return $projects; } @@ -791,10 +791,10 @@ function update_project_storage($key) { 'admin/reports/updates/check', ); if (in_array(current_path(), $paths)) { - update_storage()->delete($key); + drupal_container()->get('keyvaluestore.expirable')->get('update')->delete($key); } else { - $projects = update_storage()->get($key); + $projects = drupal_container()->get('keyvaluestore.expirable')->get('update')->get($key); } return $projects; } diff --git a/core/modules/update/update.fetch.inc b/core/modules/update/update.fetch.inc index 61bc80f..cd8efd1 100644 --- a/core/modules/update/update.fetch.inc +++ b/core/modules/update/update.fetch.inc @@ -136,7 +136,7 @@ function _update_process_fetch_task($project) { if (empty($fail)) { // If we have valid data about release history XML servers that we have // failed to fetch from on previous attempts, load that. - $fail = update_storage()->get('fetch_failures'); + $fail = drupal_container()->get('keyvaluestore.expirable')->get('update')->get('fetch_failures'); } $max_fetch_attempts = $update_config->get('fetch.max_attempts'); @@ -178,17 +178,17 @@ function _update_process_fetch_task($project) { $frequency = $update_config->get('check.interval_days'); $available['last_fetch'] = REQUEST_TIME + $request_time_difference; - update_storage('update_available_releases')->setWithExpire($project_name, $available, $request_time_difference + (60 * 60 * 24 * $frequency)); + drupal_container()->get('keyvaluestore.expirable')->get('update_available_releases')->setWithExpire($project_name, $available, $request_time_difference + (60 * 60 * 24 * $frequency)); // Stash the $fail data back in the DB for the next 5 minutes. - update_storage()->setWithExpire('fetch_failures', $fail, $request_time_difference + (60 * 5)); + drupal_container()->get('keyvaluestore.expirable')->get('update')->setWithExpire('fetch_failures', $fail, $request_time_difference + (60 * 5)); // Whether this worked or not, we did just (try to) check for updates. variable_set('update_last_check', REQUEST_TIME + $request_time_difference); // Now that we processed the fetch task for this project, clear out the // record for this task so we're willing to fetch again. - update_storage('update_fetch_task')->delete($project_name); + drupal_container()->get('keyvaluestore.expirable')->get('update_fetch_task')->delete($project_name); return $success; } @@ -205,15 +205,15 @@ function _update_refresh() { // releases just yet, since that data (even if it's stale) can be useful // during update_get_projects(); for example, to modules that implement // hook_system_info_alter() such as cvs_deploy. - update_storage()->delete('update_project_projects'); - update_storage()->delete('update_project_data'); + drupal_container()->get('keyvaluestore.expirable')->get('update')->delete('update_project_projects'); + drupal_container()->get('keyvaluestore.expirable')->get('update')->delete('update_project_data'); $projects = update_get_projects(); // Now that we have the list of projects, we should also clear the available // release data, since even if we fail to fetch new data, we need // to clear out the stale data at this point. - update_storage('available_releases')->deleteAll(); + drupal_container()->get('keyvaluestore.expirable')->get('update_available_releases')->deleteAll(); foreach ($projects as $key => $project) { update_create_fetch_task($project); @@ -240,12 +240,12 @@ function _update_refresh() { function _update_create_fetch_task($project) { $fetch_tasks = &drupal_static(__FUNCTION__, array()); if (empty($fetch_tasks)) { - $fetch_tasks = update_storage('update_fetch_task')->getAll(); + $fetch_tasks = drupal_container()->get('keyvaluestore.expirable')->get('update_fetch_task')->getAll(); } if (empty($fetch_tasks[$project['name']])) { $queue = queue('update_fetch_tasks'); $queue->createItem($project); - update_storage('update_fetch_task')->set($project['name'], $project); + drupal_container()->get('keyvaluestore.expirable')->get('update_fetch_task')->set($project['name'], $project); $fetch_tasks[$project['name']] = REQUEST_TIME; } } diff --git a/core/modules/update/update.module b/core/modules/update/update.module index d5b1e7d..f08082a 100644 --- a/core/modules/update/update.module +++ b/core/modules/update/update.module @@ -391,7 +391,7 @@ function update_get_available($refresh = FALSE) { $needs_refresh = FALSE; // Grab whatever data we currently have. - $available = update_storage('update_available_releases')->getAll(); + $available = drupal_container()->get('keyvaluestore.expirable')->get('update_available_releases')->getAll(); $projects = update_get_projects(); foreach ($projects as $key => $project) { @@ -430,7 +430,7 @@ function update_get_available($refresh = FALSE) { update_fetch_data(); // After processing the queue, we've (hopefully) got better data, so pull // the latest data again and use that directly. - $available = update_storage('update_available_releases')->getAll(); + $available = drupal_container()->get('keyvaluestore.expirable')->get('update_available_releases')->getAll(); } return $available; @@ -705,35 +705,11 @@ function update_verify_update_archive($project, $archive_file, $directory) { } /** - * Returns a expriable key value storage to store update information. - * - * @param $collection - * (optional) Specify the collection that should be used for the key value - * storage. Defaults to 'update'. - * - * @return Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface - */ -function update_storage($collection = 'update') { - $storage = &drupal_static(__FUNCTION__); - if (!isset($storage[$collection])) { - // @todo Set without expiration currently does not work on - // DatabaseStorageExpirable. - if ($collection == 'update_fetch_task') { - $storage[$collection] = new DatabaseStorage($collection, array('connection' => Database::getConnection())); - } - else { - $storage[$collection] = new DatabaseStorageExpirable($collection, array('connection' => Database::getConnection())); - } - } - return $storage[$collection]; -} - -/** * Invalidates stored data relating to update status. */ function update_storage_clear() { - update_storage()->deleteAll(); - update_storage('update_available_release')->deleteAll(); + drupal_container()->get('keyvaluestore.expirable')->get('update')->deleteAll(); + drupal_container()->get('keyvaluestore.expirable')->get('update_available_release')->deleteAll(); } /**