Commit c32dfc41 authored by heddn's avatar heddn Committed by heddn
Browse files

Issue #2885341 by heddn, mr.baileys: Migrations without a group are not...

Issue #2885341 by heddn, mr.baileys: Migrations without a group are not automatically assigned the 'default' group
parent eccef6a9
......@@ -5,8 +5,9 @@
* Provides enhancements for implementing and managing migrations.
*/
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\MigrateSourceInterface;
use Drupal\migrate\Plugin\Migration;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate_plus\Entity\MigrationGroup;
use Drupal\migrate_plus\Event\MigrateEvents;
......@@ -16,11 +17,10 @@ use Drupal\migrate_plus\Event\MigratePrepareRowEvent;
* Implements hook_migration_plugins_alter().
*/
function migrate_plus_migration_plugins_alter(array &$migrations) {
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
foreach ($migrations as $id => $migration) {
foreach (array_keys($migrations) as $id) {
// Add the default class where empty.
if (empty($migration['class'])) {
$migrations[$id]['class'] = 'Drupal\migrate\Plugin\Migration';
if (empty($migrations[$id]['class'])) {
$migrations[$id]['class'] = Migration::class;
}
// For derived configuration entity-based migrations, strip the deriver
......@@ -36,16 +36,16 @@ function migrate_plus_migration_plugins_alter(array &$migrations) {
}
// Integrate shared group configuration into the migration.
if (empty($migration['migration_group'])) {
$migration['migration_group'] = 'default';
if (empty($migrations[$id]['migration_group'])) {
$migrations[$id]['migration_group'] = 'default';
}
$group = MigrationGroup::load($migration['migration_group']);
$group = MigrationGroup::load($migrations[$id]['migration_group']);
if (empty($group)) {
// If the specified group does not exist, create it. Provide a little more
// for the 'default' group.
$group_properties = [];
$group_properties['id'] = $migration['migration_group'];
if ($migration['migration_group'] == 'default') {
$group_properties['id'] = $migrations[$id]['migration_group'];
if ($migrations[$id]['migration_group'] == 'default') {
$group_properties['label'] = 'Default';
$group_properties['description'] = 'A container for any migrations not explicitly assigned to a group.';
}
......@@ -61,7 +61,7 @@ function migrate_plus_migration_plugins_alter(array &$migrations) {
continue;
}
foreach ($shared_configuration as $key => $group_value) {
$migration_value = $migration[$key];
$migration_value = $migrations[$id][$key];
// Where both the migration and the group provide arrays, replace
// recursively (so each key collision is resolved in favor of the
// migration).
......
langcode: en
status: true
dependencies: { }
id: dummy
label: Dummy migration
migration_tags: { }
source:
plugin: embedded_data
data_rows:
-
name: Dummy
ids:
name:
type: string
process:
name: name
destination:
plugin: null
migration_dependencies:
required: { }
optional: { }
......@@ -22,6 +22,9 @@ class MigrateTableTest extends MigrateTestBase {
*/
protected $connection;
/**
* {@inheritdoc}
*/
public static $modules = ['migrate_plus'];
/**
......
......@@ -14,6 +14,9 @@ use Drupal\Tests\migrate\Kernel\MigrateTestBase;
*/
class MigrationConfigEntityTest extends MigrateTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'migrate',
'migrate_plus',
......
......@@ -13,7 +13,10 @@ use Drupal\migrate_plus\Entity\MigrationGroup;
*/
class MigrationGroupTest extends KernelTestBase {
public static $modules = ['migrate', 'migrate_plus'];
/**
* {@inheritdoc}
*/
public static $modules = ['migrate', 'migrate_plus', 'migrate_plus_test'];
/**
* Test that group configuration is properly merged into specific migrations.
......@@ -124,4 +127,16 @@ class MigrationGroupTest extends KernelTestBase {
$this->assertNull($loaded_migration);
}
/**
* Test that migrations without a group are assigned to the default group.
*/
public function testDefaultGroup() {
$this->installConfig('migrate_plus_test');
/** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface $pluginManager */
$pluginManager = \Drupal::service('plugin.manager.migration');
$migration = $pluginManager->getDefinition('dummy');
$this->assertEqual($migration['migration_group'], 'default', 'Migrations without an explicit group are assigned the default group.');
}
}
......@@ -11,6 +11,9 @@ use Drupal\KernelTests\KernelTestBase;
*/
class JsonTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['migrate', 'migrate_plus'];
/**
......
......@@ -89,6 +89,8 @@ abstract class DataParserPluginBaseMock extends DataParserPluginBase {
/**
* {@inheritdoc}
*
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod.Found
*/
public function nextSource() {
return parent::nextSource();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment