function NodeMigrateTypeTestTrait::makeNodeMigrateMapTable

Same name and namespace in other branches
  1. 9 core/modules/migrate_drupal/tests/src/Traits/NodeMigrateTypeTestTrait.php \Drupal\Tests\migrate_drupal\Traits\NodeMigrateTypeTestTrait::makeNodeMigrateMapTable()
  2. 8.9.x core/modules/migrate_drupal/tests/src/Traits/NodeMigrateTypeTestTrait.php \Drupal\Tests\migrate_drupal\Traits\NodeMigrateTypeTestTrait::makeNodeMigrateMapTable()
  3. 10 core/modules/migrate_drupal/tests/src/Traits/NodeMigrateTypeTestTrait.php \Drupal\Tests\migrate_drupal\Traits\NodeMigrateTypeTestTrait::makeNodeMigrateMapTable()

Create a node migrate_map table.

Parameters

string $type: The type of node migration, 'complete' or 'classic'.

string $version: The source database version.

Throws

\Exception

5 calls to NodeMigrateTypeTestTrait::makeNodeMigrateMapTable()
MigrateDrupal6TestBase::setUp in core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php
MigrateDrupal7TestBase::setUp in core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
MigrateDrupalTestBase::setUp in core/modules/tracker/tests/src/Kernel/Migrate/d7/MigrateDrupalTestBase.php
NodeClassicTest::testNodeClassicUpgrade in core/modules/migrate_drupal_ui/tests/src/Functional/d6/NodeClassicTest.php
Tests node classic migration via the UI.
NodeMigrationTypePluginAlterTest::testMigrationPluginAlter in core/modules/migrate_drupal/tests/src/Kernel/NodeMigrationTypePluginAlterTest.php
Tests the assignment of the node migration type.

File

core/modules/migrate_drupal/tests/src/Traits/NodeMigrateTypeTestTrait.php, line 93

Class

NodeMigrateTypeTestTrait
Helper functions to test complete and classic node migrations.

Namespace

Drupal\Tests\migrate_drupal\Traits

Code

protected function makeNodeMigrateMapTable($type, $version) {
    $name = $this->getTableName($type, $version);
    $fields = [
        'source_ids_hash' => [
            'type' => 'varchar',
            'not null' => TRUE,
            'length' => '64',
        ],
        'sourceid1' => [
            'type' => 'int',
            'not null' => TRUE,
            'size' => 'normal',
        ],
        'sourceid2' => [
            'type' => 'int',
            'not null' => TRUE,
            'size' => 'normal',
        ],
        'sourceid3' => [
            'type' => 'varchar',
            'not null' => TRUE,
            'length' => '255',
        ],
        'destid1' => [
            'type' => 'int',
            'not null' => FALSE,
            'size' => 'normal',
            'unsigned' => TRUE,
        ],
        'destid2' => [
            'type' => 'int',
            'not null' => FALSE,
            'size' => 'normal',
            'unsigned' => TRUE,
        ],
        'destid3' => [
            'type' => 'varchar_ascii',
            'not null' => FALSE,
            'length' => '12',
        ],
        'source_row_status' => [
            'type' => 'int',
            'not null' => TRUE,
            'size' => 'tiny',
            'default' => '0',
            'unsigned' => TRUE,
        ],
        'rollback_action' => [
            'type' => 'int',
            'not null' => TRUE,
            'size' => 'tiny',
            'default' => '0',
            'unsigned' => TRUE,
        ],
        'last_imported' => [
            'type' => 'int',
            'not null' => TRUE,
            'size' => 'normal',
            'default' => '0',
            'unsigned' => TRUE,
        ],
        'hash' => [
            'type' => 'varchar',
            'not null' => FALSE,
            'length' => '64',
        ],
    ];
    $values = [
        'source_ids_hash' => '123',
        'sourceid1' => '4242',
        'sourceid2' => '4242',
        'sourceid3' => 'en',
        'destid1' => '4242',
        'destid2' => '4242',
        'destid3' => 'en',
        'source_row_status' => '1',
        'rollback_action' => '1',
        'last_imported' => time(),
        'hash' => 'abc',
    ];
    $indexes = [
        'source' => [
            'sourceid1',
            'sourceid2',
            'sourceid3',
        ],
    ];
    // Remove keys not used.
    if ($type == NodeMigrateType::NODE_MIGRATE_TYPE_CLASSIC) {
        $keys = [
            'sourceid2',
            'sourceid3',
            'destid2',
            'destid3',
        ];
        foreach ($keys as $key) {
            unset($fields[$key]);
            unset($values[$key]);
            if (str_contains($key, 'sourceid')) {
                $index_key = substr($key, -1) - 1;
                unset($indexes['source'][$index_key]);
            }
        }
    }
    $connection = \Drupal::database();
    $connection->schema()
        ->createTable($name, [
        'fields' => $fields,
        'primary key' => [
            'source_ids_hash',
        ],
        'indexes' => $indexes,
        'mysql_character_set' => 'utf8mb4',
    ]);
    $field_names = array_keys($fields);
    $connection->insert($name)
        ->fields($field_names)
        ->values($values)
        ->execute();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.