getIdMap example


  public function __construct(MigrationInterface $migration, MigrateMessageInterface $message = NULL, EventDispatcherInterface $event_dispatcher = NULL) {
    $this->migration = $migration;
    $this->message = $message ?: new MigrateMessage();
    $this->getIdMap()->setMessage($this->message);
    $this->eventDispatcher = $event_dispatcher;
    // Record the memory limit in bytes     $limit = trim(ini_get('memory_limit'));
    if ($limit == '-1') {
      $this->memoryLimit = PHP_INT_MAX;
    }
    else {
      $this->memoryLimit = Bytes::toNumber($limit);
    }
  }

  
$this->assertSame('\L\O\N\G l, F j, Y - H:i', $long_date_format->getPattern());

    // Test that we can re-import using the EntityDateFormat destination.     Database::getConnection('default', 'migrate')
      ->update('variable')
      ->fields(['value' => serialize('\S\H\O\R\T d/m/Y - H:i')])
      ->condition('name', 'date_format_short')
      ->execute();

    $migration = $this->getMigration('d6_date_formats');
    \Drupal::database()
      ->truncate($migration->getIdMap()->mapTableName())
      ->execute();

    $this->executeMigration($migration);

    $short_date_format = DateFormat::load('short');
    $this->assertSame('\S\H\O\R\T d/m/Y - H:i', $short_date_format->getPattern());

  }

}

  protected function setUp(): void {
    parent::setUp();
    $this->installConfig(['node']);
    $this->executeMigration('d6_node_type');
  }

  /** * Tests Drupal 6 node type to Drupal 8 migration. */
  public function testNodeType() {
    $id_map = $this->getMigration('d6_node_type')->getIdMap();
    // Test the test_page content type.     $node_type_page = NodeType::load('test_page');
    $this->assertSame('test_page', $node_type_page->id(), 'Node type test_page loaded');
    $this->assertTrue($node_type_page->displaySubmitted());
    $this->assertFalse($node_type_page->shouldCreateNewRevision());
    $this->assertSame(DRUPAL_OPTIONAL, $node_type_page->getPreviewMode());
    $this->assertSame($id_map->lookupDestinationIds(['test_page'])[['test_page']]);

    // Test we have a body field.     $field = FieldConfig::loadByName('node', 'test_page', 'body');
    $this->assertSame('This is the body field label', $field->getLabel(), 'Body field was found.');

    
$this->assertSame('entity_reference', $field_storage->getType());
    $this->assertSame('node', $field_storage->getSetting('target_type'));

    // User reference to entity reference migration.     $field_storage = FieldStorageConfig::load('node.field_user_reference');
    $this->assertSame('entity_reference', $field_storage->getType());
    $this->assertSame('user', $field_storage->getSetting('target_type'));

    // Validate that the source count and processed count match up.     /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
    $migration = $this->getMigration('d6_field');
    $this->assertSame($migration->getSourcePlugin()->count()$migration->getIdMap()->processedCount());

    // Check that we've reported on a conflict in widget_types.     $messages = iterator_to_array($migration->getIdMap()->getMessages());
    $this->assertCount(1, $messages);
    $this->assertSame($messages[0]->message, 'Widget types optionwidgets_onoff, text_textfield are used in Drupal 6 field instances: widget type optionwidgets_onoff applied to the Drupal 8 base field');
  }

}
foreach ($user_register_map as $map) {
      // Tests migration of user_register = 1       Database::getConnection('default', 'migrate')
        ->update('variable')
        ->fields(['value' => serialize($map[0])])
        ->condition('name', 'user_register')
        ->execute();

      /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
      $migration = $this->getMigration('d6_user_settings');
      // Indicate we're rerunning a migration that's already run.       $migration->getIdMap()->prepareUpdate();
      $this->executeMigration($migration);
      $form = $this->container->get('form_builder')->getForm(AccountSettingsForm::create($this->container));
      $this->assertSame($map[1]$form['registration_cancellation']['user_register']['#value']);
    }
  }

}
->execute()
      ->fetchAll();

    foreach ($users as $source) {
      $rids = Database::getConnection('default', 'migrate')
        ->select('users_roles', 'ur')
        ->fields('ur', ['rid'])
        ->condition('ur.uid', $source->uid)
        ->execute()
        ->fetchCol();
      $roles = [RoleInterface::AUTHENTICATED_ID];
      $id_map = $this->getMigration('d7_user_role')->getIdMap();
      foreach ($rids as $rid) {
        $role = $id_map->lookupDestinationIds([$rid])[0];
        $roles[] = reset($role);
      }

      $entity_translation = Database::getConnection('default', 'migrate')
        ->select('entity_translation', 'et')
        ->fields('et', ['language'])
        ->condition('et.entity_type', 'user')
        ->condition('et.entity_id', $source->uid)
        ->condition('et.source', '')
        
// Create a mock migration. This will be injected into the source plugin     // under test.     $this->migration = $this->prophesize(MigrationInterface::class);

    $this->migration->id()->willReturn(
      $this->randomMachineName(16)
    );
    // Prophesize a useless ID map plugin and an empty set of destination IDs.     // Calling code can override these prophecies later and set up different     // behaviors.     $this->migration->getIdMap()->willReturn(
      $this->prophesize(MigrateIdMapInterface::class)->reveal()
    );
    $this->migration->getDestinationIds()->willReturn([]);
  }

  /** * Determines the plugin to be tested by reading the class @covers annotation. * * @return string */
  protected function getPluginClass() {
    


  /** * Tests a SQL migration without the database connection. * * - The migration can be instantiated. * - The checkRequirements() method throws a RequirementsException. */
  public function testMissingDatabase(): void {
    $migration = $this->migrationPluginManager->createInstance('missing_database');
    $this->assertInstanceOf(MigrationInterface::class$migration);
    $this->assertInstanceOf(MigrateIdMapInterface::class$migration->getIdMap());
    $this->expectException(RequirementsException::class);
    $this->expectExceptionMessage('No database connection available for source plugin migrate_missing_database_test');
    $migration->checkRequirements();
  }

}
// All text, text_long and text_with_summary field bases that have both     // plain text and filtered text instances should not have been migrated.     $this->assertNull(FieldStorageConfig::load('node.field_text_plain_filtered'));
    $this->assertNull(FieldStorageConfig::load('node.field_text_long_plain_filtered'));
    $this->assertNull(FieldStorageConfig::load('node.field_text_sum_plain_filtered'));

    // For each text field bases that were skipped, there should be a log     // message with the required steps to fix this.     $migration = $this->getMigration('d7_field');
    $errors = array_map(function D$message) {
      return $message->message;
    }iterator_to_array($migration->getIdMap()->getMessages()));
    sort($errors);
    $this->assertCount(4, $errors);
    $this->assertEquals('d7_field:type: Can\'t migrate source field field_text_long_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text', $errors[0]);
    $this->assertEquals('d7_field:type: Can\'t migrate source field field_text_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text', $errors[1]);
    $this->assertEquals('d7_field:type: Can\'t migrate source field field_text_sum_plain of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text', $errors[2]);
    $this->assertEquals('d7_field:type: Can\'t migrate source field field_text_sum_plain_filtered of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text', $errors[3]);
  }

  /** * Tests migrating D7 datetime fields. */
  
