1 install.inc backdrop_get_schema_versions($module)

Returns an array of available schema versions for a module.

This function contains backwards-compatibility code to order schema versions such that updates between 7000 and 8999 (inclusive) run before all other updates. This is to allow users to upgrade from Drupal 7, where the last installed schema will likely be in the 7xxx range.

Parameters

$module: A module name.

Return value

array|FALSE If the module has updates, an unindexed array of available updates sorted by the order they should be executed. Otherwise, FALSE.

File

core/includes/install.inc, line 103
API functions for installing modules and themes.

Code

function backdrop_get_schema_versions($module) {
  $updates = &backdrop_static(__FUNCTION__, NULL);
  if (!isset($updates[$module])) {
    $updates = array();

    foreach (module_list() as $loaded_module) {
      $updates[$loaded_module] = array();
    }

    // Prepare regular expression to match all possible defined hook_update_N().
    $regexp = '/^(?P<module>.+)_update_(?P<version>\d+)$/';
    $functions = get_defined_functions();
    // Narrow this down to functions ending with an integer, since all
    // hook_update_N() functions end this way, and there are other
    // possible functions which match '_update_'. We use preg_grep() here
    // instead of foreaching through all defined functions, since the loop
    // through all PHP functions can take significant page execution time
    // and this function is called on every administrative page via
    // system_requirements().
    foreach (preg_grep('/_\d+$/', $functions['user']) as $function) {
      // If this function is a module update function, add it to the list of
      // module updates.
      if (preg_match($regexp, $function, $matches)) {
        $updates[$matches['module']][] = $matches['version'];
      }
    }
    // Ensure that updates are applied in numerical order. Updates are ordered
    // 7000 to 8999, then 0 to 6999. This is to ensure compatibility of the
    // schema updates from Drupal 7 to Backdrop CMS 1.
    foreach ($updates as &$module_updates) {
      usort($module_updates, function($a, $b) {
        if ($a >= 7000 && $a < 9000) {
          $a -= 9000;
        }
        if ($b >= 7000 && $b < 9000) {
          $b -= 9000;
        }
        return ($a == $b) ? 0 : ($a > $b ? 1 : -1);
      });
    }
  }
  return empty($updates[$module]) ? FALSE : $updates[$module];
}