diff --git a/core/modules/comment/src/Plugin/migrate/source/d7/CommentEntityTranslation.php b/core/modules/comment/src/Plugin/migrate/source/d7/CommentEntityTranslation.php index 428b41f931..efdec81974 100644 --- a/core/modules/comment/src/Plugin/migrate/source/d7/CommentEntityTranslation.php +++ b/core/modules/comment/src/Plugin/migrate/source/d7/CommentEntityTranslation.php @@ -2,6 +2,7 @@ namespace Drupal\comment\Plugin\migrate\source\d7; +use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity; @@ -100,4 +101,20 @@ public function getIds() { ]; } + /** + * {@inheritdoc} + */ + public function checkRequirements() { + parent::checkRequirements(); + + if (!$this->moduleExists('comment')) { + // If we make it to here, the comment module isn't installed. + throw new RequirementsException('The module comment is not enabled in the source site'); + } + if (!$this->moduleExists('node')) { + // Node module is also a requirement. + throw new RequirementsException('The module node is not enabled in the source site'); + } + } + } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/CommentEntityTranslationCheckRequirementsTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/CommentEntityTranslationCheckRequirementsTest.php new file mode 100644 index 0000000000..47c6de2f59 --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/CommentEntityTranslationCheckRequirementsTest.php @@ -0,0 +1,56 @@ +sourceDatabase->update('system') + ->condition('name', $module) + ->fields([ + 'status' => '0', + ]) + ->execute(); + $this->expectException(RequirementsException::class); + $this->expectExceptionMessage("The module $module is not enabled in the source site"); + $this->getMigration('d7_comment_entity_translation') + ->getSourcePlugin() + ->checkRequirements(); + } + + /** + * Provides data for testCheckRequirements. + * + * @return string[][] + */ + public function providerTestCheckRequirements() { + return [ + ['comment'], + ['node'], + ]; + } + +}