1

Is it safe to change the entity bundle (e.g. node type or commerce product type) when updating an entity with Migrate API?

Specific use case:

The site already contains plenty of commerce_product entities with $product->type === 'product', that were imported with something other than Migrate API.

I now want to re-import these entities with Migrate API, updating the existing entities. Custom MigrateMap to sync by field or property, e.g. SKU

The product type should be changed to something else by the update, let's say $product->type === 'othertype'.

Some of the fields are the same in both bundles. Other fields only exist in one of the bundles. Data from obsolete fields should be discarded / deleted. This includes images from an image field.


So, I wonder if all of this will happen painlessly, or if I need to do something special to make it work.

I will try this anyway and see what happens, but I think it is useful to have this documented here on stackexchange.

9
  • I know there are modules like site:drupal.org/project node convert and drupal.org/project/bundleswitcher, so changing a bundle is technically possible.
    – donquixote
    Jul 13, 2016 at 14:13
  • Oops. I mean this of course. drupal.org/project/node_convert
    – donquixote
    Jul 14, 2016 at 0:40
  • @kiamlaluno Are you sure the title change does not obscure the intent of the question, if someone is looking at a list of questions? I realize the migrate context might be irrelevant for the solution. But it is relevant for people looking specifically for the problem within a migrate context.
    – donquixote
    Jul 14, 2016 at 0:44
  • We have tags for that purpose; there is no need to repeat them in the title, in the same way there is no need to put Drupal in the title.
    – apaderno
    Jul 14, 2016 at 6:31
  • If you look at a list of related questions in the sidebar, you don't see the tags. But you do know it is drupal.stackexchange. Also the tag "migration" does not necessarily mean the specific "Migrate API" module, does it? I don't want to discuss this forever. If I cannot convince you I will leave the name change :)
    – donquixote
    Jul 14, 2016 at 16:30

1 Answer 1

1

That seems dangerous to me - a node's bundle is fundamental to its identity, and has repercussions well beyond the node's data itself. You're on Drupal 7, presumably? Simple way to test would be a script like:

$node = node_load(5);
$node->type = 'other_type';
node_save($node);

If it breaks there, it'll break with migration too. And if it works there, it should work with migration.

3
  • Well, the existence of drupal.org/project/node_convert suggests that it is generally possible. But maybe not trivial. I will try and report how it works. I imagine that it will work if the validation of the new type passes. But there could be broken leftovers.
    – donquixote
    Jul 14, 2016 at 0:51
  • And I should mention that node_convert has worked reliably for me in past projects.
    – donquixote
    Jul 22, 2016 at 22:48
  • So far in this new project, the product type converting seems ok so far. I will report if there are problems. Also see drupal.stackexchange.com/questions/208040/…
    – donquixote
    Jul 22, 2016 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.