3

I have a node migration as part of a D6->D8 migration, and for the image field in the node, I've done a separate files migration, and then in my node migration, I just refer to the files migration to get the destination fid and write that to the image field.

field_image:
  plugin: iterator
  source: field_thumbnail
  process:
    target_id:
      plugin: migration
      migration: file
      source: fid

The problem I'm running into is the error listed in the title. This is the presave() function:

public function preSave() {
  parent::preSave();

  $width = $this->width;
  $height = $this->height;

  // Determine the dimensions if necessary.
  if (empty($width) || empty($height)) {
    $image = \Drupal::service('image.factory')->get($this->entity->getFileUri());
    if ($image->isValid()) {
      $this->width = $image->getWidth();
      $this->height = $image->getHeight();
    }
  }
}

It seems like it's dying because there is no image for that node, because it's dying at this line:

$image = \Drupal::service('image.factory')->get($this->entity->getFileUri());

It works just fine when there is an image for the node. Shouldn't this be skipped if there is no image found in the files migration? Is there a config option in the .yml file I can use to avoid this error?

Thanks.

UPDATE: I found this docs page on the skip_on_empty process plugin, and implemented as suggested on that page:

field_image:
  plugin: iterator
  source: field_thumbnail 
    process:
    target_id:
    -
      plugin: migration
      migration: file
      source: fid
    -
      plugin: skip_on_empty
      method: row

but I still get the same error, more than likely because in the pipeline, it's already errored out before it gets to the skip_on_empty plugin. However, if I switch things around:

field_image:
  plugin: iterator
  source: field_thumbnail 
    process:
    target_id:
    -
      plugin: skip_on_empty
      method: row
    -
      plugin: migration
      migration: file
      source: fid

Then the entire blog node is skipped if there is no image. How can I just skip trying to migrate the image if there is none?

1 Answer 1

1

I a similar issue on a previous migration, I found that a core issue sometimes causes that error.

The patch submitted fixed the problem on my case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.