diff --git a/core/modules/user/src/Plugin/migrate/source/ProfileField.php b/core/modules/user/src/Plugin/migrate/source/ProfileField.php index 93a0430d68..7b4b7cb21e 100644 --- a/core/modules/user/src/Plugin/migrate/source/ProfileField.php +++ b/core/modules/user/src/Plugin/migrate/source/ProfileField.php @@ -2,6 +2,7 @@ namespace Drupal\user\Plugin\migrate\source; +use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; use Drupal\migrate\Row; @@ -33,16 +34,7 @@ class ProfileField extends DrupalSqlBase { * {@inheritdoc} */ public function query() { - if (empty($this->fieldTable) || empty($this->valueTable)) { - if ($this->getModuleSchemaVersion('system') >= 7000) { - $this->fieldTable = 'profile_field'; - $this->valueTable = 'profile_value'; - } - else { - $this->fieldTable = 'profile_fields'; - $this->valueTable = 'profile_values'; - } - } + $this->setTableNames(); return $this->select($this->fieldTable, 'pf')->fields('pf'); } @@ -105,4 +97,32 @@ public function getIds() { return $ids; } + /** + * {@inheritdoc} + */ + public function checkRequirements() { + $this->setTableNames(); + if (!$this->getDatabase()->schema()->tableExists($this->fieldTable)) { + // If we make it to here, the profile module isn't installed. + throw new RequirementsException('Profile module not enabled on source site'); + } + parent::checkRequirements(); + } + + /** + * Helper to set the profile field table names. + */ + protected function setTableNames() { + if (empty($this->fieldTable) || empty($this->valueTable)) { + if ($this->getModuleSchemaVersion('system') >= 7000) { + $this->fieldTable = 'profile_field'; + $this->valueTable = 'profile_value'; + } + else { + $this->fieldTable = 'profile_fields'; + $this->valueTable = 'profile_values'; + } + } + } + } diff --git a/core/modules/user/tests/src/Kernel/Migrate/d6/ProfileFieldCheckRequirementsTest.php b/core/modules/user/tests/src/Kernel/Migrate/d6/ProfileFieldCheckRequirementsTest.php new file mode 100644 index 0000000000..ffa19a5386 --- /dev/null +++ b/core/modules/user/tests/src/Kernel/Migrate/d6/ProfileFieldCheckRequirementsTest.php @@ -0,0 +1,33 @@ +sourceDatabase->schema()->dropTable('profile_fields'); + } + + /** + * Tests exception in thrown when profile_fields tables does not exist. + */ + public function testCheckRequirements() { + $this->setExpectedException(RequirementsException::class, 'Profile module not enabled on source site'); + $this->getMigration('user_profile_field') + ->getSourcePlugin() + ->checkRequirements(); + } + +} diff --git a/core/modules/user/tests/src/Kernel/Migrate/d7/ProfileFieldCheckRequirementsTest.php b/core/modules/user/tests/src/Kernel/Migrate/d7/ProfileFieldCheckRequirementsTest.php new file mode 100644 index 0000000000..fb2d82a000 --- /dev/null +++ b/core/modules/user/tests/src/Kernel/Migrate/d7/ProfileFieldCheckRequirementsTest.php @@ -0,0 +1,33 @@ +sourceDatabase->schema()->dropTable('profile_field'); + } + + /** + * Tests exception in thrown when profile_fields tables does not exist. + */ + public function testCheckRequirements() { + $this->setExpectedException(RequirementsException::class, 'Profile module not enabled on source site'); + $this->getMigration('user_profile_field') + ->getSourcePlugin() + ->checkRequirements(); + } + +}