class NodeMigrateType

Same name in other branches
  1. 8.9.x core/modules/migrate_drupal/src/NodeMigrateType.php \Drupal\migrate_drupal\NodeMigrateType
  2. 10 core/modules/migrate_drupal/src/NodeMigrateType.php \Drupal\migrate_drupal\NodeMigrateType
  3. 11.x core/modules/migrate_drupal/src/NodeMigrateType.php \Drupal\migrate_drupal\NodeMigrateType

Provides a class to determine the type of migration.

Hierarchy

Expanded class hierarchy of NodeMigrateType

11 files declare their use of NodeMigrateType
MigrateDrupal6TestBase.php in core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php
MigrateDrupal6TestBase.php in core/modules/aggregator/tests/src/Kernel/Migrate/d6/MigrateDrupal6TestBase.php
MigrateDrupal7TestBase.php in core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php
MigrateDrupal7TestBase.php in core/modules/aggregator/tests/src/Kernel/Migrate/d7/MigrateDrupal7TestBase.php
MigrateDrupalTestBase.php in core/modules/tracker/tests/src/Kernel/Migrate/d7/MigrateDrupalTestBase.php

... See full list

File

core/modules/migrate_drupal/src/NodeMigrateType.php, line 11

Namespace

Drupal\migrate_drupal
View source
final class NodeMigrateType {
    use MigrationConfigurationTrait;
    
    /**
     * Only the complete node migration map tables are in use.
     */
    const NODE_MIGRATE_TYPE_COMPLETE = 'COMPLETE';
    
    /**
     * Only the classic node migration map tables are in use.
     */
    const NODE_MIGRATE_TYPE_CLASSIC = 'CLASSIC';
    
    /**
     * Determines the type of node migration to be used.
     *
     * The node complete migration is the default. It is not used when there
     * are existing tables for dN_node.
     *
     * @param \Drupal\Core\Database\Connection $connection
     *   The connection to the target database.
     * @param string|false $version
     *   The Drupal version of the source database, FALSE if it cannot be
     *   determined.
     *
     * @return string
     *   The migrate type.
     *
     * @internal
     */
    public static function getNodeMigrateType(Connection $connection, $version) {
        $migrate_node_migrate_type_classic = Settings::get('migrate_node_migrate_type_classic', FALSE);
        if ($migrate_node_migrate_type_classic) {
            return static::NODE_MIGRATE_TYPE_CLASSIC;
        }
        $migrate_type = static::NODE_MIGRATE_TYPE_COMPLETE;
        if ($version) {
            // Create the variable name, 'node_has_rows' or 'node_complete_exists' and
            // set it the default value, FALSE.
            $node_has_rows = FALSE;
            $node_complete_has_rows = FALSE;
            // Find out what migrate map tables have rows for the node migrations.
            // It is either the classic, 'dN_node', or the complete,
            // 'dN_node_complete', or both. This is used to determine which migrations
            // are run and if migrations using the node migrations in a
            // migration_lookup are altered.
            $bases = [
                'node',
                'node_complete',
            ];
            $tables = $connection->schema()
                ->findTables('migrate_map_d' . $version . '_node%');
            foreach ($bases as $base) {
                $has_rows = $base . '_has_rows';
                $base_tables = preg_grep('/^migrate_map_d' . $version . '_' . $base . '_{2}.*$/', $tables);
                // Set the has_rows True when a map table has rows with a positive
                // count for the matched migration.
                foreach ($base_tables as $base_table) {
                    if ($connection->schema()
                        ->tableExists($base_table)) {
                        $count = $connection->select($base_table)
                            ->countQuery()
                            ->execute()
                            ->fetchField();
                        if ($count > 0) {
                            ${$has_rows} = TRUE;
                            break;
                        }
                    }
                }
            }
            // Set the node migration type to use.
            if ($node_has_rows && !$node_complete_has_rows) {
                $migrate_type = static::NODE_MIGRATE_TYPE_CLASSIC;
            }
        }
        return $migrate_type;
    }

}

Members

Title Sort descending Modifiers Object type Summary
MigrationConfigurationTrait::$configFactory protected property The config factory service.
MigrationConfigurationTrait::$followUpMigrationTags protected property The follow-up migration tags.
MigrationConfigurationTrait::$migrationPluginManager protected property The migration plugin manager service.
MigrationConfigurationTrait::$state protected property The state service.
MigrationConfigurationTrait::createDatabaseStateSettings protected function Creates the necessary state entries for SqlBase::getDatabase() to work.
MigrationConfigurationTrait::getConfigFactory protected function Gets the config factory service.
MigrationConfigurationTrait::getConnection protected function Gets the database connection for the source Drupal database.
MigrationConfigurationTrait::getFollowUpMigrationTags protected function Returns the follow-up migration tags.
MigrationConfigurationTrait::getLegacyDrupalVersion public static function Determines what version of Drupal the source database contains.
MigrationConfigurationTrait::getMigrationPluginManager protected function Gets the migration plugin manager service.
MigrationConfigurationTrait::getMigrations protected function Gets the migrations for import.
MigrationConfigurationTrait::getState protected function Gets the state service.
MigrationConfigurationTrait::getSystemData protected function Gets the system data from the system table of the source Drupal database.
NodeMigrateType::getNodeMigrateType public static function Determines the type of node migration to be used.
NodeMigrateType::NODE_MIGRATE_TYPE_CLASSIC constant Only the classic node migration map tables are in use.
NodeMigrateType::NODE_MIGRATE_TYPE_COMPLETE constant Only the complete node migration map tables are in use.

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