You are here

function drupal_get_schema_versions in Drupal 8

Same name and namespace in other branches
  1. 4 includes/install.inc \drupal_get_schema_versions()
  2. 5 includes/install.inc \drupal_get_schema_versions()
  3. 6 includes/install.inc \drupal_get_schema_versions()
  4. 7 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

string $module: A module name.

Return value

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

Related topics

6 calls to drupal_get_schema_versions()
Module::getSchemaUpdates in core/lib/Drupal/Core/Updater/Module.php
Returns available database schema updates once a new version is installed.
ModuleInstaller::install in core/lib/Drupal/Core/Extension/ModuleInstaller.php
Installs a given list of modules.
system_requirements in core/modules/system/system.install
Implements hook_requirements().
update_get_update_function_list in core/includes/update.inc
Returns an organized list of update functions for a set of modules.
update_get_update_list in core/includes/update.inc
Returns a list of all the pending database updates.

... See full list

File

core/includes/schema.inc, line 30
Schema API handling functions.

Code

function drupal_get_schema_versions($module) {
  $updates =& drupal_static(__FUNCTION__, NULL);
  if (!isset($updates[$module])) {
    $updates = [];
    foreach (\Drupal::moduleHandler()
      ->getModuleList() as $loaded_module => $filename) {
      $updates[$loaded_module] = [];
    }

    // Prepare regular expression to match all possible defined hook_update_N().
    $regexp = '/^(?<module>.+)_update_(?<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];
}