Commit 7aca9955 authored by alexpott's avatar alexpott

Issue #1937600 by Berdir, rootatwc | webchick: Determine what services to...

Issue #1937600 by Berdir, rootatwc | webchick: Determine what services to register in the new Drupal class.
parent b71bc2c1
...@@ -5024,7 +5024,7 @@ function drupal_cron_run() { ...@@ -5024,7 +5024,7 @@ function drupal_cron_run() {
// existing queue. // existing queue.
foreach ($queues as $queue_name => $info) { foreach ($queues as $queue_name => $info) {
if (isset($info['cron'])) { if (isset($info['cron'])) {
queue($queue_name)->createQueue(); Drupal::queue($queue_name)->createQueue();
} }
} }
...@@ -5054,7 +5054,7 @@ function drupal_cron_run() { ...@@ -5054,7 +5054,7 @@ function drupal_cron_run() {
if (isset($info['cron'])) { if (isset($info['cron'])) {
$function = $info['worker callback']; $function = $info['worker callback'];
$end = time() + (isset($info['cron']['time']) ? $info['cron']['time'] : 15); $end = time() + (isset($info['cron']['time']) ? $info['cron']['time'] : 15);
$queue = queue($queue_name); $queue = Drupal::queue($queue_name);
while (time() < $end && ($item = $queue->claimItem())) { while (time() < $end && ($item = $queue->claimItem())) {
$function($item->data); $function($item->data);
$queue->deleteItem($item); $queue->deleteItem($item);
...@@ -6665,34 +6665,6 @@ function drupal_get_filetransfer_info() { ...@@ -6665,34 +6665,6 @@ function drupal_get_filetransfer_info() {
* once (because the processing code might time out before it finishes). * once (because the processing code might time out before it finishes).
*/ */
/**
* Instantiates and statically caches the correct class for a queue.
*
* The following variables can be set by variable_set or $conf overrides:
* - queue_class_$name: The class to be used for the queue $name.
* - queue_default_class: The class to use when queue_class_$name is not
* defined. Defaults to Drupal\Core\Queue\System, a reliable backend using
* SQL.
* - queue_default_reliable_class: The class to use when queue_class_$name is
* not defined and the queue_default_class is not reliable. Defaults to
* Drupal\Core\Queue\System.
*
* @param string $name
* The name of the queue to work with.
* @param bool $reliable
* (optional) TRUE if the ordering of items and guaranteeing every item
* executes at least once is important, FALSE if scalability is the main
* concern. Defaults to FALSE.
*
* @return Drupal\Core\Queue\QueueInterface
* The queue object for a given name.
*
* @see Drupal\Core\Queue\QueueInterface
*/
function queue($name, $reliable = FALSE) {
return drupal_container()->get('queue')->get($name, $reliable);
}
/** /**
* @} End of "defgroup queue". * @} End of "defgroup queue".
*/ */
...@@ -1526,7 +1526,7 @@ function install_retrieve_file($uri, $destination) { ...@@ -1526,7 +1526,7 @@ function install_retrieve_file($uri, $destination) {
} }
try { try {
$request = drupal_container()->get('http_default_client')->get($uri, array('Accept' => 'text/plain')); $request = Drupal::httpClient()->get($uri, array('Accept' => 'text/plain'));
$data = $request->send()->getBody(TRUE); $data = $request->send()->getBody(TRUE);
if (empty($data)) { if (empty($data)) {
return FALSE; return FALSE;
...@@ -1549,7 +1549,7 @@ function install_retrieve_file($uri, $destination) { ...@@ -1549,7 +1549,7 @@ function install_retrieve_file($uri, $destination) {
*/ */
function install_check_localization_server($uri) { function install_check_localization_server($uri) {
try { try {
$request = drupal_container()->get('http_default_client')->head($uri); $request = Drupal::httpClient()->head($uri);
$response = $request->send(); $response = $request->send();
return TRUE; return TRUE;
} }
......
...@@ -629,10 +629,7 @@ function drupal_install_system() { ...@@ -629,10 +629,7 @@ function drupal_install_system() {
require_once DRUPAL_ROOT . '/' . $system_path . '/system.install'; require_once DRUPAL_ROOT . '/' . $system_path . '/system.install';
$system_versions = drupal_get_schema_versions('system'); $system_versions = drupal_get_schema_versions('system');
$system_version = $system_versions ? max($system_versions) : SCHEMA_INSTALLED; $system_version = $system_versions ? max($system_versions) : SCHEMA_INSTALLED;
drupal_container() Drupal::keyValue('system.schema')->set('system', $system_version);
->get('keyvalue')
->get('system.schema')
->set('system', $system_version);
// System module needs to be enabled and the system/module lists need to be // System module needs to be enabled and the system/module lists need to be
// reset first in order to allow config_install_default_config() to invoke // reset first in order to allow config_install_default_config() to invoke
......
...@@ -284,7 +284,7 @@ function module_enable($module_list, $enable_dependencies = TRUE) { ...@@ -284,7 +284,7 @@ function module_enable($module_list, $enable_dependencies = TRUE) {
$modules_installed = array(); $modules_installed = array();
$modules_enabled = array(); $modules_enabled = array();
$schema_store = drupal_container()->get('keyvalue')->get('system.schema'); $schema_store = Drupal::keyValue('system.schema');
$module_config = config('system.module'); $module_config = config('system.module');
$disabled_config = config('system.module.disabled'); $disabled_config = config('system.module.disabled');
$module_handler = drupal_container()->get('module_handler'); $module_handler = drupal_container()->get('module_handler');
...@@ -567,7 +567,7 @@ function module_uninstall($module_list = array(), $uninstall_dependents = TRUE) ...@@ -567,7 +567,7 @@ function module_uninstall($module_list = array(), $uninstall_dependents = TRUE)
} }
$storage = drupal_container()->get('config.storage'); $storage = drupal_container()->get('config.storage');
$schema_store = drupal_container()->get('keyvalue')->get('system.schema'); $schema_store = Drupal::keyValue('system.schema');
$disabled_config = config('system.module.disabled'); $disabled_config = config('system.module.disabled');
foreach ($module_list as $module) { foreach ($module_list as $module) {
// Uninstall the module. // Uninstall the module.
......
...@@ -173,7 +173,7 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F ...@@ -173,7 +173,7 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F
} }
if (!$versions) { if (!$versions) {
if (!$versions = drupal_container()->get('keyvalue')->get('system.schema')->getAll()) { if (!$versions = Drupal::keyValue('system.schema')->getAll()) {
$versions = array(); $versions = array();
} }
} }
...@@ -195,7 +195,7 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F ...@@ -195,7 +195,7 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F
* The new schema version. * The new schema version.
*/ */
function drupal_set_installed_schema_version($module, $version) { function drupal_set_installed_schema_version($module, $version) {
drupal_container()->get('keyvalue')->get('system.schema')->set($module, $version); Drupal::keyValue('system.schema')->set($module, $version);
// Reset the static cache of module schema versions. // Reset the static cache of module schema versions.
drupal_get_installed_schema_version(NULL, TRUE); drupal_get_installed_schema_version(NULL, TRUE);
} }
......
...@@ -332,7 +332,7 @@ function update_prepare_d8_bootstrap() { ...@@ -332,7 +332,7 @@ function update_prepare_d8_bootstrap() {
$disabled_modules = config('system.module.disabled'); $disabled_modules = config('system.module.disabled');
$theme_config = config('system.theme'); $theme_config = config('system.theme');
$disabled_themes = config('system.theme.disabled'); $disabled_themes = config('system.theme.disabled');
$schema_store = drupal_container()->get('keyvalue')->get('system.schema'); $schema_store = Drupal::keyValue('system.schema');
// Load system.module, because update_prepare_d8_bootstrap() is called in // Load system.module, because update_prepare_d8_bootstrap() is called in
// the initial minimal update.php bootstrap that performs the core // the initial minimal update.php bootstrap that performs the core
...@@ -694,7 +694,7 @@ function update_fix_d8_requirements() { ...@@ -694,7 +694,7 @@ function update_fix_d8_requirements() {
* if the module was not installed before. * if the module was not installed before.
*/ */
function update_module_enable(array $modules, $schema_version = 0) { function update_module_enable(array $modules, $schema_version = 0) {
$schema_store = drupal_container()->get('keyvalue')->get('system.schema'); $schema_store = Drupal::keyValue('system.schema');
$old_schema = array(); $old_schema = array();
foreach ($modules as $module) { foreach ($modules as $module) {
// Check for initial schema and install it. The schema version of a newly // Check for initial schema and install it. The schema version of a newly
...@@ -1268,7 +1268,7 @@ function update_retrieve_dependencies() { ...@@ -1268,7 +1268,7 @@ function update_retrieve_dependencies() {
$return = array(); $return = array();
// Get a list of installed modules, arranged so that we invoke their hooks in // Get a list of installed modules, arranged so that we invoke their hooks in
// the same order that module_invoke_all() does. // the same order that module_invoke_all() does.
foreach (drupal_container()->get('keyvalue')->get('system.schema')->getAll() as $module => $schema) { foreach (Drupal::keyValue('system.schema')->getAll() as $module => $schema) {
if ($schema == SCHEMA_UNINSTALLED) { if ($schema == SCHEMA_UNINSTALLED) {
// Nothing to upgrade. // Nothing to upgrade.
continue; continue;
......
...@@ -138,7 +138,7 @@ public static function database() { ...@@ -138,7 +138,7 @@ public static function database() {
* (optional) The cache bin for which the cache object should be returned, * (optional) The cache bin for which the cache object should be returned,
* defaults to 'cache'. * defaults to 'cache'.
* *
* @return Drupal\Core\Cache\CacheBackendInterface * @return \Drupal\Core\Cache\CacheBackendInterface
* The cache object associated with the specified bin. * The cache object associated with the specified bin.
*/ */
public static function cache($bin = 'cache') { public static function cache($bin = 'cache') {
...@@ -167,4 +167,135 @@ public static function lock() { ...@@ -167,4 +167,135 @@ public static function lock() {
return static::$container->get('lock'); return static::$container->get('lock');
} }
/**
* Retrieves a configuration object.
*
* This is the main entry point to the configuration API. Calling
* @code Drupal::config('book.admin') @endcode will return a configuration
* object in which the book module can store its administrative settings.
*
* @param string $name
* The name of the configuration object to retrieve. The name corresponds to
* a configuration file. For @code config('book.admin') @endcode, the config
* object returned will contain the contents of book.admin configuration file.
*
* @return \Drupal\Core\Config\Config
* A configuration object.
*/
public static function config($name) {
return static::$container->get('config.factory')->get($name);
}
/**
* Returns a queue for the given queue name.
*
* The following variables can be set by variable_set or $conf overrides:
* - queue_class_$name: The class to be used for the queue $name.
* - queue_default_class: The class to use when queue_class_$name is not
* defined. Defaults to \Drupal\Core\Queue\System, a reliable backend using
* SQL.
* - queue_default_reliable_class: The class to use when queue_class_$name is
* not defined and the queue_default_class is not reliable. Defaults to
* \Drupal\Core\Queue\System.
*
* @param string $name
* The name of the queue to work with.
* @param bool $reliable
* (optional) TRUE if the ordering of items and guaranteeing every item
* executes at least once is important, FALSE if scalability is the main
* concern. Defaults to FALSE.
*
* @return \Drupal\Core\Queue\QueueInterface
* The queue object for a given name.
*/
public static function queue($name, $reliable = FALSE) {
return static::$container->get('queue')->get($name, $reliable);
}
/**
* Returns a key/value storage collection.
*
* @param $collection
* Name of the key/value collection to return.
*
* @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface
*/
public static function keyValue($collection) {
return static::$container->get('keyvalue')->get($collection);
}
/**
* Returns the state storage service.
*
* Use this to store machine-generated data, local to a specific environment
* that does not need deploying and does not need human editing; for example,
* the last time cron was run. Data which needs to be edited by humans and
* needs to be the same across development, production, etc. environments
* (for example, the system maintenance message) should use config() instead.
*
* @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface
*/
public static function state() {
return static::$container->get('state');
}
/**
* Returns the default http client.
*
* @return \Guzzle\Http\ClientInterface
* A guzzle http client instance.
*/
public static function httpClient() {
return static::$container->get('http_default_client');
}
/**
* Returns the entity query object for this entity type.
*
* @param string $entity_type
* The entity type, e.g. node, for which the query object should be
* returned.
* @param string $conjunction
* AND if all conditions in the query need to apply, OR if any of them is
* enough. Optional, defaults to AND.
*
* @return \Drupal\Core\Entity\Query\QueryInterface
* The query object that can query the given entity type.
*/
public static function entityQuery($entity_type, $conjunction = 'AND') {
return static::$container->get('entity.query')->get($entity_type, $conjunction);
}
/**
* Returns the flood instance.
*
* @return \Drupal\Core\Flood\FloodInterface
*/
public static function flood() {
return static::$container->get('flood');
}
/**
* Returns the module handler.
*
* @return \Drupal\Core\Extension\ModuleHandler
*/
public static function moduleHandler() {
return static::$container->get('module_handler');
}
/**
* Returns the typed data manager service.
*
* Use the typed data manager service for creating typed data objects.
*
* @return \Drupal\Core\TypedData\TypedDataManager
* The typed data manager.
*
* @see \Drupal\Core\TypedData\TypedDataManager::create()
*/
public static function typedData() {
return static::$container->get('typed_data');
}
} }
...@@ -306,7 +306,7 @@ function aggregator_cron() { ...@@ -306,7 +306,7 @@ function aggregator_cron() {
':time' => REQUEST_TIME, ':time' => REQUEST_TIME,
':never' => AGGREGATOR_CLEAR_NEVER ':never' => AGGREGATOR_CLEAR_NEVER
)); ));
$queue = queue('aggregator_feeds'); $queue = Drupal::queue('aggregator_feeds');
foreach ($result->fetchCol() as $fid) { foreach ($result->fetchCol() as $fid) {
$feed = aggregator_feed_load($fid); $feed = aggregator_feed_load($fid);
if ($queue->createItem($feed)) { if ($queue->createItem($feed)) {
......
...@@ -31,7 +31,8 @@ class DefaultFetcher implements FetcherInterface { ...@@ -31,7 +31,8 @@ class DefaultFetcher implements FetcherInterface {
* Implements \Drupal\aggregator\Plugin\FetcherInterface::fetch(). * Implements \Drupal\aggregator\Plugin\FetcherInterface::fetch().
*/ */
public function fetch(Feed $feed) { public function fetch(Feed $feed) {
$request = \Drupal::service('http_default_client')->get($feed->url->value); // @todo: Inject the http client.
$request = \Drupal::httpClient()->get($feed->url->value);
$feed->source_string = FALSE; $feed->source_string = FALSE;
// Generate conditional GET headers. // Generate conditional GET headers.
......
...@@ -125,7 +125,7 @@ function hook_cron() { ...@@ -125,7 +125,7 @@ function hook_cron() {
':time' => REQUEST_TIME, ':time' => REQUEST_TIME,
':never' => AGGREGATOR_CLEAR_NEVER, ':never' => AGGREGATOR_CLEAR_NEVER,
)); ));
$queue = queue('aggregator_feeds'); $queue = Drupal::queue('aggregator_feeds');
foreach ($result as $feed) { foreach ($result as $feed) {
$queue->createItem($feed); $queue->createItem($feed);
} }
......
...@@ -201,7 +201,7 @@ function testFetchTasks() { ...@@ -201,7 +201,7 @@ function testFetchTasks() {
$projectb = array( $projectb = array(
'name' => 'bbb_update_test', 'name' => 'bbb_update_test',
); );
$queue = queue('update_fetch_tasks'); $queue = \Drupal::queue('update_fetch_tasks');
$this->assertEqual($queue->numberOfItems(), 0, 'Queue is empty'); $this->assertEqual($queue->numberOfItems(), 0, 'Queue is empty');
update_create_fetch_task($projecta); update_create_fetch_task($projecta);
$this->assertEqual($queue->numberOfItems(), 1, 'Queue contains one item'); $this->assertEqual($queue->numberOfItems(), 1, 'Queue contains one item');
......
...@@ -35,7 +35,7 @@ function update_manual_status() { ...@@ -35,7 +35,7 @@ function update_manual_status() {
* Reference to an array used for Batch API storage. * Reference to an array used for Batch API storage.
*/ */
function update_fetch_data_batch(&$context) { function update_fetch_data_batch(&$context) {
$queue = queue('update_fetch_tasks'); $queue = Drupal::queue('update_fetch_tasks');
if (empty($context['sandbox']['max'])) { if (empty($context['sandbox']['max'])) {
$context['finished'] = 0; $context['finished'] = 0;
$context['sandbox']['max'] = $queue->numberOfItems(); $context['sandbox']['max'] = $queue->numberOfItems();
...@@ -106,7 +106,7 @@ function update_fetch_data_finished($success, $results) { ...@@ -106,7 +106,7 @@ function update_fetch_data_finished($success, $results) {
* Attempts to drain the queue of tasks for release history data to fetch. * Attempts to drain the queue of tasks for release history data to fetch.
*/ */
function _update_fetch_data() { function _update_fetch_data() {
$queue = queue('update_fetch_tasks'); $queue = Drupal::queue('update_fetch_tasks');
$end = time() + config('update.settings')->get('fetch.timeout'); $end = time() + config('update.settings')->get('fetch.timeout');
while (time() < $end && ($item = $queue->claimItem())) { while (time() < $end && ($item = $queue->claimItem())) {
_update_process_fetch_task($item->data); _update_process_fetch_task($item->data);
...@@ -243,7 +243,7 @@ function _update_create_fetch_task($project) { ...@@ -243,7 +243,7 @@ function _update_create_fetch_task($project) {
$fetch_tasks = drupal_container()->get('keyvalue')->get('update_fetch_task')->getAll(); $fetch_tasks = drupal_container()->get('keyvalue')->get('update_fetch_task')->getAll();
} }
if (empty($fetch_tasks[$project['name']])) { if (empty($fetch_tasks[$project['name']])) {
$queue = queue('update_fetch_tasks'); $queue = Drupal::queue('update_fetch_tasks');
$queue->createItem($project); $queue->createItem($project);
drupal_container()->get('keyvalue')->get('update_fetch_task')->set($project['name'], $project); drupal_container()->get('keyvalue')->get('update_fetch_task')->set($project['name'], $project);
$fetch_tasks[$project['name']] = REQUEST_TIME; $fetch_tasks[$project['name']] = REQUEST_TIME;
......
...@@ -60,7 +60,7 @@ function update_requirements($phase) { ...@@ -60,7 +60,7 @@ function update_requirements($phase) {
* Implements hook_install(). * Implements hook_install().
*/ */
function update_install() { function update_install() {
$queue = queue('update_fetch_tasks', TRUE); $queue = Drupal::queue('update_fetch_tasks', TRUE);
$queue->createQueue(); $queue->createQueue();
} }
...@@ -72,7 +72,7 @@ function update_uninstall() { ...@@ -72,7 +72,7 @@ function update_uninstall() {
variable_del('update_last_check'); variable_del('update_last_check');
variable_del('update_last_email_notification'); variable_del('update_last_email_notification');
$queue = queue('update_fetch_tasks'); $queue = Drupal::queue('update_fetch_tasks');
$queue->deleteQueue(); $queue->deleteQueue();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment