You are here

public function Node::undo in Search and Replace Scanner 8

Undo the replace operation by reverting entities to a previous revision.

Parameters

array $data: An array containing the revision ids needed to undo the previous replace operation.

Overrides Entity::undo

File

src/Plugin/Scanner/Node.php, line 209

Class

Node
Class Node.

Namespace

Drupal\scanner\Plugin\Scanner

Code

public function undo(array $data) {
  $revision = \Drupal::entityTypeManager()
    ->getStorage('node')
    ->loadRevision($data['old_vid']);
  $revision
    ->setNewRevision(TRUE);
  $revision->revision_log = $this
    ->t('Copy of the revision from %date via Search and Replace Undo', [
    '%date' => \Drupal::service('date.formatter')
      ->format($revision
      ->getRevisionCreationTime()),
  ]);
  $revision
    ->isDefaultRevision(TRUE);
  $revision
    ->save();
}