You are here

function update_requirements in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/update/update.install \update_requirements()
  2. 6 modules/update/update.module \update_requirements()
  3. 7 modules/update/update.install \update_requirements()

Implements hook_requirements().

Describes the status of the site regarding available updates. If there is no update data, only one record will be returned, indicating that the status of core can't be determined. If data is available, there will be two records: one for core, and another for all of contrib (assuming there are any contributed modules or themes enabled on the site). In addition to the fields expected by hook_requirements ('value', 'severity', and optionally 'description'), this array will contain a 'reason' attribute, which is an integer constant to indicate why the given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or UPDATE_UNKNOWN). This is used for generating the appropriate email notification messages during update_cron(), and might be useful for other modules that invoke update_requirements() to find out if the site is up to date or not.

See also

_update_message_text()

_update_cron_notify()

\Drupal\update\UpdateManagerInterface

2 calls to update_requirements()
update_page_top in core/modules/update/update.module
Implements hook_page_top().
_update_cron_notify in core/modules/update/update.fetch.inc
Performs any notifications that should be done once cron fetches new data.

File

core/modules/update/update.install, line 35
Install, update, and uninstall functions for the Update Manager module.

Code

function update_requirements($phase) {
  $requirements = [];
  if ($phase == 'runtime') {
    if ($available = update_get_available(FALSE)) {
      module_load_include('inc', 'update', 'update.compare');
      $data = update_calculate_project_data($available);

      // First, populate the requirements for core:
      $requirements['update_core'] = _update_requirement_check($data['drupal'], 'core');
      if (!empty($available['drupal']['releases'])) {
        $security_data = ProjectSecurityData::createFromProjectDataAndReleases($data['drupal'], $available['drupal']['releases'])
          ->getCoverageInfo();
        if ($core_coverage_requirement = ProjectSecurityRequirement::createFromProjectDataAndSecurityCoverageInfo($data['drupal'], $security_data)
          ->getRequirement()) {
          $requirements['coverage_core'] = $core_coverage_requirement;
        }
      }

      // We don't want to check drupal a second time.
      unset($data['drupal']);
      if (!empty($data)) {

        // Now, sort our $data array based on each project's status. The
        // status constants are numbered in the right order of precedence, so
        // we just need to make sure the projects are sorted in ascending
        // order of status, and we can look at the first project we find.
        uasort($data, '_update_project_status_sort');
        $first_project = reset($data);
        $requirements['update_contrib'] = _update_requirement_check($first_project, 'contrib');
      }
    }
    else {
      $requirements['update_core']['title'] = t('Drupal core update status');
      $requirements['update_core']['value'] = t('No update data available');
      $requirements['update_core']['severity'] = REQUIREMENT_WARNING;
      $requirements['update_core']['reason'] = UpdateFetcherInterface::UNKNOWN;
      $requirements['update_core']['description'] = _update_no_data();
    }
  }
  return $requirements;
}