You are here

function drupal_get_schema_versions in Drupal 7

Same name and namespace in other branches
  1. 8 core/includes/schema.inc \drupal_get_schema_versions()
  2. 4 includes/install.inc \drupal_get_schema_versions()
  3. 5 includes/install.inc \drupal_get_schema_versions()
  4. 6 includes/install.inc \drupal_get_schema_versions()
  5. 9 core/includes/schema.inc \drupal_get_schema_versions()

Returns an array of available schema versions for a module.

Parameters

$module: A module name.

Return value

If the module has updates, an array of available updates sorted by version. Otherwise, FALSE.

7 calls to drupal_get_schema_versions()
drupal_install_system in includes/install.inc
Installs the system module.
ModuleUpdater::getSchemaUpdates in modules/system/system.updater.inc
Return available database schema updates one a new version is installed.
module_enable in includes/module.inc
Enables or installs a given list of modules.
system_install in modules/system/system.install
Implements hook_install().
system_requirements in modules/system/system.install
Implements hook_requirements().

... See full list

1 string reference to 'drupal_get_schema_versions'
system_install in modules/system/system.install
Implements hook_install().

File

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

Code

function drupal_get_schema_versions($module) {
  $updates =& drupal_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.
    foreach ($updates as &$module_updates) {
      sort($module_updates, SORT_NUMERIC);
    }
  }
  return empty($updates[$module]) ? FALSE : $updates[$module];
}