Problem/Motivation
When importing from a Drupal 6 site, I am getting the following error which causes the migration of a given node type to fail:
Migration failed with source plugin exception: Illegal string offset 'alt' File /migrate_d2d/d6/d6.inc, line 307
Digging through the code, that would be this excerpt:
if ($display_name == "$field_name:alt") {
$row->{$index}[] = $data['alt'];
}
In my case, $data is not an array at all but a string. Specifically, it's a string "b:0;", which is the serialized form of boolean FALSE in PHP. (iknowright?)
As near as I can guess, the problem is that not all nodes in my dataset HAVE a value for a specific image field. How that's turning into a serialized FALSE I have no idea, but that's my working theory. The particular PHP error in question (string offset of a string) didn't used to be an error pre PHP 5.4, which may be why it went unnoticed until now.
Proposed resolution
This is perhaps not the best solution, but it makes the code a little more robust at least. There's no possible way for that code block to work if $data is not an array. So, verify that it's an array and skip it otherwise. It works for me, at least.
Comment | File | Size | Author |
---|---|---|---|
#5 | 2466405-5-illegal_string_offset.patch | 585 bytes | ekes |
#1 | 2466405-string-offset-error.patch | 1.87 KB | Crell |
Comments
Comment #1
Crell CreditAttribution: Crell at Palantir.net commentedAnd patch.
Comment #2
mikeryanYep, looks reasonable, committed. Thanks!
Comment #5
ekes CreditAttribution: ekes commentedThe if (is_array($data) && $data) reached out a bit wide there.
$data is NULL unless it's a filefield (it set just before the foreach loop this is in). The if included the non-filefield case where it maps $field_row->$column_name. Attached patch just moves that back outside, and maintains mapping $field_row->$column_name and the unserialized filefield cases.
Comment #6
mikeryanGood catch - committed, thanks!
Comment #8
mikeryanThis broke multi-value file field imports - I'll fix it at #2485895: Migrating multivalue images doesn't work.
Comment #9
ekes CreditAttribution: ekes commentedActually was a bit quick with my fix too. It should be if, not elseif. Otherwise the file doesn't get the fid stored.
ie:
- elseif (isset($field_row->$column_name)) {
- $row->{$index}[] = $field_row->$column_name;
+ if (isset($field_row->$column_name)) {
+ $row->{$index}[] = $field_row->$column_name;