public function UpdateProcessor::processFetchTask in Drupal 8
Same name and namespace in other branches
- 9 core/modules/update/src/UpdateProcessor.php \Drupal\update\UpdateProcessor::processFetchTask()
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
1 call to UpdateProcessor::processFetchTask()
- UpdateProcessor::fetchData in core/
modules/ update/ src/ UpdateProcessor.php - Attempts to drain the queue of tasks for release history data to fetch.
File
- core/
modules/ update/ src/ UpdateProcessor.php, line 144
Class
- UpdateProcessor
- Process project update information.
Namespace
Drupal\updateCode
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 = [];
$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;
}