You are here

public static function Schemas::batchProcessUpdate in Express 8

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.

File

themes/contrib/bootstrap/src/Plugin/Setting/Schemas.php, line 133
Contains \Drupal\bootstrap\Plugin\Setting\Schemas.

Class

Schemas
The "schemas" theme setting.

Namespace

Drupal\bootstrap\Plugin\Setting

Code

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);
  } catch (\Exception $e) {
    $variables['@message'] = $e
      ->getMessage();
    $context['results']['errors'][] = t('<strong>[@theme][@schema] @label</strong> - @message', $variables);
  }
}