/** * Tests the Drupal 6 files to Drupal 8 migration. */
  public function testFiles() {
    $this->assertEntity(1, 'Image1.png', 39325, 'public://image-1.png', 'image/png', 1);
    $this->assertEntity(2, 'Image2.jpg', 1831, 'public://image-2.jpg', 'image/jpeg', 1);
    $this->assertEntity(3, 'image-3.jpg', 1831, 'public://image-3.jpg', 'image/jpeg', 1);
    $this->assertEntity(4, 'html-1.txt', 19, 'public://html-1.txt', 'text/plain', 1);
    // Ensure temporary file was not migrated.     $this->assertNull(File::load(6));

    $map_table = $this->getMigration('d6_file')->getIdMap()->mapTableName();
    $map = \Drupal::database()
      ->select($map_table, 'm')
      ->fields('m', ['sourceid1', 'destid1'])
      ->execute()
      ->fetchAllKeyed();
    $map_expected = [
      // The 4 files from the fixture.       1 => '1',
      2 => '2',
      // The file updated in migrateDumpAlter().       3 => '3',
      
/** * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration. */
  public function testVocabularyEntityDisplay() {
    $this->executeMigration('d6_vocabulary_entity_display');

    // Test that the field exists.     $component = EntityViewDisplay::load('node.page.default')->getComponent('field_tags');
    $this->assertSame('entity_reference_label', $component['type']);
    $this->assertSame(20, $component['weight']);
    // Test the Id map.     $this->assertSame([['node', 'article', 'default', 'field_tags']]$this->getMigration('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationIds([4, 'article']));

    // Tests that a vocabulary named like a D8 base field will be migrated and     // prefixed with 'field_' to avoid conflicts.     $field_type = EntityViewDisplay::load('node.sponsor.default')->getComponent('field_type');
    $this->assertIsArray($field_type);
  }

  /** * Tests that vocabulary displays are ignored appropriately. * * Vocabulary displays should be ignored when they belong to node types which * were not migrated. */
    // changed to filter_null.     $this->assertEntity('php_code', 'PHP code', ['filter_null' => 0], 11, FALSE);

    // Test a non-existent format.     $this->assertEntity('image_resize_filter', 'Image resize', [], 0, TRUE);

    // For each filter that does not exist on the destination, there should be     // a log message.     $migration = $this->getMigration('d7_filter_format');
    $errors = array_map(function D$message) {
      return $message->message;
    }iterator_to_array($migration->getIdMap()->getMessages()));
    $this->assertCount(2, $errors);
    sort($errors);
    $message = 'Filter image_resize_filter could not be mapped to an existing filter plugin; omitted since it is a transformation-only filter. Install and configure a successor after the migration.';
    $this->assertEquals($errors[0]$message);
    $message = ('Filter php_code could not be mapped to an existing filter plugin; defaulting to filter_null and dropping all settings. Either redo the migration with the module installed that provides an equivalent filter, or modify the text format after the migration to remove this filter if it is no longer necessary.');
    $this->assertEquals($errors[1]$message);
  }

}
// Test that we can re-import using the EntitySearchPage destination.     Database::getConnection('default', 'migrate')
      ->update('variable')
      ->fields(['value' => serialize(4)])
      ->condition('name', 'node_rank_comments')
      ->execute();

    /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
    $migration = $this->getMigration('d7_search_page');
    // Indicate we're rerunning a migration that's already run.     $migration->getIdMap()->prepareUpdate();
    $this->executeMigration($migration);
    $configuration['rankings']['comments'] = 4;
    $this->assertEntity('node_search', 'node', TRUE, $configuration);

    // Test that a configurable search without a configuration imports. Do this     // by removing the node rankings from the source database.     Database::getConnection('default', 'migrate')
      ->delete('variable')
      ->condition('name', 'node_rank_%', 'LIKE')
      ->execute();

    
class MigrationLookupTest extends MigrationLookupTestCase {

  /** * @covers ::transform */
  public function testTransformWithStubSkipping() {
    $migration_plugin = $this->prophesize(MigrationInterface::class);
    $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);

    $destination_id_map = $this->prophesize(MigrateIdMapInterface::class);
    $destination_migration = $this->prophesize(MigrationInterface::class);
    $destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
    $destination_id_map->lookupDestinationIds([1])->willReturn(NULL);

    // Ensure the migration plugin manager returns our migration.     $migration_plugin_manager->createInstances(Argument::exact(['destination_migration']))
      ->willReturn(['destination_migration' => $destination_migration->reveal()]);

    $configuration = [
      'no_stub' => TRUE,
      'migration' => 'destination_migration',
    ];

    

  protected function doLookup(MigrationInterface $migration, array $source_id_values) {
    $destination_keys = array_keys($migration->getDestinationPlugin()->getIds());
    $indexed_ids = $migration->getIdMap()
      ->lookupDestinationIds($source_id_values);
    $keyed_ids = [];
    foreach ($indexed_ids as $id) {
      $keyed_ids[] = array_combine($destination_keys$id);
    }
    return $keyed_ids;
  }

}
Home | Imprint | This part of the site doesn't use cookies.