function update_invoke_post_update

Same name in other branches
  1. 9 core/includes/update.inc \update_invoke_post_update()
  2. 10 core/includes/update.inc \update_invoke_post_update()
  3. 11.x core/includes/update.inc \update_invoke_post_update()

Executes a single hook_post_update_NAME().

Parameters

string $function: The function name, that should be executed.

array $context: The batch context array.

1 string reference to 'update_invoke_post_update'
DbUpdateController::triggerBatch in core/modules/system/src/Controller/DbUpdateController.php
Starts the database update batch process.

File

core/includes/update.inc, line 296

Code

function update_invoke_post_update($function, &$context) {
    $ret = [];
    // If this update was aborted in a previous step, or has a dependency that was
    // aborted in a previous step, go no further.
    if (!empty($context['results']['#abort'])) {
        return;
    }
    list($module, $name) = explode('_post_update_', $function, 2);
    module_load_include('php', $module, $module . '.post_update');
    if (function_exists($function)) {
        try {
            $ret['results']['query'] = $function($context['sandbox']);
            $ret['results']['success'] = TRUE;
            if (!isset($context['sandbox']['#finished']) || isset($context['sandbox']['#finished']) && $context['sandbox']['#finished'] >= 1) {
                \Drupal::service('update.post_update_registry')->registerInvokedUpdates([
                    $function,
                ]);
            }
        } catch (Exception $e) {
            watchdog_exception('update', $e);
            $variables = Error::decodeException($e);
            unset($variables['backtrace']);
            $ret['#abort'] = [
                'success' => FALSE,
                'query' => t('%type: @message in %function (line %line of %file).', $variables),
            ];
        }
    }
    if (isset($context['sandbox']['#finished'])) {
        $context['finished'] = $context['sandbox']['#finished'];
        unset($context['sandbox']['#finished']);
    }
    if (!isset($context['results'][$module][$name])) {
        $context['results'][$module][$name] = [];
    }
    $context['results'][$module][$name] = array_merge($context['results'][$module][$name], $ret);
    if (!empty($ret['#abort'])) {
        // Record this function in the list of updates that were aborted.
        $context['results']['#abort'][] = $function;
    }
    $context['message'] = t('Post updating @module', [
        '@module' => $module,
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.