function public static function Schemas::batchProcessUpdate

8.x-3.x Schemas.php public static Schemas::batchProcessUpdate($theme_name, $update_id, array &$context)

Processes an update in a batch operation.

Parameters

string $theme_name: The machine name of the theme this update is being applied to.

string $update_id: The combined identifier of the update being applied, e.g. provider:schema.

array $context: The batch context.

Class

Schemas
The "schemas" theme setting.

Namespace

Drupal\bootstrap\Plugin\Setting

Source src/Plugin/Setting/Schemas.php (line 131)

public static function batchProcessUpdate($theme_name, $update_id, array &$context) {
  // Reconstruct the theme object this update is being applied to.
  $theme = Bootstrap::getTheme($theme_name);

  // Reconstruct the update plugin that is being applied.
  list($provider, $plugin_id) = explode(':', $update_id);
  $provider = Bootstrap::getTheme($provider);

  /* @type \Drupal\bootstrap\Plugin\Update\UpdateInterface $update */
  $update = $provider->getUpdateManager()->createInstance($plugin_id, ['theme' => $provider]);

  // Initialize results with theme name and installed schemas.
  if (!isset($context['results']['theme_name'])) {
    $context['results']['theme_name'] = $theme_name;
  }
  if (!isset($context['results']['schemas'])) {
    $context['results']['schemas'] = $theme->getSetting('schemas', []);
  }

  $schemas = &$context['results']['schemas'];

  $variables = [
    '@theme' => $update->getTheme()->getName(),
    '@schema' => $update->getSchema(),
    '@label' => $update->getLabel(),
  ];

  // Perform the update.
  try {
    // Attempt to perform the update.
    if ($update->update($theme, $context) === FALSE) {
      throw new \Exception(t('Update failed'));
    }

    // Store the results.
    $schemas[$update->getTheme()->getName()] = $update->getSchema();

    $context['results']['success'][] = t('<strong>[@theme][@schema] @label</strong>', $variables);
  }
  // Capture any errors.
  catch (\Exception $e) {
    $variables['@message'] = $e->getMessage();
    $context['results']['errors'][] = t('<strong>[@theme][@schema] @label</strong> - @message', $variables);
  }
}