function _update_create_fetch_task

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 'fetch_task::' entries in the {cache_update} table).

Parameters

$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 file for the project.

See also

update_get_projects()

update_get_available()

update_refresh()

update_fetch_data()

_update_process_fetch_task()

1 call to _update_create_fetch_task()
update_create_fetch_task in drupal/modules/update/update.module
Creates a new fetch task after loading the necessary include file.
1 string reference to '_update_create_fetch_task'
UpdateCoreTestCase::testFetchTasks in drupal/modules/update/update.test
Tests that exactly one fetch task per project is created and not more.

File

drupal/modules/update/update.fetch.inc, line 243
Code required only when fetching information about available updates.

Code

function _update_create_fetch_task($project) {
  $fetch_tasks =& drupal_static(__FUNCTION__, array());
  if (empty($fetch_tasks)) {
    $fetch_tasks = _update_get_cache_multiple('fetch_task');
  }
  $cid = 'fetch_task::' . $project['name'];
  if (empty($fetch_tasks[$cid])) {
    $queue = DrupalQueue::get('update_fetch_tasks');
    $queue
      ->createItem($project);

    // Due to race conditions, it is possible that another process already
    // inserted a row into the {cache_update} table and the following query will
    // throw an exception.
    // @todo: Remove the need for the manual check by relying on a queue that
    // enforces unique items.
    try {
      db_insert('cache_update')
        ->fields(array(
        'cid' => $cid,
        'created' => REQUEST_TIME,
      ))
        ->execute();
    } catch (Exception $e) {

      // The exception can be ignored safely.
    }
    $fetch_tasks[$cid] = REQUEST_TIME;
  }
}