UpdateProcessor::processFetchTask

public UpdateProcessor::processFetchTask($project)

Processes a task to fetch available update data for a single project.

Once the release history XML data is downloaded, it is parsed and saved in an entry just for that project.

Parameters

array $project: Associative array of information about the project to fetch data for.

Return value

bool TRUE if we fetched parsable XML, otherwise FALSE.

Overrides UpdateProcessorInterface::processFetchTask

File

core/modules/update/src/UpdateProcessor.php, line 139

Class

UpdateProcessor
Process project update information.

Namespace

Drupal\update

Code

public function processFetchTask($project) {
  global $base_url;

  // This can be in the middle of a long-running batch, so REQUEST_TIME won't
  // necessarily be valid.
  $request_time_difference = time() - REQUEST_TIME;
  if (empty($this->failed)) {
    // If we have valid data about release history XML servers that we have
    // failed to fetch from on previous attempts, load that.
    $this->failed = $this->tempStore->get('fetch_failures');
  }

  $max_fetch_attempts = $this->updateSettings->get('fetch.max_attempts');

  $success = FALSE;
  $available = array();
  $site_key = Crypt::hmacBase64($base_url, $this->privateKey->get());
  $fetch_url_base = $this->updateFetcher->getFetchBaseUrl($project);
  $project_name = $project['name'];

  if (empty($this->failed[$fetch_url_base]) || $this->failed[$fetch_url_base] < $max_fetch_attempts) {
    $data = $this->updateFetcher->fetchProjectData($project, $site_key);
  }
  if (!empty($data)) {
    $available = $this->parseXml($data);
    // @todo: Purge release data we don't need. See
    //   https://www.drupal.org/node/238950.
    if (!empty($available)) {
      // Only if we fetched and parsed something sane do we return success.
      $success = TRUE;
    }
  }
  else {
    $available['project_status'] = 'not-fetched';
    if (empty($this->failed[$fetch_url_base])) {
      $this->failed[$fetch_url_base] = 1;
    }
    else {
      $this->failed[$fetch_url_base]++;
    }
  }

  $frequency = $this->updateSettings->get('check.interval_days');
  $available['last_fetch'] = REQUEST_TIME + $request_time_difference;
  $this->availableReleasesTempStore->setWithExpire($project_name, $available, $request_time_difference + (60 * 60 * 24 * $frequency));

  // Stash the $this->failed data back in the DB for the next 5 minutes.
  $this->tempStore->setWithExpire('fetch_failures', $this->failed, $request_time_difference + (60 * 5));

  // Whether this worked or not, we did just (try to) check for updates.
  $this->stateStore->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.
  $this->fetchTaskStore->delete($project_name);

  return $success;
}
doc_Drupal
2016-10-29 09:51:00
Comments
Leave a Comment

Please login to continue.