0

I need to migrate new nodes and update others in the same time. 2 installations of the same project are out of sync, which means, that the same nid may not indicate the same node on both sides. But I'm sure they're the same if their titles are equal. So I think, that I need a conditional field mapping, as illustrated in the following pseudocode:

if source_nid = destination_nid
  if source_title = destination_title
    addFieldMapping('nid', 'nid')
else 
  continue

I have only one idea, how can I do this - split migrations into two different parts with filters managed by prepareRow() method (one of the for node updating, the other for import of new nodes). Is this the only way? I would appreciate something more elegant.

0

OK, at least now I know, that splitting migration into two with filtered rows works just fine. prepareRow function looks like this:

public function prepareRow($row) {
  // If node exists on destination
  if ($node = node_load($row->nid)) {
    // Use the metatdata wrapper to pull values
    $node_wrapper = entity_metadata_wrapper('node', $node);
    // If destination title is the same as source title
    if ($node_wrapper->label() == $row->title) {
      return TRUE;
    }
    else {
      return FALSE;
    }
  }
  else {
    return FALSE;
  }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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