I succeed to import the Image data (Alt, and title) and it's working when there is only one image in the Image field, but when there is multiple images, it just skip the import of the entire node and return this error:

array_flip(): Can only flip STRING and INTEGER values! [error]
File /home/website/bigd7/includes/entity.inc, line 178

Here my code:
In the constructor:

 $this->sourceFields['image_title'] = 'Image Title text extracted from data';
    $this->sourceFields['image_alt'] = 'Image alt text extracted from data';
  

Then the mapping:

 $this->addFieldMapping('field_image:alt', 'image_alt');
 $this->addFieldMapping('field_image:title', 'image_title');
 
    $this->addFieldMapping('field_image', 'field_main_image')
  ->sourceMigration('Files');
$this->addFieldMapping('field_image:file_class')
  ->defaultValue('MigrateFileFid');
  $this->addFieldMapping('field_image:preserve_files')
         ->defaultValue(TRUE);//not working
         $this->addFieldMapping('field_image:file_replace')->defaultValue('FILE_EXISTS_REUSE');//not working

And then in the prepareRow:

    $row->image_description = array();
    $row->image_alt = array();
    $row->image_title = array();
    $datas = $row->{'field_main_image:data'};
    foreach ($datas as $data) {
        $data = unserialize($data);
        if(!empty($data['description']))
            $row->image_description[] = $data['description'];
        else 
            $row->image_description[] = "";
        if(!empty($data['alt']))
            $row->image_alt[] = $data['alt'];
        else 
            $row->image_alt[] = "";
        if(!empty($data['title']))
            $row->image_title[] = $data['title'];
        else 
            $row->image_title[] = "";
    }

When I remove the Alt/Title mapping, it's just import multiple images without any error.

Can you see the bug?

Comments

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

There's nothing obviously wrong I can see, although it's unusual to map subfields before the main field, I would move the :alt and title: mappings later - this would break with earlier versions of Migrate, what version are you running?

Try printing $row at the end of prepareRow and make sure it looks right - in particular, that field_main_image, image_alt, and image_title are all arrays of strings and are all in sync with each other.

kobee’s picture

Here the version I use:
Migrate 7.x-2.5
Drupal-to-Drupal migration (migrate_d2d) 7.x-2.0+4-dev

Here the output of the var_dump($row):

 ["field_main_image"]=>
  array(8) {
    [0]=>
    string(5) "14516"
    [1]=>
    string(5) "14517"
    [2]=>
    string(5) "14518"
    [3]=>
    string(5) "14519"
    [4]=>
    string(5) "14520"
    [5]=>
    string(5) "14521"
    [6]=>
    string(5) "14522"
    [7]=>
    string(5) "14523"
  }
  ["field_main_image:list"]=>
  array(8) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "1"
    [2]=>
    string(1) "1"
    [3]=>
    string(1) "1"
    [4]=>
    string(1) "1"
    [5]=>
    string(1) "1"
    [6]=>
    string(1) "1"
    [7]=>
    string(1) "1"
  }
  ["field_main_image:data"]=>
  array(8) {
    [0]=>
    string(54) "a:2:{s:5:"title";s:11:"Roy Hodgson";s:3:"alt";s:0:"";}"
    [1]=>
    string(49) "a:2:{s:5:"title";s:7:"Ramires";s:3:"alt";s:0:"";}"
    [2]=>
    string(57) "a:2:{s:5:"title";s:14:"Lee Cattermole";s:3:"alt";s:0:"";}"
    [3]=>
    string(54) "a:2:{s:5:"title";s:11:"Avram Grant";s:3:"alt";s:0:"";}"
    [4]=>
    string(60) "a:2:{s:5:"title";s:17:"Laurent Koscielny";s:3:"alt";s:0:"";}"
    [5]=>
    string(59) "a:2:{s:5:"title";s:16:"Roman Abramovich";s:3:"alt";s:0:"";}"
    [6]=>
    string(54) "a:2:{s:5:"title";s:11:"Alan Pardew";s:3:"alt";s:0:"";}"
    [7]=>
    string(58) "a:2:{s:5:"title";s:15:"Roberto Mancini";s:3:"alt";s:0:"";}"
  }

 ["image_alt"]=>
  array(8) {
    [0]=>
    string(0) ""
    [1]=>
    string(0) ""
    [2]=>
    string(0) ""
    [3]=>
    string(0) ""
    [4]=>
    string(0) ""
    [5]=>
    string(0) ""
    [6]=>
    string(0) ""
    [7]=>
    string(0) ""
  }
  ["image_title"]=>
  array(8) {
    [0]=>
    string(11) "Roy Hodgson"
    [1]=>
    string(7) "Ramires"
    [2]=>
    string(14) "Lee Cattermole"
    [3]=>
    string(11) "Avram Grant"
    [4]=>
    string(17) "Laurent Koscielny"
    [5]=>
    string(16) "Roman Abramovich"
    [6]=>
    string(11) "Alan Pardew"
    [7]=>
    string(15) "Roberto Mancini"
  }

Tried to push down the alt, but no success.

Anything else?

mikeryan’s picture

Please upgrade to at least the 2.6-beta1 version of the Migrate module and see if that works any better.

kobee’s picture

It works!

Thanks.

BTW, when do you plan to release the Migrate2.6?

mikeryan’s picture

Status: Postponed (maintainer needs more info) » Fixed

The beta will stay out there for a couple of weeks, then my plan is to put out a release candidate (unless no significant issues come up in the meantime, in which case I'll go directly to full release).

Status: Fixed » Closed (fixed)

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