From 6cfbb3e91147dd137ad846517fccc33ff7b70002 Mon Sep 17 00:00:00 2001 From: lucashedding <lucashedding@1463982.no-reply.drupal.org> Date: Fri, 28 Sep 2018 08:07:39 -0500 Subject: [PATCH] Issue #2987787 by SylvainM, heddn: Status of migration config file is not respected --- src/Entity/Migration.php | 3 +- src/Plugin/MigrationConfigDeriver.php | 4 ++ .../src/Kernel/MigrationConfigEntityTest.php | 39 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/Entity/Migration.php b/src/Entity/Migration.php index 6359825c..e128e8a2 100644 --- a/src/Entity/Migration.php +++ b/src/Entity/Migration.php @@ -18,7 +18,8 @@ use Drupal\Core\Entity\EntityTypeInterface; * entity_keys = { * "id" = "id", * "label" = "label", - * "weight" = "weight" + * "weight" = "weight", + * "status" = "status" * } * ) */ diff --git a/src/Plugin/MigrationConfigDeriver.php b/src/Plugin/MigrationConfigDeriver.php index 01354449..d6689212 100644 --- a/src/Plugin/MigrationConfigDeriver.php +++ b/src/Plugin/MigrationConfigDeriver.php @@ -20,6 +20,10 @@ class MigrationConfigDeriver extends DeriverBase { $migrations = Migration::loadMultiple(); /** @var \Drupal\migrate_plus\Entity\MigrationInterface $migration */ foreach ($migrations as $id => $migration) { + if (!$migration->status()) { + continue; + } + $this->derivatives[$id] = $migration->toArray(); } return $this->derivatives; diff --git a/tests/src/Kernel/MigrationConfigEntityTest.php b/tests/src/Kernel/MigrationConfigEntityTest.php index 354da762..2570e184 100644 --- a/tests/src/Kernel/MigrationConfigEntityTest.php +++ b/tests/src/Kernel/MigrationConfigEntityTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\migrate_plus\Kernel; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\KernelTests\KernelTestBase; use Drupal\migrate_plus\Entity\Migration; @@ -35,6 +36,7 @@ class MigrationConfigEntityTest extends KernelTestBase { public function testCacheInvalidation() { $config = Migration::create([ 'id' => 'test', + 'status' => TRUE, 'label' => 'Label A', 'migration_tags' => [], 'source' => [], @@ -57,4 +59,41 @@ class MigrationConfigEntityTest extends KernelTestBase { $this->assertSame('Label B', $this->pluginManager->getDefinition('test')['label']); } + /** + * Tests migration status. + */ + public function testMigrationStatus() { + $configs = [ + [ + 'id' => 'test_active', + 'status' => TRUE, + 'label' => 'Label Active', + 'migration_tags' => [], + 'source' => [], + 'destination' => [], + 'migration_dependencies' => [], + ], + [ + 'id' => 'test_inactive', + 'status' => FALSE, + 'label' => 'Label Inactive', + 'migration_tags' => [], + 'source' => [], + 'destination' => [], + 'migration_dependencies' => [], + ], + ]; + + foreach ($configs as $config) { + Migration::create($config)->save(); + } + + $definitions = $this->pluginManager->getDefinitions(); + $this->assertCount(1, $definitions); + $this->assertArrayHasKey('test_active', $definitions); + + $this->setExpectedException(PluginNotFoundException::class, 'The "test_inactive" plugin does not exist.'); + $this->pluginManager->getDefinition('test_inactive'); + } + } -- GitLab