When importing a new entity via Migrate, the assigned values are "overwritten" by the behaviour values, but that might not to be useful if the one wants to import the original creation date or author UID.

I'll post a patch for solving that, in the next comment. ;)

Comments

derhasi’s picture

Title: Let "Migrate" import behaviour driven parameters » Let "Migrate" import behaviour driven properties
Status: Active » Needs review
StatusFileSize
new1.09 KB

And there it is, a patch, that does only implement the behviour specific functions if no migrate flag is set.

The wrapper function might be used for other modules (or an hook) too.

fmizzell’s picture

Status: Needs review » Active

@derhasi, thank you for the patch. I am not sure that adding code to the behavior is the best way to handle the problem. I have not used migrate, so I do not know how it works, but would deactivating the behavior work?

I added a couple of function to the EntityType class to make that easier:

 //deactive the behavior of the 'changed' property
    $entity_type = EntityType::loadByName($entity_type);
    $entity_type->removeBehavior('changed');
    $entity_type->save();

    //do stuff with entities of $entity_type while the changed behavior is deactivated
    
    //reactivate the 'changed' behavior in the 'changed' property
    $entity_type->changeBehavior('changed', 'changed');
    $entity_type->save();

would this approach work?

derhasi’s picture

That would not work for migrate and other modules, as the entity is often not build AND saved in one process, like in Rules or Migrate, first alle fields are populated, and after some time, the entity is saved.

derhasi’s picture

Status: Active » Needs review
fmizzell’s picture

Do you think the solution presented by @acrazyanimal here #1600838: Author and Created behaviours override previously set values would solve the problem? I think the solution in the other issue is a little bit more general than an if statement targeted to the migrate module. Let me know, otherwise I will push your path through until a better solution can be implemented.

acrazyanimal’s picture

Status: Needs review » Closed (duplicate)

The patch in #1600838: Author and Created behaviours override previously set values has been committed and should resolve this issue as well. Marking as fixed.

derhasi’s picture

Status: Closed (duplicate) » Needs work

Sorry, but that patch does not fix this issues problem, as it also occurs for the "changed" behaviour.

acrazyanimal’s picture

Gotcha! Right, I had assumed that 'changed' would always be the date that it was changed and thus we didn't need to worry about this case. However, I did not consider imports/migration on entity creation. Cool I'll see what I can do.

acrazyanimal’s picture

Status: Needs work » Needs review
StatusFileSize
new987 bytes

Try this patch out.

fmizzell’s picture

Status: Needs review » Fixed

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 64e9360 on 7.x-2.x, change_paths, own_permissions, 7.x-2.x-property-widgets, 7.x-3.x, entity_reference, 7.x-3.x-settings, 7.x-2.0.x, 7.x-2.1.x authored by acrazyanimal, committed by fmizzell:
    #1546972 Let Migrate import behaviour driven properties
    

  • Commit 64e9360 on 7.x-2.x, change_paths, own_permissions, 7.x-2.x-property-widgets, 7.x-3.x, entity_reference, 7.x-3.x-settings, 7.x-2.0.x, 7.x-2.1.x authored by acrazyanimal, committed by fmizzell:
    #1546972 Let Migrate import behaviour driven properties
    

  • Commit 64e9360 on 7.x-2.x, 7.x-3.x, 8.x authored by acrazyanimal, committed by fmizzell:
    #1546972 Let Migrate import behaviour driven properties
    

  • Commit 64e9360 on 7.x-2.x, 7.x-3.x, 8.x authored by acrazyanimal, committed by fmizzell:
    #1546972 Let Migrate import behaviour driven properties