function 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 228 
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;
  }
  // Ensure extension post update code is loaded.
  [$extension, $name] = explode('_post_update_', $function, 2);
  \Drupal::service('update.post_update_registry')->getUpdateFunctions($extension);
  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) {
      $variables = Error::decodeException($e);
      \Drupal::logger('update')->error(Error::DEFAULT_ERROR_MESSAGE, $variables);
      unset($variables['backtrace'], $variables['exception'], $variables['severity_level']);
      $ret['#abort'] = [
        'success' => FALSE,
        'query' => t(Error::DEFAULT_ERROR_MESSAGE, $variables),
      ];
    }
  }
  if (isset($context['sandbox']['#finished'])) {
    $context['finished'] = $context['sandbox']['#finished'];
    unset($context['sandbox']['#finished']);
  }
  if (!isset($context['results'][$extension][$name])) {
    $context['results'][$extension][$name] = [];
  }
  $context['results'][$extension][$name] = array_merge($context['results'][$extension][$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 @extension', [
    '@extension' => $extension,
  ]);
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
