Remove deprecated function _update_create_fetch_task and its usage

Usages:
1. update.module

/**
* Creates a new fetch task after loading the necessary include file.
*
* @param $project
*   Associative array of information about a project. See update_get_projects()
*   for the keys used.
*
* @see _update_create_fetch_task()
*/
function update_create_fetch_task($project) {
  module_load_include('inc', 'update', 'update.fetch');
  _update_create_fetch_task($project);
}

2. UpdateCoreTest.php

 /**
   * Tests that exactly one fetch task per project is created and not more.
   */
  function testFetchTasks() {
    $projecta = array(
      'name' => 'aaa_update_test',
    );
    $projectb = array(
      'name' => 'bbb_update_test',
    );
    $queue = \Drupal::queue('update_fetch_tasks');
    $this->assertEqual($queue->numberOfItems(), 0, 'Queue is empty');
    update_create_fetch_task($projecta);
    $this->assertEqual($queue->numberOfItems(), 1, 'Queue contains one item');
    update_create_fetch_task($projectb);
    $this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items');
    // Try to add project a again.
    update_create_fetch_task($projecta);
    $this->assertEqual($queue->numberOfItems(), 2, 'Queue still contains two items');

    // Clear storage and try again.
    update_storage_clear();
    drupal_static_reset('_update_create_fetch_task');
    update_create_fetch_task($projecta);
    $this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items');
  }

Function
update.fetch.inc

/**
 * Adds a task to the queue for fetching release history data for a project.
 *
 * We only create a new fetch task if there's no task already in the queue for
 * this particular project (based on 'update_fetch_task' key-value collection).
 *
 * @param $project
 *   Associative array of information about a project as created by
 *   update_get_projects(), including keys such as 'name' (short name), and the
 *   'info' array with data from a .info.yml file for the project.
 *
 * @see \Drupal\update\UpdateFetcher::createFetchTask()
 *
 * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
 *   Use \Drupal::service('update.processor')->createFetchTask().
 */
function _update_create_fetch_task($project) {
  \Drupal::service('update.processor')->createFetchTask($project);
}

Comments

arpitr’s picture

arpitr’s picture

Assigned: arpitr » Unassigned
Status: Active » Needs review

Status: Needs review » Needs work
benjy’s picture

If you're going to remove _update_create_fetch_task() then you'll need to also update update_create_fetch_task() not to call it. Something like this:

diff --git a/core/modules/update/update.module b/core/modules/update/update.module
index cdfc40c..4aa1d4b 100644
--- a/core/modules/update/update.module
+++ b/core/modules/update/update.module
@@ -378,7 +378,7 @@ function update_get_available($refresh = FALSE) {
  */
 function update_create_fetch_task($project) {
   module_load_include('inc', 'update', 'update.fetch');
-  _update_create_fetch_task($project);
+  \Drupal::service('update.processor')->createFetchTask($project);
 }
 
 /**

EDIT: the module_load_include could also be removed.

arpitr’s picture

Title: Remove deprecated function _update_create_fetch_task » Remove deprecated function _update_create_fetch_task and its usage
Assigned: Unassigned » arpitr
Issue summary: View changes
arpitr’s picture

Status: Needs work » Needs review
StatusFileSize
new2.38 KB
arpitr’s picture

Assigned: arpitr » Unassigned
benjy’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Quickfix

This looks good to me if the docs on update_create_fetch_task() suitably replace the docs we're removing on _update_create_fetch_task().

arpitr’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.99 KB

Updated the docs for update_create_fetch_task(), thanks @benjy :).

benjy’s picture

Status: Needs review » Reviewed & tested by the community

@arpitr, usually it's customary to create an interdiff when posting new patches: https://www.drupal.org/documentation/git/interdiff

Looks fine with me.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue is a prioritized change (deprecated code) as per https://www.drupal.org/core/beta-changes and it's benefits outweigh any disruption. Committed c7245b0 and pushed to 8.0.x. Thanks!

Normally we would commit the removal of usages in a separate patch from the removal of the function. Also this function _update_create_fetch_task() is prefixed by an underscore so was marked as private in D7 - therefore no need for a CR.

  • alexpott committed c7245b0 on 8.0.x
    Issue #2384009 by arpitr: Remove deprecated function...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.