diff --git a/core/modules/block/src/Plugin/migrate/source/Block.php b/core/modules/block/src/Plugin/migrate/source/Block.php index 26725cd..3e3e76c 100644 --- a/core/modules/block/src/Plugin/migrate/source/Block.php +++ b/core/modules/block/src/Plugin/migrate/source/Block.php @@ -15,7 +15,7 @@ * * @MigrateSource( * id = "block", - * source_provider = "block" + * source_provider = "drupal.block" * ) */ class Block extends DrupalSqlBase { diff --git a/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php b/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php index 08a1013..9824d20 100644 --- a/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php +++ b/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php @@ -15,7 +15,7 @@ * * @MigrateSource( * id = "d6_comment", - * source_provider = "comment" + * source_provider = "drupal.comment.6[0-9]{3}" * ) */ class Comment extends DrupalSqlBase { diff --git a/core/modules/comment/src/Plugin/migrate/source/d7/CommentType.php b/core/modules/comment/src/Plugin/migrate/source/d7/CommentType.php index 41b0669..ddbf93a 100644 --- a/core/modules/comment/src/Plugin/migrate/source/d7/CommentType.php +++ b/core/modules/comment/src/Plugin/migrate/source/d7/CommentType.php @@ -16,7 +16,7 @@ * * @MigrateSource( * id = "d7_comment_type", - * source_provider = "comment" + * source_provider = "drupal.comment.7[0-9]{3}" * ) */ class CommentType extends DrupalSqlBase { diff --git a/core/modules/contact/src/Plugin/migrate/source/ContactCategory.php b/core/modules/contact/src/Plugin/migrate/source/ContactCategory.php index 13cc780..ddc5a2d 100644 --- a/core/modules/contact/src/Plugin/migrate/source/ContactCategory.php +++ b/core/modules/contact/src/Plugin/migrate/source/ContactCategory.php @@ -15,7 +15,7 @@ * * @MigrateSource( * id = "contact_category", - * source_provider = "contact" + * source_provider = "drupal.contact" * ) */ class ContactCategory extends DrupalSqlBase { diff --git a/core/modules/field/src/Plugin/migrate/source/d6/Field.php b/core/modules/field/src/Plugin/migrate/source/d6/Field.php index 2fe24bc..81132d1 100644 --- a/core/modules/field/src/Plugin/migrate/source/d6/Field.php +++ b/core/modules/field/src/Plugin/migrate/source/d6/Field.php @@ -15,7 +15,7 @@ * * @MigrateSource( * id = "d6_field", - * source_provider = "content" + * source_provider = "drupal.content.6[0-9]{3}" * ) */ class Field extends DrupalSqlBase { diff --git a/core/modules/field/src/Plugin/migrate/source/d6/FieldInstance.php b/core/modules/field/src/Plugin/migrate/source/d6/FieldInstance.php index bddfc27..069b55b 100644 --- a/core/modules/field/src/Plugin/migrate/source/d6/FieldInstance.php +++ b/core/modules/field/src/Plugin/migrate/source/d6/FieldInstance.php @@ -15,7 +15,7 @@ * * @MigrateSource( * id = "d6_field_instance", - * source_provider = "content" + * source_provider = "drupal.content.6[0-9]{3}" * ) */ class FieldInstance extends DrupalSqlBase { diff --git a/core/modules/field/src/Plugin/migrate/source/d7/Field.php b/core/modules/field/src/Plugin/migrate/source/d7/Field.php index a39971a..91ae9fa 100755 --- a/core/modules/field/src/Plugin/migrate/source/d7/Field.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/Field.php @@ -14,7 +14,8 @@ * Drupal 7 field source from database. * * @MigrateSource( - * id = "d7_field" + * id = "d7_field", + * source_provider = "drupal.field.7[0-9]{3}" * ) */ class Field extends DrupalSqlBase { diff --git a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php index 87853ef..beb84c2 100755 --- a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php @@ -15,6 +15,7 @@ * * @MigrateSource( * id = "d7_field_instance", + * source_provider = "drupal.field.7[0-9]{3}" * ) */ class FieldInstance extends DrupalSqlBase { diff --git a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerFormDisplay.php b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerFormDisplay.php index 2be9223..da28da3 100755 --- a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerFormDisplay.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerFormDisplay.php @@ -14,7 +14,8 @@ * The field instance per form display source class. * * @MigrateSource( - * id = "d7_field_instance_per_form_display" + * id = "d7_field_instance_per_form_display", + * source_provider = "drupal.field.7[0-9]{3}" * ) */ class FieldInstancePerFormDisplay extends DrupalSqlBase { diff --git a/core/modules/file/src/Plugin/migrate/source/d6/File.php b/core/modules/file/src/Plugin/migrate/source/d6/File.php index 3bb7708..c92b7e6 100644 --- a/core/modules/file/src/Plugin/migrate/source/d6/File.php +++ b/core/modules/file/src/Plugin/migrate/source/d6/File.php @@ -14,7 +14,8 @@ * Drupal 6 file source from database. * * @MigrateSource( - * id = "d6_file" + * id = "d6_file", + * source_provider = "drupal.system.6[0-9]{3}" * ) */ class File extends DrupalSqlBase { diff --git a/core/modules/file/src/Plugin/migrate/source/d6/Upload.php b/core/modules/file/src/Plugin/migrate/source/d6/Upload.php index d0e7440..d11108b 100644 --- a/core/modules/file/src/Plugin/migrate/source/d6/Upload.php +++ b/core/modules/file/src/Plugin/migrate/source/d6/Upload.php @@ -15,7 +15,7 @@ * * @MigrateSource( * id = "d6_upload", - * source_provider = "upload" + * source_provider = "drupal.upload.6[0-9]{3}" * ) */ class Upload extends DrupalSqlBase { diff --git a/core/modules/file/src/Plugin/migrate/source/d7/File.php b/core/modules/file/src/Plugin/migrate/source/d7/File.php index 129fa62..ad46af4 100644 --- a/core/modules/file/src/Plugin/migrate/source/d7/File.php +++ b/core/modules/file/src/Plugin/migrate/source/d7/File.php @@ -15,7 +15,8 @@ * Drupal 7 file source from database. * * @MigrateSource( - * id = "d7_file" + * id = "d7_file", + * source_provider = "drupal.file.7[0-9]{3}" * ) */ class File extends DrupalSqlBase { diff --git a/core/modules/filter/src/Plugin/migrate/source/d6/FilterFormat.php b/core/modules/filter/src/Plugin/migrate/source/d6/FilterFormat.php index b84444c..af75985 100644 --- a/core/modules/filter/src/Plugin/migrate/source/d6/FilterFormat.php +++ b/core/modules/filter/src/Plugin/migrate/source/d6/FilterFormat.php @@ -14,7 +14,8 @@ * Drupal 6 filter source from database. * * @MigrateSource( - * id = "d6_filter_format" + * id = "d6_filter_format", + * source_provider = "drupal.filter.6[0-9]{3}" * ) */ class FilterFormat extends DrupalSqlBase { diff --git a/core/modules/filter/src/Plugin/migrate/source/d7/FilterFormat.php b/core/modules/filter/src/Plugin/migrate/source/d7/FilterFormat.php index 06f4c6d..ca02704 100755 --- a/core/modules/filter/src/Plugin/migrate/source/d7/FilterFormat.php +++ b/core/modules/filter/src/Plugin/migrate/source/d7/FilterFormat.php @@ -14,7 +14,8 @@ * Drupal 7 filter source from database. * * @MigrateSource( - * id = "d7_filter_format" + * id = "d7_filter_format", + * source_provider = "drupal.filter.7[0-9]{3}" * ) */ class FilterFormat extends DrupalSqlBase { diff --git a/core/modules/image/src/Plugin/migrate/source/d6/ImageCachePreset.php b/core/modules/image/src/Plugin/migrate/source/d6/ImageCachePreset.php index 8c563f0..5be4ce3 100644 --- a/core/modules/image/src/Plugin/migrate/source/d6/ImageCachePreset.php +++ b/core/modules/image/src/Plugin/migrate/source/d6/ImageCachePreset.php @@ -14,7 +14,8 @@ * Drupal 6 imagecache presets source from database. * * @MigrateSource( - * id = "d6_imagecache_presets" + * id = "d6_imagecache_presets", + * source_provider = "drupal.imagecache.6[0-9]{3}" * ) */ class ImageCachePreset extends DrupalSqlBase { diff --git a/core/modules/image/src/Plugin/migrate/source/d7/ImageStyles.php b/core/modules/image/src/Plugin/migrate/source/d7/ImageStyles.php index 9e9a5d3..20a4216 100644 --- a/core/modules/image/src/Plugin/migrate/source/d7/ImageStyles.php +++ b/core/modules/image/src/Plugin/migrate/source/d7/ImageStyles.php @@ -15,7 +15,7 @@ * * @MigrateSource( * id = "d7_image_styles", - * source_provider = "image" + * source_provider = "drupal.image.7[0-9]{3}" * ) */ class ImageStyles extends DrupalSqlBase { diff --git a/core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php b/core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php index 93cf583..0ff36c8 100644 --- a/core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php +++ b/core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php @@ -14,7 +14,7 @@ * Drupal menu link source from database. * * @MigrateSource( - * id = "menu_link", + * id = "menu_link" * ) */ class MenuLink extends DrupalSqlBase { diff --git a/core/modules/migrate/src/Exception/RequirementsException.php b/core/modules/migrate/src/Exception/RequirementsException.php index 5843de2..cd0007b 100644 --- a/core/modules/migrate/src/Exception/RequirementsException.php +++ b/core/modules/migrate/src/Exception/RequirementsException.php @@ -7,10 +7,9 @@ namespace Drupal\migrate\Exception; -use Exception; - /** - * Defines an + * Exception thrown when source data does not meet the source plugin's + * requirements. * * @see \Drupal\migrate\Plugin\RequirementsInterface */ @@ -35,9 +34,8 @@ class RequirementsException extends \RuntimeException { * @param \Exception $previous * (optional) The previous exception used for the exception chaining. */ - public function __construct($message = "", array $requirements = [], $code = 0, Exception $previous = NULL) { + public function __construct($message = "", array $requirements = [], $code = 0, \Exception $previous = NULL) { parent::__construct($message, $code, $previous); - $this->requirements = $requirements; } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php index bb7f452..1ef7477 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php @@ -101,13 +101,25 @@ public static function create(ContainerInterface $container, array $configuratio public function checkRequirements() { if ($this->pluginDefinition['requirements_met'] === TRUE) { if (isset($this->pluginDefinition['source_provider'])) { - if ($this->moduleExists($this->pluginDefinition['source_provider'])) { - if (isset($this->pluginDefinition['minimum_schema_version']) && !$this->getModuleSchemaVersion($this->pluginDefinition['source_provider']) < $this->pluginDefinition['minimum_schema_version']) { - throw new RequirementsException('Required minimum schema version ' . $this->pluginDefinition['minimum_schema_version'], ['minimum_schema_version' => $this->pluginDefinition['minimum_schema_version']]); + $matches = array(); + preg_match('/^drupal(.+)?$/', $this->pluginDefinition['source_provider'], $matches); + + if (isset($matches[1])) { + @list ($module, $version_pattern) = explode('.', ltrim($matches[1], '.'), 2); + + if ($this->moduleExists($module)) { + if ($version_pattern) { + // Installed modules may have a schema version of 0 if they have + // never been updated. + $installed_version = $this->getModuleSchemaVersion($module); + if ($installed_version && !preg_match("/^{$version_pattern}$/", $installed_version)) { + throw new RequirementsException('Incompatible schema version ' . $installed_version); + } + } + } + else { + throw new RequirementsException('Missing source provider ' . $module); } - } - else { - throw new RequirementsException('Missing source provider ' . $this->pluginDefinition['source_provider'], ['source_provider' => $this->pluginDefinition['source_provider']]); } } } diff --git a/core/modules/migrate_drupal/src/SourcePluginServiceModifier.php b/core/modules/migrate_drupal/src/SourcePluginServiceModifier.php new file mode 100644 index 0000000..e3f3b90 --- /dev/null +++ b/core/modules/migrate_drupal/src/SourcePluginServiceModifier.php @@ -0,0 +1,28 @@ +get('plugin.manager.migrate.source'); + $attributes = $service->getTag('migrate.source_provider'); + $attributes['patterns'][] = 'drupal'; + $attributes['patterns'][] = 'drupal.*'; + $service->addTag('migrate.source_provider', $attributes); + } + +} diff --git a/core/modules/migrate_drupal/src/Tests/RequirementsTest.php b/core/modules/migrate_drupal/src/Tests/RequirementsTest.php new file mode 100644 index 0000000..1417f2a --- /dev/null +++ b/core/modules/migrate_drupal/src/Tests/RequirementsTest.php @@ -0,0 +1,93 @@ + 'foo', + 'requirements_met' => TRUE, + 'source_provider' => $source_provider, + ); + return new TestDrupalSqlBase(array(), 'foo', $definition, Migration::create(), \Drupal::state(), \Drupal::entityManager()); + } + + /** + * Tests various checkRequirements() scenarios. + */ + public function testCheckRequirements() { + // Require an installed module, any version. + $this->getTestPlugin('drupal.node')->checkRequirements(); + + // Require a non-installed module, any version. + try { + $this->getTestPlugin('drupal.profile2')->checkRequirements(); + $this->fail('Did not catch expected RequirementsException.'); + } + catch (RequirementsException $e) { + $this->pass('Caught expected RequirementsException: ' . $e->getMessage()); + } + + // Require an installed minimum schema version. + $this->getTestPlugin('drupal.node.7000')->checkRequirements(); + + // Require a minimum schema version higher than what's installed. + try { + $this->getTestPlugin('drupal.node.7015')->checkRequirements(); + $this->fail('Did not catch expected RequirementsException.'); + } + catch (RequirementsException $e) { + $this->pass('Caught expected RequirementsException: ' . $e->getMessage()); + } + } + +} + +/** + * Fake implementation of DrupalSqlBase for testing checkRequirements(). + */ +class TestDrupalSqlBase extends DrupalSqlBase { + + /** + * {@inheritdoc} + */ + public function fields() { + return array(); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + return array(); + } + + /** + * {@inheritdoc} + */ + public function query() { + return $this->select('system', 's')->fields('s'); + } + +} diff --git a/core/modules/node/src/Plugin/migrate/source/d6/Node.php b/core/modules/node/src/Plugin/migrate/source/d6/Node.php index b8a4d7d..355e9f2 100644 --- a/core/modules/node/src/Plugin/migrate/source/d6/Node.php +++ b/core/modules/node/src/Plugin/migrate/source/d6/Node.php @@ -14,7 +14,8 @@ * Drupal 6 node source from database. * * @MigrateSource( - * id = "d6_node" + * id = "d6_node", + * source_provider = "drupal.node.6[0-9]{3}" * ) */ class Node extends DrupalSqlBase { diff --git a/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php b/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php index 034c934..145d957 100644 --- a/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php +++ b/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php @@ -14,7 +14,8 @@ * Drupal 6 Node types source from database. * * @MigrateSource( - * id = "d6_node_type" + * id = "d6_node_type", + * source_provider = "drupal.node.6[0-9]{3}" * ) */ class NodeType extends DrupalSqlBase { diff --git a/core/modules/node/src/Plugin/migrate/source/d7/NodeType.php b/core/modules/node/src/Plugin/migrate/source/d7/NodeType.php index d496363..7f0cc5b 100644 --- a/core/modules/node/src/Plugin/migrate/source/d7/NodeType.php +++ b/core/modules/node/src/Plugin/migrate/source/d7/NodeType.php @@ -15,7 +15,7 @@ * * @MigrateSource( * id = "d7_node_type", - * source_provider = "node" + * source_provider = "drupal.node.7[0-9]{3}" * ) */ class NodeType extends DrupalSqlBase { diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/Term.php b/core/modules/taxonomy/src/Plugin/migrate/source/Term.php index ff4507d..d90664a 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/source/Term.php +++ b/core/modules/taxonomy/src/Plugin/migrate/source/Term.php @@ -17,7 +17,7 @@ * * @MigrateSource( * id = "taxonomy_term", - * source_provider = "taxonomy" + * source_provider = "drupal.taxonomy" * ) */ class Term extends DrupalSqlBase { diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/d6/TermNode.php b/core/modules/taxonomy/src/Plugin/migrate/source/d6/TermNode.php index a09ffba..9e40464 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/source/d6/TermNode.php +++ b/core/modules/taxonomy/src/Plugin/migrate/source/d6/TermNode.php @@ -15,7 +15,7 @@ * * @MigrateSource( * id = "d6_term_node", - * source_provider = "taxonomy" + * source_provider = "drupal.taxonomy.6[0-9]{3}" * ) */ class TermNode extends DrupalSqlBase { diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/d6/Vocabulary.php b/core/modules/taxonomy/src/Plugin/migrate/source/d6/Vocabulary.php index d2d3f19..151b447 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/source/d6/Vocabulary.php +++ b/core/modules/taxonomy/src/Plugin/migrate/source/d6/Vocabulary.php @@ -15,7 +15,7 @@ * * @MigrateSource( * id = "d6_taxonomy_vocabulary", - * source_provider = "taxonomy" + * source_provider = "drupal.taxonomy.6[0-9]{3}" * ) */ class Vocabulary extends DrupalSqlBase { diff --git a/core/modules/user/src/Plugin/migrate/source/ProfileField.php b/core/modules/user/src/Plugin/migrate/source/ProfileField.php index 4550d5b..054109c 100644 --- a/core/modules/user/src/Plugin/migrate/source/ProfileField.php +++ b/core/modules/user/src/Plugin/migrate/source/ProfileField.php @@ -15,7 +15,7 @@ * * @MigrateSource( * id = "profile_field", - * source_provider = "profile" + * source_provider = "drupal.profile" * ) */ class ProfileField extends DrupalSqlBase { diff --git a/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldValues.php b/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldValues.php index 66c04c3..f5735bb 100644 --- a/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldValues.php +++ b/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldValues.php @@ -15,7 +15,7 @@ * * @MigrateSource( * id = "d6_profile_field_values", - * source_provider = "profile" + * source_provider = "drupal.profile.6[0-9]{3}" * ) */ class ProfileFieldValues extends DrupalSqlBase { diff --git a/core/modules/user/src/Plugin/migrate/source/d6/Role.php b/core/modules/user/src/Plugin/migrate/source/d6/Role.php index cc6bcaa..10120fe 100644 --- a/core/modules/user/src/Plugin/migrate/source/d6/Role.php +++ b/core/modules/user/src/Plugin/migrate/source/d6/Role.php @@ -14,7 +14,8 @@ * Drupal 6 role source from database. * * @MigrateSource( - * id = "d6_user_role" + * id = "d6_user_role", + * source_provider = "drupal.user.6[0-9]{3}" * ) */ class Role extends DrupalSqlBase { diff --git a/core/modules/user/src/Plugin/migrate/source/d6/User.php b/core/modules/user/src/Plugin/migrate/source/d6/User.php index 59c3229..e8a40cd 100644 --- a/core/modules/user/src/Plugin/migrate/source/d6/User.php +++ b/core/modules/user/src/Plugin/migrate/source/d6/User.php @@ -14,7 +14,8 @@ * Drupal 6 user source from database. * * @MigrateSource( - * id = "d6_user" + * id = "d6_user", + * source_provider = "drupal.user.6[0-9]{3}" * ) */ class User extends DrupalSqlBase { diff --git a/core/modules/user/src/Plugin/migrate/source/d6/UserPictureFile.php b/core/modules/user/src/Plugin/migrate/source/d6/UserPictureFile.php index ff0d1ae..d8c6836 100644 --- a/core/modules/user/src/Plugin/migrate/source/d6/UserPictureFile.php +++ b/core/modules/user/src/Plugin/migrate/source/d6/UserPictureFile.php @@ -14,7 +14,8 @@ * Drupal 6 user picture source from database. * * @MigrateSource( - * id = "d6_user_picture_file" + * id = "d6_user_picture_file", + * source_provider = "drupal.user.6[0-9]{3}" * ) */ class UserPictureFile extends DrupalSqlBase { diff --git a/core/modules/user/src/Plugin/migrate/source/d7/Role.php b/core/modules/user/src/Plugin/migrate/source/d7/Role.php index 4f84290..3ecb34f 100755 --- a/core/modules/user/src/Plugin/migrate/source/d7/Role.php +++ b/core/modules/user/src/Plugin/migrate/source/d7/Role.php @@ -14,7 +14,8 @@ * Drupal 7 role source from database. * * @MigrateSource( - * id = "d7_user_role" + * id = "d7_user_role", + * source_provider = "drupal.user.7[0-9]{3}" * ) */ class Role extends DrupalSqlBase {