Add option to create new revision in entity migration

Created on 26 July 2018, over 6 years ago
Updated 24 March 2023, almost 2 years ago

Problem/Motivation

With migrate, it would be great to be able to create new revision when you run the migration with update.

Proposed resolution

Add a "new_revision" option to entity destination plugin. If set to true, Drupal\migrate\Plugin\migrate\destination\Entity::getEntity() call setNewRevision(TRUE) on the entity.

Remaining tasks

  1. reviews needed
  2. tests to be written
  3. documentation to be written

API changes

None?
If you don't add this option in your migration, current behavior is preserved.

Feature request
Status

Needs work

Version

10.1

Component
Migration 

Last updated about 1 hour ago

Created by

🇫🇷France SylvainM

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany daveiano

    @stijndmd Your last changes breaks this for me. I debugged this down and in my case

    $id_map = $row->getIdMap();
    

    always returns

    {"original_hash":"","hash":"","source_row_status":1}.

    track_changes is set to true for the migration. The strange behaviour is that when I check the $id_map in prepareRow the hashes are in place and working.

    However, since track_changes is activated, there are only revisions created for changed rows, so I do not really get the requirement for these checks?

    Using patch from #32 in the meantime.

  • 🇫🇮Finland tvalimaa

    Patch #32 worked for me but it didn't change revision author or revision message. Revision author and message was same than previous revision...

  • 🇦🇺Australia mortim07

    We have an issue where ::setRevisionCreationTime doesn't exist on the entity. To make this patch more robust we should be checking for the interface that implements ::setRevisionCreationTime - Drupal\Core\Entity\RevisionLogInterface.

  • 🇨🇦Canada Shiraz Dindar Sooke, BC

    Patch #39 works great for me.

    Thanks everyone!

    As an aside: this seems like it would be a rather common need and I'm a bit surprised by the lack of activity on this thread. But this is only place I see this happening.

  • 🇫🇮Finland tvalimaa

    Hi, I tested patch #39 and it looks like working like #32 with translations

    drush mim --group=activity --update
     [notice] Processed 334 items (0 created, 301 updated, 0 failed, 33 ignored) - done with 'activities'
     [notice] Processed 334 items (0 created, 321 updated, 0 failed, 13 ignored) - done with 'activities_en'
    destination:
      plugin: entity:node
      new_revision: yes
    destination:
      plugin: entity:node
      translations: true
      new_revision: yes
  • 🇫🇮Finland tvalimaa

    Now API content has change so :
    This is never be false because it always have array key.
    if (!array_key_exists('original_hash', $id_map)

    This is ok.
    $id_map['hash'] !== $id_map['original_hash'])

    Maybe?
    if (!empty($id_map['original_hash']) && $id_map['hash'] !== $id_map['original_hash'])

  • 🇧🇬Bulgaria pfrenssen Sofia

    Idea: allow to set a revision log message and user ID.

Production build 0.71.5 2024