I'm using the Migrate module to import data but I want to compare existing data in my Drupal content for one specific field before I overwrite it during an update migration.

PrepareRow() doesn't seem to have access to the destination data. I was hoping that Prepare() would as the inputs to prepare($entity, stdclass $row) suggest it has the entity in hand, however it appears that this entity is the fully constructed row it is about to import rather than the data from the destination object.

Is there any way I can get access to the unaltered destination row to do a comparison with my source row before the import happens?


Answer lies in PrepareRow() method you will implement... You always have access to source where reference to destination is given.. For example if you are importing a node you will have nodeid reference.. From node id you can get destination details using node_load api function..

Similarly for any other entity if you are updating you will have a reference in source using which you can load destination details...

  • Thanks, I dug around in the $row object that is passed to PrepareRow() and if it is an update (and not an add new), the destination row id shows up at $row->migrate_map_destid1, will use it to node_load. – Oddible May 2 '14 at 6:34
  • Awesome.. If one of the answers above fixes your issue, you should accept it (click the check mark next to the appropriate answer). That does two things. It lets everyone know your issue has been resolved, and it gives the person that helps you credit for the assist. See here for a full explanation – Anil Sagar May 2 '14 at 6:40

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.