Skip to content
Snippets Groups Projects

Issue #2988382: Add option to create new revision in entity migration

@@ -8,6 +8,7 @@
@@ -8,6 +8,7 @@
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
 
use Drupal\Core\Entity\RevisionableStorageInterface;
use Drupal\Core\Session\AccountSwitcherInterface;
use Drupal\Core\Session\AccountSwitcherInterface;
use Drupal\Core\TypedData\TranslatableInterface;
use Drupal\Core\TypedData\TranslatableInterface;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\Core\TypedData\TypedDataInterface;
@@ -20,6 +21,7 @@
@@ -20,6 +21,7 @@
use Drupal\migrate\Row;
use Drupal\migrate\Row;
use Drupal\user\EntityOwnerInterface;
use Drupal\user\EntityOwnerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
 
use Drupal\Core\Entity\RevisionableInterface;
// cspell:ignore validatable
// cspell:ignore validatable
@@ -328,6 +330,15 @@ protected function updateEntity(EntityInterface $entity, Row $row) {
@@ -328,6 +330,15 @@ protected function updateEntity(EntityInterface $entity, Row $row) {
$entity->$field_name = NULL;
$entity->$field_name = NULL;
}
}
 
if (!empty($this->configuration['new_revision']) && $entity instanceof RevisionableInterface && $this->storage instanceof RevisionableStorageInterface) {
 
$id_map = $row->getIdMap();
 
// Create a revision when "track_changes" is not enabled or when the source data has changed.
 
if (!array_key_exists('original_hash', $id_map) || $id_map['hash'] !== $id_map['original_hash']) {
 
$entity->setRevisionCreationTime(\Drupal::time()->getRequestTime());
 
$entity = $this->storage->createRevision($entity);
 
}
 
}
 
$this->setRollbackAction($row->getIdMap(), $rollback_action);
$this->setRollbackAction($row->getIdMap(), $rollback_action);
// We might have a different (translated) entity, so return it.
// We might have a different (translated) entity, so return it.
Loading