Hello.

My first post on here so please be gentle...

I am having some difficulty with migrating users from a legacy DB into Drupal 7 using the Migrate module. The legacy data is very messy and not structured very well. The issue I am having is with pulling the correct created date and then saving this against the user in Drupal.

The problem is that the created date exists in two places on the legacy table (kinda)! The table has a 'creation_date' field however this has a default value of '0000-00-00 00:00:00'. Around 1/3 of the users have a creation_date of '0000-00-00 00:00:00', but they do have a 'last_mod_date' with a usable value... the other 2/3 of users have an actual creation_date value.

So what I want to do is pull all users, if they have a 'creation_date' value of '0000-00-00 00:00:00' grab and use the 'last_mod_date' date, otherwise use the 'creation_date' value.

I can do this is SQL with the below. However I can’t see how to replicate this using Drupal.

SELECT *, IF (creation_date = '0000-00-00 00:00:00', last_mod_date, creation_date) AS date_added FROM oldusers.subscribed_user_union;

I gave up on doing this with SQL and looked at doing it in the addFieldMapping part of the migration.

However, I can’t see how you can pass two values to $this->addFieldMapping(), and select one to use based on the above. The ->callbacks method seems to only work on a single value and allow some manipulation to occur before saving.

So I am unsure if/how I can do this.

Hopefully I explained the above ok. Any pointers would be appreciated very much.

Thanks, Ali

Comments

ali.day’s picture

Using the: prepareRow($current_row) function and simply overwriting one value with the other if it contains all zeroes.