1 update.inc update_get_update_list()

Returns a list of all the pending database updates.

Return value

An associative array keyed by module name which contains all information: about database updates that need to be run, and any updates that are not going to proceed due to missing requirements. The system module will always be listed first.

The subarray for each module can contain the following keys:

  • start: The starting update that is to be processed. If this does not exist then do not process any updates for this module as there are other requirements that need to be resolved.
  • warning: Any warnings about why this module can not be updated.
  • pending: An array of all the pending updates for the module including the update number and the description from source code comment for each update function. This array is keyed by the update number.

File

core/includes/update.inc, line 649
Backdrop database update API.

Code

function update_get_update_list() {
  // Make sure that the system module is first in the list of updates.
  $ret = array('system' => array());

  $modules = backdrop_get_installed_schema_version(NULL, FALSE, TRUE);
  foreach ($modules as $module => $schema_version) {
    // Skip uninstalled and incompatible modules.
    if ($schema_version == SCHEMA_UNINSTALLED || update_check_incompatibility($module)) {
      continue;
    }
    // Otherwise, get the list of updates defined by this module.
    $updates = backdrop_get_schema_versions($module);
    if ($updates !== FALSE) {
      // module_invoke returns NULL for nonexisting hooks, so if no updates
      // are removed, it will == 0.
      $last_removed = module_invoke($module, 'update_last_removed');
      // A last removed schema version of "7xxx" should consider "1xxx" updates
      // to be after itself. We add 7000 to make an update 1000 be compared
      // as if it were 8000.
      $comparison_schema_version = $schema_version;
      if ($last_removed >= 7000 && $last_removed < 9000 && $schema_version < 7000) {
        $comparison_schema_version += 7000;
      }
      if ($comparison_schema_version < $last_removed) {
        $ret[$module]['warning'] = '<em>' . $module . '</em> module can not be updated. Its schema version is ' . $schema_version . '. Updates up to and including ' . $last_removed . ' have been removed in this release. In order to update <em>' . $module . '</em> module, you will first <a href="https://backdropcms.org/upgrade">need to upgrade</a> to the last version in which these updates were available.';
        continue;
      }

      // Reduce schema versions by 7000 for legacy updates.
      if ($schema_version >= 7000 && $schema_version < 9000) {
        $schema_version -= 7000;
      }

      foreach ($updates as $update) {
        // Reduce update versions by 7000 for legacy update comparisons. Note
        // that the original update version is still queued for execution.
        $compare_version = $update;
        if ($update >= 7000 && $update < 9000) {
          $compare_version -= 7000;
        }
        if ($compare_version > $schema_version) {
          // The description for an update comes from its Doxygen.
          $func = new ReflectionFunction($module . '_update_' . $update);
          $description = str_replace(array("\n", '*', '/'), '', $func->getDocComment());
          $ret[$module]['pending'][$update] = $update . ' - ' . trim($description);
          if (!isset($ret[$module]['start'])) {
            $ret[$module]['start'] = $update;
          }
        }
      }
      if (!isset($ret[$module]['start']) && isset($ret[$module]['pending'])) {
        $ret[$module]['start'] = $schema_version;
      }
    }
  }

  if (empty($ret['system'])) {
    unset($ret['system']);
  }
  return $ret;
}