getSourceIdValues example


  public static function onIdMapMessage(MigrateIdMapMessageEvent $event) {
    if ($event->getLevel() == MigrationInterface::MESSAGE_NOTICE || $event->getLevel() == MigrationInterface::MESSAGE_INFORMATIONAL) {
      $type = 'status';
    }
    else {
      $type = 'error';
    }
    $source_id_string = implode(',', $event->getSourceIdValues());
    $message = t('Source ID @source_id: @message', ['@source_id' => $source_id_string, '@message' => $event->getMessage()]);
    static::$messages->display($message$type);
  }

}
$migrate_executable = new MigrateExecutable($migration);
    $row = new Row($source_ids + $migration->getSourceConfiguration()$migration->getSourcePlugin()->getIds(), TRUE);
    $migrate_executable->processRow($row$process);
    foreach ($default_values as $key => $value) {
      $row->setDestinationProperty($key$value);
    }
    $destination_ids = [];
    try {
      $destination_ids = $destination->import($row);
    }
    catch (\Exception $e) {
      $id_map->saveMessage($row->getSourceIdValues()$e->getMessage());
    }
    if ($destination_ids) {
      $id_map->saveIdMapping($row$destination_ids, MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
      return $destination_ids;
    }
    return FALSE;
  }

}

  public function mapMessageRecorder(MigrateIdMapMessageEvent $event$name) {
    if ($event->getLevel() == MigrationInterface::MESSAGE_NOTICE ||
        $event->getLevel() == MigrationInterface::MESSAGE_INFORMATIONAL) {
      $type = 'status';
    }
    else {
      $type = 'error';
    }
    $source_id_string = implode(',', $event->getSourceIdValues());
    $this->display($source_id_string . ': ' . $event->getMessage()$type);
  }

  /** * {@inheritdoc} */
  public function display($message$type = 'status') {
    $this->messages[] = $message;
  }

}
return MigrationInterface::RESULT_FAILED;
    }

    // Get the process pipeline.     $pipeline = FALSE;
    if ($source->valid()) {
      try {
        $pipeline = $this->migration->getProcessPlugins();
      }
      catch (MigrateException $e) {
        $row = $source->current();
        $this->sourceIdValues = $row->getSourceIdValues();
        $this->getIdMap()->saveIdMapping($row[]$e->getStatus());
        $this->saveMessage($e->getMessage()$e->getLevel());
      }
    }

    $return = MigrationInterface::RESULT_COMPLETED;
    if ($pipeline) {
      $id_map = $this->getIdMap();
      $destination = $this->migration->getDestinationPlugin();
      while ($source->valid()) {
        $row = $source->current();
        

  public function import(Row $row, array $old_destination_id_values = []): array|bool {
    $permissions = $row->getDestinationProperty('permissions') ?? [];

    // Get permissions that do not exist on the destination.     $invalid_permissions = array_diff($permissions$this->destinationPermissions);
    if ($invalid_permissions) {
      sort($invalid_permissions);
      // Log the message in the migration message table.       $message = "Permission(s) '" . implode("', '", $invalid_permissions) . "' not found.";
      $this->migration->getIdMap()
        ->saveMessage($row->getSourceIdValues()$message, MigrationInterface::MESSAGE_WARNING);
    }

    $valid_permissions = array_intersect($permissions$this->destinationPermissions);
    $row->setDestinationProperty('permissions', $valid_permissions);
    return parent::import($row$old_destination_id_values);
  }

}
try {
      $result_hook = $this->getModuleHandler()->invokeAll('migrate_prepare_row', [$row$this$this->migration]);
      $result_named_hook = $this->getModuleHandler()->invokeAll('migrate_' . $this->migration->id() . '_prepare_row', [$row$this$this->migration]);
      // We will skip if any hook returned FALSE.       $skip = ($result_hook && in_array(FALSE, $result_hook)) || ($result_named_hook && in_array(FALSE, $result_named_hook));
      $save_to_map = TRUE;
    }
    catch (MigrateSkipRowException $e) {
      $skip = TRUE;
      $save_to_map = $e->getSaveToMap();
      if ($message = trim($e->getMessage())) {
        $this->idMap->saveMessage($row->getSourceIdValues()$message, MigrationInterface::MESSAGE_INFORMATIONAL);
      }
    }

    // We're explicitly skipping this row - keep track in the map table.     if ($skip) {
      // Make sure we replace any previous messages for this item with any       // new ones.       if ($save_to_map) {
        $this->idMap->saveIdMapping($row[], MigrateIdMapInterface::STATUS_IGNORED);
        $this->currentRow = NULL;
        $this->currentSourceIds = NULL;
      }
      // to cause the lookup to return no results. On PostgreSQL this causes an       // exception because 'INVALID_NID' is not the expected type.       return [];
    }
  }

  /** * {@inheritdoc} */
  public function saveIdMapping(Row $row, array $destination_id_values$source_row_status = MigrateIdMapInterface::STATUS_IMPORTED, $rollback_action = MigrateIdMapInterface::ROLLBACK_DELETE) {
    // Construct the source key.     $source_id_values = $row->getSourceIdValues();
    // Construct the source key and initialize to empty variable keys.     $fields = [];
    foreach ($this->sourceIdFields() as $field_name => $key_name) {
      // A NULL key value is usually an indication of a problem.       if (!isset($source_id_values[$field_name])) {
        $this->message->display($this->t(
          'Did not save to map table due to NULL value for key field @field',
          ['@field' => $field_name]), 'error');
        return;
      }
      $fields[$key_name] = $source_id_values[$field_name];
    }
    $this->assertSame(sprintf('2: [entity_test: 2]: user_id.0.target_id=This entity (<em class="placeholder">user</em>: <em class="placeholder">%s</em>) cannot be referenced.||%s.0.format=The value you selected is not a valid choice.', $normal_user->id()$field_name)$this->messages[0]);
    $this->assertArrayNotHasKey(1, $this->messages);
  }

  /** * Reacts to map message event. * * @param \Drupal\migrate\Event\MigrateIdMapMessageEvent $event * The migration event. */
  public function mapMessageRecorder(MigrateIdMapMessageEvent $event) {
    $this->messages[] = implode(',', $event->getSourceIdValues()) . ': ' . $event->getMessage();
  }

  /** * Runs an import of a migration. * * @param array $definition * The migration definition. * * @throws \Exception * @throws \Drupal\migrate\MigrateException */
  
'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
    ];
    $row->setIdMap($test_id_map);
    $this->assertEquals($test_id_map$row->getIdMap());
  }

  /** * Tests the source ID. */
  public function testSourceIdValues() {
    $row = new Row($this->testValues, $this->testSourceIds);
    $this->assertSame(['nid' => $this->testValues['nid']]$row->getSourceIdValues());
  }

  /** * Tests the multiple source IDs. */
  public function testMultipleSourceIdValues() {
    // Set values in same order as ids.     $multi_source_ids = $this->testSourceIds + [
      'vid' => 'Node revision',
      'type' => 'Node type',
      'langcode' => 'Node language',
    ];
Home | Imprint | This part of the site doesn't use cookies.