diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php index aacbc2b..12c280a 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -4395,6 +4395,18 @@ 'field_file_display' => '1', 'field_file_description' => 'file desc', )) +->values(array( + 'entity_type' => 'user', + 'bundle' => 'user', + 'deleted' => '0', + 'entity_id' => '2', + 'revision_id' => '2', + 'language' => 'und', + 'delta' => '0', + 'field_file_fid' => '2', + 'field_file_display' => '1', + 'field_file_description' => 'file desc', +)) ->execute(); $connection->schema()->createTable('field_data_field_float', array( @@ -6233,6 +6245,18 @@ 'field_file_display' => '1', 'field_file_description' => 'file desc', )) +->values(array( + 'entity_type' => 'user', + 'bundle' => 'user', + 'deleted' => '0', + 'entity_id' => '2', + 'revision_id' => '2', + 'language' => 'und', + 'delta' => '0', + 'field_file_fid' => '2', + 'field_file_display' => '1', + 'field_file_description' => 'file desc', +)) ->execute(); $connection->schema()->createTable('field_revision_field_float', array( diff --git a/core/modules/user/migration_templates/d7_user.yml b/core/modules/user/migration_templates/d7_user.yml index b72e8c7..de157f4 100644 --- a/core/modules/user/migration_templates/d7_user.yml +++ b/core/modules/user/migration_templates/d7_user.yml @@ -46,6 +46,7 @@ migration_dependencies: required: - d7_user_role optional: + - d7_field_instance - d7_file - language - default_language diff --git a/core/modules/user/src/Plugin/migrate/User.php b/core/modules/user/src/Plugin/migrate/User.php index 986b58d..9f6c6ab 100644 --- a/core/modules/user/src/Plugin/migrate/User.php +++ b/core/modules/user/src/Plugin/migrate/User.php @@ -3,19 +3,12 @@ namespace Drupal\user\Plugin\migrate; use Drupal\migrate\Exception\RequirementsException; -use Drupal\migrate\Plugin\Migration; +use Drupal\migrate_drupal\Plugin\migrate\CckMigration; /** * Plugin class for Drupal 7 user migrations dealing with fields and profiles. */ -class User extends Migration { - - /** - * Flag indicating whether the CCK data has been filled already. - * - * @var bool - */ - protected $init = FALSE; +class User extends CckMigration { /** * {@inheritdoc} @@ -33,7 +26,18 @@ public function getProcess() { $field_migration = $this->migrationPluginManager->createStubMigration($definition); foreach ($field_migration->getSourcePlugin() as $row) { $field_name = $row->getSourceProperty('field_name'); - $this->process[$field_name] = $field_name; + $field_type = $row->getSourceProperty('type'); + if ($this->cckPluginManager->hasDefinition($field_type)) { + if (!isset($this->cckPluginCache[$field_type])) { + $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $this); + } + $info = $row->getSource(); + $this->cckPluginCache[$field_type] + ->processCckFieldValues($this, $field_name, $info); + } + else { + $this->process[$field_name] = $field_name; + } } } try { diff --git a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php index c21856e..726e9cd 100644 --- a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php +++ b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php @@ -109,10 +109,12 @@ protected function createType($id) { * Role IDs the user account is expected to have. * @param int $field_integer * The value of the integer field. + * @param int $field_file_target_id + * The target ID of the file field. * @param bool $has_picture * Whether the user is expected to have a picture attached. */ - protected function assertEntity($id, $label, $mail, $password, $created, $access, $login, $blocked, $langcode, $timezone, $init, $roles, $field_integer, $has_picture = FALSE) { + protected function assertEntity($id, $label, $mail, $password, $created, $access, $login, $blocked, $langcode, $timezone, $init, $roles, $field_integer, $field_file_target_id, $has_picture = FALSE) { /** @var \Drupal\user\UserInterface $user */ $user = User::load($id); $this->assertTrue($user instanceof UserInterface); @@ -155,6 +157,10 @@ protected function assertEntity($id, $label, $mail, $password, $created, $access $this->assertTrue($user->hasField('field_integer')); $this->assertEquals($field_integer[0], $user->field_integer->value); } + if (!is_null($field_file_target_id)) { + $this->assertTrue($user->hasField('field_file')); + $this->assertSame($field_file_target_id[0], $user->field_file->target_id); + } } /** @@ -190,6 +196,14 @@ public function testUser() { ->fetchCol(); $field_integer = !empty($field_integer) ? $field_integer : NULL; + $field_file = Database::getConnection('default', 'migrate') + ->select('field_data_field_file', 'ff') + ->fields('ff', array('field_file_fid')) + ->condition('ff.entity_id', $source->uid) + ->execute() + ->fetchCol(); + $field_file = !empty($field_file) ? $field_file : NULL; + $this->assertEntity( $source->uid, $source->name, @@ -203,7 +217,8 @@ public function testUser() { $source->timezone, $source->init, $roles, - $field_integer + $field_integer, + $field_file ); // Ensure that the user can authenticate.