update_invoke_post_update($function, &$context)
Executes a single hook_post_update_NAME().
string $function: The function name, that should be executed.
array $context: The batch context array.
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]); } } // @TODO We may want to do different error handling for different exception // types, but for now we'll just log the exception and return the message // for printing. // @see https://www.drupal.org/node/2564311 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] = array(); } $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]); }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!includes!update.inc/function/update_invoke_post_update/8.1.x