You are here

public static function ScannerConfirmUndoForm::batchUndo in Search and Replace Scanner 8

Helper function to handle batch operation.

Parameters

array $data: The array containing the revision ids for each entity.

string $undo_id: The id of the undo record.

array $context: The array containing the data which is persisted across jobs.

File

src/Form/ScannerConfirmUndoForm.php, line 79

Class

ScannerConfirmUndoForm
Displayed to confirm that the user want to undo the replace operation.

Namespace

Drupal\scanner\Form

Code

public static function batchUndo(array $data, $undo_id, array &$context) {
  $pluginManager = \Drupal::service('plugin.manager.scanner');
  try {
    $plugin = $pluginManager
      ->createInstance('scanner_entity');

    // This process can take a while so we want to extend the execution time
    // if it's less then 300 (5 minutes).
    if (ini_get('max_execution_time') < 300) {
      ini_set('max_execution_time', '300');
    }
  } catch (PluginException $e) {

    // The instance could not be found so fail gracefully and let the user
    // know.
    \Drupal::logger('scanner')
      ->error($e
      ->getMessage());
    \Drupal::messenger()
      ->addError($this
      ->t('An error occured @e:', [
      '@e' => $e
        ->getMessage(),
    ]));
  }
  $plugin
    ->undo($data);
  $context['results']['undo_id'] = $undo_id;
  $context['message'] = 'Undoing...';
}