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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Crell’s picture

Status: Active » Needs review
FileSize
1.87 KB

And patch.

mikeryan’s picture

Status: Needs review » Fixed

Yep, looks reasonable, committed. Thanks!

  • mikeryan committed aea662a on 7.x-2.x authored by Crell
    Issue #2466405 by Crell: Illegal string offset 'alt'
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ekes’s picture

Status: Closed (fixed) » Needs review
FileSize
585 bytes

The 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.

mikeryan’s picture

Status: Needs review » Fixed

Good catch - committed, thanks!

  • mikeryan committed a5f70fc on 7.x-2.x authored by ekes
    Issue #2466405 by ekes: Fix to file property fix
    
mikeryan’s picture

This broke multi-value file field imports - I'll fix it at #2485895: Migrating multivalue images doesn't work.

ekes’s picture

Actually 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;

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.