We have an export from a database (non-drupal) in which rows are basically listed as:

row 1) id:1, langcode: nl
row 2) id:1, langcode: fr
row 3) id:1, langcode: en

I have configured the my_migration yml as follows:

source:
  plugin: migration_custom
process:
  nid:
    plugin: migration
    source: news_article_id
    migration: my_migration
    no_stub: true
  langcode: langcode
  ...
destination:
  plugin: entity:node
  translations: true

The migration_custom class extends SqlBase and provides these fields:
- news_article_id, langcode
and the getIds() returns this array

     [
      'news_article_id' => [
        'type'  => 'integer',
      ],
      'langcode' => [
        'type' => 'string',
      ],

When running the migration, all rows are migrated, but are not linked as a translation of each other. When importing the 2nd row, a translation of the first, upon debugging I found that in the transform method of the process/Migration class, the returned destinations ids is this an array: array(0=>'2', 1=>'nl'). 2 being the nid of the node representing the first row.

The last part of the transform method however does this:

if ($destination_ids) {
      if ($scalar) {
        if (count($destination_ids) == 1) {
          return reset($destination_ids);
        }
      }
      else {
        return $destination_ids;
      }
    } 

Because the process plugin of the 'nid' field only has one source value, the $scalar is set to true. The count($destination_ids) returns 2 and thus nothing is returned.

So question, is this a bug, or do I need to configure the whole thing in a different matter??

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kriboogh created an issue. See original summary.

kriboogh’s picture

Issue summary: View changes
kriboogh’s picture

Issue summary: View changes
kriboogh’s picture

Category: Support request » Bug report

Removing the extra check on the count makes the code work... so maybe someone can have a look at it to see why this check is necessary.

if ($destination_ids) {
      if ($scalar) {
        return reset($destination_ids);
      }
      else {
        return $destination_ids;
      }
    } 
kriboogh’s picture

Status: Active » Needs review
heddn’s picture

Category: Bug report » Support request
Status: Needs review » Active

Marking as a support request and leaving as active. There is not patch to review.

kriboogh’s picture

Status: Active » Needs review
FileSize
680 bytes

Heres a patch agains the latest 8.2

heddn’s picture

Status: Needs review » Closed (duplicate)