I noticed that every time I did drush mi the nodes had their menu links removed. Not my favorite feature of Migrate :)

What's causing it is MigrateDestinationNode->import() which calls node_save() with a faux node object which in turn calls menu_node_save(). Because $node->menu['enabled'] hasn't been set (I assume it's the "Provide a menu link" checkbox from the node edit form) menu_node_save() will delete the node's menu link.

To me this seems like a shortcoming in core, maybe affecting other modules like Deploy and Feeds as well? It's not a problem if you first do node_load($node), but you don't always want to do that for performance reasons.

Anyway, the patch solves the problem for now.

CommentFileSizeAuthor
migrate_node_menu_trick.patch522 bytesximo

Comments

mikeryan’s picture

Status: Needs review » Closed (won't fix)

You had manually changed the node to provide a menu link, correct? The default operation of migration is to treat the source data as the system-of-record - it is intentional and correct that remigration of a node will wipe any manual changes. The alternative is setting the migration systemOfRecord to DESTINATION, which will do a node_load() and only change those fields which are present in the source, maintaining all other data on the destination side. These two alternatives are all that Migrate can reasonably handle automatically - if you need more complex handling, you can attain this by overriding the behavior with an appropriate handler or method. For example, in this case you can override the Migration class prepare() method (don't forget to call the parent!):

protected function prepare($node, $row) {
  parent::prepare($node, $row);
  // Make sure existing menu items are not deleted.
  $node->menu['enabled'] = (int) (bool) $node->menu['mlid'];
}
ximo’s picture

Thank you for taking the time to explain. Yes, I had manually added menu links for nodes, and wrongly assumed Migrate to be fine with that. I'll go with setting systemOfRecord to DESTINATION – that's exactly what I want.

Thanks also for the quick answer and a great module :)