Issue #2550309 by webflo, phenaproxima, kaushashah: Unable to import migration config-entities generated by migrate_upgrade module
							parent
							
								
									d3c5e548b9
								
							
						
					
					
						commit
						3eaded3590
					
				| 
						 | 
				
			
			@ -585,8 +585,11 @@ class Migration extends ConfigEntityBase implements MigrationInterface, Requirem
 | 
			
		|||
    parent::calculateDependencies();
 | 
			
		||||
    $this->calculatePluginDependencies($this->getSourcePlugin());
 | 
			
		||||
    $this->calculatePluginDependencies($this->getDestinationPlugin());
 | 
			
		||||
    // Add dependencies on required migration dependencies.
 | 
			
		||||
    foreach ($this->getMigrationDependencies()['required'] as $dependency) {
 | 
			
		||||
 | 
			
		||||
    // Add hard dependencies on required migrations.
 | 
			
		||||
    $dependencies = $this->getEntityManager()->getStorage($this->entityTypeId)
 | 
			
		||||
      ->getVariantIds($this->getMigrationDependencies()['required']);
 | 
			
		||||
    foreach ($dependencies as $dependency) {
 | 
			
		||||
      $this->addDependency('config', $this->getEntityType()->getConfigPrefix() . '.' . $dependency);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -92,7 +92,7 @@ class MigrationStorage extends ConfigEntityStorage implements MigrateBuildDepend
 | 
			
		|||
   * @return string[]
 | 
			
		||||
   *   The expanded list of IDs.
 | 
			
		||||
   */
 | 
			
		||||
  protected function getVariantIds(array $ids) {
 | 
			
		||||
  public function getVariantIds(array $ids) {
 | 
			
		||||
    // Re-index the array numerically, since we need to limit the loop by size.
 | 
			
		||||
    $ids = array_values($ids);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,76 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file
 | 
			
		||||
 * Contains \Drupal\Tests\migrate\Kernel\Entity\MigrationTest.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Drupal\Tests\migrate\Kernel\Entity;
 | 
			
		||||
 | 
			
		||||
use Drupal\KernelTests\KernelTestBase;
 | 
			
		||||
use Drupal\migrate\Entity\Migration;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Tests the Migration entity.
 | 
			
		||||
 *
 | 
			
		||||
 * @coversDefaultClass \Drupal\migrate\Entity\Migration
 | 
			
		||||
 * @group migrate
 | 
			
		||||
 */
 | 
			
		||||
class MigrationTest extends KernelTestBase {
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  public static $modules = ['migrate'];
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @covers ::calculateDependencies
 | 
			
		||||
   */
 | 
			
		||||
  public function testCalculateDependencies() {
 | 
			
		||||
    $fixture_migrations = [
 | 
			
		||||
      'd6_node__article' => 'd6_node',
 | 
			
		||||
      'd6_node__page' => 'd6_node',
 | 
			
		||||
      'd6_variables' => 'd6_variables',
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    foreach ($fixture_migrations as $id => $template) {
 | 
			
		||||
      $values = [
 | 
			
		||||
        'id' => $id,
 | 
			
		||||
        'template' => $template,
 | 
			
		||||
        'source' => [
 | 
			
		||||
          'plugin' => 'empty',
 | 
			
		||||
        ],
 | 
			
		||||
        'destination' => [
 | 
			
		||||
          'plugin' => 'null',
 | 
			
		||||
        ],
 | 
			
		||||
        'migration_tags' => []
 | 
			
		||||
      ];
 | 
			
		||||
      Migration::create($values)->save();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    $values = [
 | 
			
		||||
      'migration_dependencies' => [
 | 
			
		||||
        'required' => [
 | 
			
		||||
          'd6_node:*',
 | 
			
		||||
          'd6_variables'
 | 
			
		||||
        ]
 | 
			
		||||
      ],
 | 
			
		||||
      'source' => [
 | 
			
		||||
        'plugin' => 'empty',
 | 
			
		||||
      ],
 | 
			
		||||
      'destination' => [
 | 
			
		||||
        'plugin' => 'null',
 | 
			
		||||
      ],
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    $migration = new Migration($values, 'migration');
 | 
			
		||||
    $expected = [
 | 
			
		||||
      'migrate.migration.d6_node__article',
 | 
			
		||||
      'migrate.migration.d6_node__page',
 | 
			
		||||
      'migrate.migration.d6_variables'
 | 
			
		||||
    ];
 | 
			
		||||
    $migration->calculateDependencies();
 | 
			
		||||
    $this->assertEquals($expected, $migration->getDependencies()['config']);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -39,6 +39,3 @@ process:
 | 
			
		|||
 | 
			
		||||
destination:
 | 
			
		||||
  plugin: entity_revision:node
 | 
			
		||||
migration_dependencies:
 | 
			
		||||
  required:
 | 
			
		||||
    - d6_node:*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,9 +41,17 @@ class Node extends CckBuilder {
 | 
			
		|||
      $node_type = $row->getSourceProperty('type');
 | 
			
		||||
      $values = $template;
 | 
			
		||||
      $values['id'] = $template['id'] . '__' . $node_type;
 | 
			
		||||
 | 
			
		||||
      $label = $template['label'];
 | 
			
		||||
      $values['label'] = $this->t("@label (@type)", ['@label' => $label, '@type' => $node_type]);
 | 
			
		||||
      $values['source']['node_type'] = $node_type;
 | 
			
		||||
 | 
			
		||||
      // If this migration is based on the d6_node_revision template, it should
 | 
			
		||||
      // explicitly depend on the corresponding d6_node variant.
 | 
			
		||||
      if ($template['id'] == 'd6_node_revision') {
 | 
			
		||||
        $values['migration_dependencies']['required'][] = 'd6_node__' . $node_type;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      $migration = Migration::create($values);
 | 
			
		||||
 | 
			
		||||
      if (isset($fields[$node_type])) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue