I can't find any specific reference to this problem elsewhere so here we go:
I have a source field of multiple items (comma-separated)
$row->content_authors = "55,56,57"
Which converts fine into an entityreference field using a sourceMigration from which to map values.
But if the field is empty ("") bad things happen, the resultant array is:
$node->field_author = array('und' => array(0 => array('target_id' => FALSE)));
Which generates an error when node_save() is called - because FALSE is not an integer.
I tracked the error down to the source mapping function, which returns a FALSE when there's nothing. This is treated as an actual value and transferred to the array.
I realise this is not necessarily a simple issue. But if the mapping function returned NULL if there's nothing to map, which is then used to determine that the field should be set to:
$node->field_author = array();
which will save correctly.
To get around it I use the prepare() method to check for the bad array and replace it. Obviously this is not ideal.
Comment | File | Size | Author |
---|---|---|---|
#1 | migrate-node_ref_skip_empty-1665332-1.patch | 525 bytes | greenjuls |
Comments
Comment #1
greenjuls CreditAttribution: greenjuls commentedI have the same issue, with some node_reference fields.
When source fields are empty, it throws the same error as adaddinsane on node_save().
I got this error since I updated Migrate from 2.3 to 2.4
I suspect that #1569612: Field handlers with skip_empty should only skip NULL values broke this by only skipping NULL but not FALSE anymore. And FALSE is what sourceMigration() returns when destination is not found.
I found no other way than patching the MigrateNodeReferenceFieldHandler class.
Comment #2
greenjuls CreditAttribution: greenjuls commentedComment #3
Dave Reid@greenjuls: This may probably help you out for all your fields if you add this to your base abstract Migration class:
Just ensure that all your specific migration classes' prepare() functions call parent::prepare($entity, $row) as the first line. I would really love for this to make it make to Migrate as well so that we wouldn't have to do this for each time we use Migrate.
Comment #4
ayalon CreditAttribution: ayalon commentedLife saver!
Comment #5
mikeryanI've committed greenjuls fix for node reference fields, applying it to user reference fields as well, for those narrow cases.
I've opened a separate issue for calling into the field defaulting mechanism: #1792894: Set configured defaults for empty fields
Comment #7
joelstein CreditAttribution: joelstein commentedHere's a DRY approach to Dave Reid's code, without patching Migrate:
And in each of your Migrate classes:
Comment #8
webdrips CreditAttribution: webdrips commentedFor those of you using migrate_d2d with the latest stable versions of all the migrate modules, if you're still having a problem with empty CCK textarea fields appearing in your migrated content (which may lead to theme problems), here's what I had to do as none of the above worked in my abstract class:
Note I have not fully tested the above to see if it's too liberally setting NULLs, so you may want to do this in your node class instead:
Don't forget to call
parent::prepare($entity, $row)
if your abstract class already has aprepare()
method.