function update_get_available in Drupal 10
Same name and namespace in other branches
- 8 core/modules/update/update.module \update_get_available()
- 6 modules/update/update.module \update_get_available()
- 7 modules/update/update.module \update_get_available()
- 9 core/modules/update/update.module \update_get_available()
Tries to get update information and refreshes it when necessary.
In addition to checking the lifetime, this function also ensures that there are no .info.yml files for enabled modules or themes that have a newer modification timestamp than the last time we checked for available update data. If any .info.yml file was modified, it almost certainly means a new version of something was installed. Without fresh available update data, the logic in update_calculate_project_data() will be wrong and produce confusing, bogus results.
Parameters
$refresh: (optional) Boolean to indicate if this method should refresh automatically if there's no data. Defaults to FALSE.
Return value
Array of data about available releases, keyed by project shortname.
See also
\Drupal\update\UpdateManager::getProjects()
6 calls to update_get_available()
- UpdateContribTest::testNoReleasesAvailable in core/
modules/ update/ tests/ src/ Functional/ UpdateContribTest.php - Tests when there is no available release data for a contrib module.
- UpdateController::updateStatus in core/
modules/ update/ src/ Controller/ UpdateController.php - Returns a page about the update status of projects.
- UpdateManagerUpdate::buildForm in core/
modules/ update/ src/ Form/ UpdateManagerUpdate.php - Form constructor.
- UpdateUploadTest::testUploadModule in core/
modules/ update/ tests/ src/ Functional/ UpdateUploadTest.php - Tests upload, extraction, and update of a module.
- update_cron in core/
modules/ update/ update.module - Implements hook_cron().
File
- core/
modules/ update/ update.module, line 277 - Handles updates of Drupal core and contributed projects.
Code
function update_get_available($refresh = FALSE) {
\Drupal::moduleHandler()
->loadInclude('update', 'inc', 'update.compare');
$needs_refresh = FALSE;
// Grab whatever data we currently have.
$available = \Drupal::keyValueExpirable('update_available_releases')
->getAll();
$projects = \Drupal::service('update.manager')
->getProjects();
foreach ($projects as $key => $project) {
// If there's no data at all, we clearly need to fetch some.
if (empty($available[$key])) {
// update_create_fetch_task($project);
\Drupal::service('update.processor')
->createFetchTask($project);
$needs_refresh = TRUE;
continue;
}
// See if the .info.yml file is newer than the last time we checked for
// data, and if so, mark this project's data as needing to be re-fetched.
// Any time an admin upgrades their local installation, the .info.yml file
// will be changed, so this is the only way we can be sure we're not showing
// bogus information right after they upgrade.
if ($project['info']['_info_file_ctime'] > $available[$key]['last_fetch']) {
$available[$key]['fetch_status'] = UpdateFetcherInterface::FETCH_PENDING;
}
// If we have project data but no release data, we need to fetch. This
// can be triggered when we fail to contact a release history server.
if (empty($available[$key]['releases']) && !$available[$key]['last_fetch']) {
$available[$key]['fetch_status'] = UpdateFetcherInterface::FETCH_PENDING;
}
// If we think this project needs to fetch, actually create the task now
// and remember that we think we're missing some data.
if (!empty($available[$key]['fetch_status']) && $available[$key]['fetch_status'] == UpdateFetcherInterface::FETCH_PENDING) {
\Drupal::service('update.processor')
->createFetchTask($project);
$needs_refresh = TRUE;
}
}
if ($needs_refresh && $refresh) {
// Attempt to drain the queue of fetch tasks.
update_fetch_data();
// After processing the queue, we've (hopefully) got better data, so pull
// the latest data again and use that directly.
$available = \Drupal::keyValueExpirable('update_available_releases')
->getAll();
}
return $available;
}