You are here

protected function UpdateRegistry::getAvailableUpdateFunctions in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Update/UpdateRegistry.php \Drupal\Core\Update\UpdateRegistry::getAvailableUpdateFunctions()

Gets all available update functions.

Return value

callable[] A list of update functions.

2 calls to UpdateRegistry::getAvailableUpdateFunctions()
UpdateRegistry::getModuleUpdateFunctions in core/lib/Drupal/Core/Update/UpdateRegistry.php
Returns all available updates for a given module.
UpdateRegistry::getPendingUpdateFunctions in core/lib/Drupal/Core/Update/UpdateRegistry.php
Find all update functions that haven't been executed.

File

core/lib/Drupal/Core/Update/UpdateRegistry.php, line 110

Class

UpdateRegistry
Provides all and missing update implementations.

Namespace

Drupal\Core\Update

Code

protected function getAvailableUpdateFunctions() {
  $regexp = '/^(?<module>.+)_' . $this->updateType . '_(?<name>.+)$/';
  $functions = get_defined_functions();
  $updates = [];
  foreach (preg_grep('/_' . $this->updateType . '_/', $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)) {
      if (in_array($matches['module'], $this->enabledModules)) {
        $function_name = $matches['module'] . '_' . $this->updateType . '_' . $matches['name'];
        if ($this->updateType === 'post_update') {
          $removed = array_keys($this
            ->getRemovedPostUpdates($matches['module']));
          if (array_search($function_name, $removed) !== FALSE) {
            throw new RemovedPostUpdateNameException(sprintf('The following update is specified as removed in hook_removed_post_updates() but still exists in the code base: %s', $function_name));
          }
        }
        $updates[] = $function_name;
      }
    }
  }

  // Ensure that the update order is deterministic.
  sort($updates);
  return $updates;
}