2

On the migrate module, my source migration "ProductImageMigration" gets all the files from the database and loads them correctly into my public folder. Checked and double checked, not a single error.

I have a field "field_product_main_images" that includes an unlimited amount of images.

"field_product_main_images" settings:

type: 'image'
allowed-extensions: png, gif, jpg, jpeg
alt & title field enabled
Unlimited amount of values
public files

My "ProductMigration" has following code for my main images:

$query->addExpression("CONCAT_WS(',', GROUP_CONCAT(DISTINCT ct_f.field_foto1_fid), GROUP_CONCAT(DISTINCT gai.fid))", 'main_images');

$this->addFieldMapping('field_product_main_images', 'main_images')
  ->separator(',')
  ->sourceMigration('ProductImages');

$this->addFieldMapping('field_product_main_images:file_class')
  ->defaultValue('MigrateFileFid');

$this->addFieldMapping('field_product_main_images:preserve_files')
  ->defaultValue(TRUE);

When I do an output of my row's main_images I get:

drush_print_r('For product ' . $row->title . ' following images:');
drush_print_r($row->main_images);

// OUTPUT
For product Trampolines walljumping following images:
5248,5249,5250

Which I lookup in my mapping table and finds all possible images. The strange thing is that only one is added to my products, which is good, but I really need all of them...

UPDATE

If I dig deeper, I come across the (possible) strange behaviour that my node id's are getting flushed on the prepare statement of the node.

I'm not doing anything in my custom migration's prepare statement, so that isn't altering anything. This is what I put in my import function of the node.inc file:

public function import(stdClass $node, stdClass $row) {
  ...
  drush_print_r('Prepare node - BEFORE');
  drush_print_r($node->field_product_main_images);

  // Invoke migration prepare handlers
  $this->prepare($node, $row);

  drush_print_r('Prepare node - After');
  drush_print_r($node->field_product_main_images);
  ...
}

I get following output in my console:

Prepare node - BEFORE
Array
(
  [0] => 29226
  [1] => 28598
  [2] => 28599
  [arguments] => Array
    (
        [alt] => Trampolines walljumping
        [file_class] => MigrateFileFid
        [language] => nl
        [preserve_files] => 1
        [title] => Trampolines walljumping
    )
)

And then:

Prepare node - After
Array
(
  [und] => Array
    (
        [0] => Array
            (
                [fid] => 29226
                [alt] => Trampolines walljumping
                [title] => Trampolines walljumping
            )

    )
)

So the prepare statement loses 2 of my images... Why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.