diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_field.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_field.yml index 183a2657d0f150ea15b8c3e0d763be2d7885c104..14103025de6c922439de7b78bd73a4638709bbed 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_field.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_field.yml @@ -18,6 +18,7 @@ process: textfield: text textarea: text_long url: link + settings.allowed_values: options cardinality: plugin: static_map default_value: 1 diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ProfileField.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ProfileField.php index e16fa9e7185a1eb5d0165f3e1ccba6c93778202b..a55979674c22d31789a829c1491417b73ce49c58 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ProfileField.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ProfileField.php @@ -8,6 +8,7 @@ namespace Drupal\migrate_drupal\Plugin\migrate\source\d6; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; +use Drupal\migrate\Row; /** * Drupal 6 profile fields source from database. @@ -43,6 +44,31 @@ public function query() { return $query; } + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + if ($row->getSourceProperty('type') == 'selection') { + // Get the current options. + $current_options = preg_split("/[\r\n]+/", $row->getSourceProperty('options')); + // Select the list values from the profile_values table to ensure we get + // them all since they can get out of sync with profile_fields. + $options = $this->getDatabase()->query('SELECT DISTINCT value FROM {profile_values} WHERE fid = :fid', array(':fid' => $row->getSourceProperty('fid')))->fetchCol(); + $options = array_merge($current_options, $options); + // array_combine() takes care of any duplicates options. + $row->setSourceProperty('options', array_combine($options, $options)); + } + + if ($row->getSourceProperty('type') == 'checkbox') { + // D6 profile checkboxes values are always 0 or 1 (with no labels), so we + // need to create two label-less options that will get 0 and 1 for their + // keys. + $row->setSourceProperty('options', array(NULL, NULL)); + } + + return parent::prepareRow($row); + } + /** * {@inheritdoc} */ diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ProfileFieldValues.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ProfileFieldValues.php index 363a960137c9fac3af3473bb7d4b3df22bb3243e..807ee43d3ad7aa5241c134900f441dc5b6f04741 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ProfileFieldValues.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ProfileFieldValues.php @@ -7,9 +7,10 @@ namespace Drupal\migrate_drupal\Plugin\migrate\source\d6; + +use Drupal\migrate\Row; use Drupal\migrate\Plugin\SourceEntityInterface; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; -use Drupal\migrate\Row; /** @@ -46,7 +47,7 @@ public function prepareRow(Row $row) { $results = $query->execute(); foreach ($results as $profile_value) { - // Check special case for date. We need unserialize. + // Check special case for date. We need to unserialize. if ($profile_value['type'] == 'date') { $date = unserialize($profile_value['value']); $date = date('Y-m-d', mktime(0, 0, 0, $date['month'], $date['day'], $date['year'])); @@ -71,7 +72,7 @@ public function fields() { $fields = array( 'fid' => $this->t('Unique profile field ID.'), 'uid' => $this->t('The user Id.'), - 'value' => $this->t('The value for this field..'), + 'value' => $this->t('The value for this field.'), ); $query = $this->select('profile_values', 'pv') diff --git a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6User.php b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6User.php index a7e41f443300e6650db19d8eebbab557ee7d852d..ba706dd77cd437eba5310db90517beb5ea89bce1 100644 --- a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6User.php +++ b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6User.php @@ -456,7 +456,7 @@ public static function getData($table) { array('fid' => 8, 'uid' => 8, 'value' => 'brown'), array('fid' => 9, 'uid' => 8, 'value' => 'Nunc condimentum ligula felis, eget lacinia purus accumsan at. Pellentesque eu lobortis felis. Duis at accumsan nisl, vel pulvinar risus. Nullam venenatis, tellus non eleifend hendrerit, augue nulla rhoncus leo, eget convallis enim sem ut velit. Mauris tincidunt enim ut eros volutpat dapibus. Curabitur augue libero, imperdiet eget orci sed, malesuada dapibus tellus. Nam lacus sapien, convallis vitae quam vel, bibendum commodo odio.'), array('fid' => 10, 'uid' => 8, 'value' => '0'), - array('fid' => 11, 'uid' => 8, 'value' => ''), + array('fid' => 11, 'uid' => 8, 'value' => 'Spammers'), array('fid' => 12, 'uid' => 8, 'value' => "Deep Purple\nWho\nThe Beatles"), array('fid' => 13, 'uid' => 8, 'value' => "http://blog.example.com"), array('fid' => 14, 'uid' => 8, 'value' => 'a:3:{s:5:"month";s:1:"9";s:3:"day";s:1:"9";s:4:"year";s:4:"1980";}'), diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateProfileValuesTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateProfileValuesTest.php index 436ed9a153c3988a2291f077fe27c57da3b8ffb6..b117a643016daf8a5102890fbdaddf9dfa061b59 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateProfileValuesTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateProfileValuesTest.php @@ -11,6 +11,7 @@ use Drupal\migrate_drupal\Tests\Dump\Drupal6User; use Drupal\migrate_drupal\Tests\Dump\Drupal6UserProfileFields; use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; +use Drupal\user\Entity\User; /** * Tests Drupal 6 profile values to Drupal 8 migration. @@ -67,6 +68,12 @@ protected function setUp() { 'entity_type' => 'user', 'name' => 'profile_sold_to', 'type' => 'list_text', + 'settings' => array( + 'allowed_values' => array( + 'Pill spammers' => 'Pill spammers', + 'Fitness spammers' => 'Fitness spammers', + ) + ) ))->save(); entity_create('field_config', array( 'entity_type' => 'user', @@ -144,7 +151,7 @@ protected function setUp() { * Tests Drupal 6 profile values to Drupal 8 migration. */ public function testUserProfileValues() { - $user = user_load(2); + $user = User::load(2); $this->assertFalse(is_null($user)); $this->assertEqual($user->profile_color->value, 'red'); $this->assertEqual($user->profile_biography->value, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nulla sapien, congue nec risus ut, adipiscing aliquet felis. Maecenas quis justo vel nulla varius euismod. Quisque metus metus, cursus sit amet sem non, bibendum vehicula elit. Cras dui nisl, eleifend at iaculis vitae, lacinia ut felis. Nullam aliquam ligula volutpat nulla consectetur accumsan. Maecenas tincidunt molestie diam, a accumsan enim fringilla sit amet. Morbi a tincidunt tellus. Donec imperdiet scelerisque porta. Sed quis sem bibendum eros congue sodales. Vivamus vel fermentum est, at rutrum orci. Nunc consectetur purus ut dolor pulvinar, ut volutpat felis congue. Cras tincidunt odio sed neque sollicitudin, vehicula tempor metus scelerisque.'); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileEntityDisplayTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileEntityDisplayTest.php index e29143e9269fe5b405e1e9aa593194f122a0c158..1b8b36bd83a83e23197c123804cd7901526ae1cb 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileEntityDisplayTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileEntityDisplayTest.php @@ -97,6 +97,7 @@ protected function setUp() { $migration = entity_load('migration', 'd6_user_profile_entity_display'); $dumps = array( $this->getDumpDirectory() . '/Drupal6UserProfileFields.php', + $this->getDumpDirectory() . '/Drupal6User.php', ); $this->prepare($migration, $dumps); $executable = new MigrateExecutable($migration, $this); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileEntityFormDisplayTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileEntityFormDisplayTest.php index 947b6622c7d83924c5e1a3c72ec9d0f99a1f9c68..e999001be1ae507e3a16d02ab13b186b50e33438 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileEntityFormDisplayTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileEntityFormDisplayTest.php @@ -92,6 +92,7 @@ protected function setUp() { $migration = entity_load('migration', 'd6_user_profile_entity_form_display'); $dumps = array( $this->getDumpDirectory() . '/Drupal6UserProfileFields.php', + $this->getDumpDirectory() . '/Drupal6User.php', ); $this->prepare($migration, $dumps); $executable = new MigrateExecutable($migration, $this); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileFieldInstanceTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileFieldInstanceTest.php index b866689a25e78d097f9db427f82909bd8cd9c323..394984dd8e092dc4cf17e48671ef3ea509c9a2d7 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileFieldInstanceTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileFieldInstanceTest.php @@ -45,6 +45,7 @@ protected function setUp() { $migration = entity_load('migration', 'd6_user_profile_field_instance'); $dumps = array( $this->getDumpDirectory() . '/Drupal6UserProfileFields.php', + $this->getDumpDirectory() . '/Drupal6User.php', ); $this->prepare($migration, $dumps); $executable = new MigrateExecutable($migration, $this); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileFieldTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileFieldTest.php index 69af4a04a70aeedf992835a769c515f7bc1a6534..71a1bcf99f5f188548346187cbb559d5ed947074 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileFieldTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileFieldTest.php @@ -36,11 +36,11 @@ protected function setUp() { $migration = entity_load('migration', 'd6_user_profile_field'); $dumps = array( $this->getDumpDirectory() . '/Drupal6UserProfileFields.php', + $this->getDumpDirectory() . '/Drupal6User.php', ); $this->prepare($migration, $dumps); $executable = new MigrateExecutable($migration, $this); $executable->import(); - } /** @@ -62,6 +62,14 @@ public function testUserProfileFields() { // Migrated selection field. $field = entity_load('field_config', 'user.profile_sold_to'); + $settings = $field->getSettings(); + $this->assertEqual($settings['allowed_values'], array( + 'Pill spammers' => 'Pill spammers', + 'Spammers' => 'Spammers', + 'Fitness spammers' => 'Fitness spammers', + 'Faithful servant' => 'Faithful servant', + 'Anonymous donor' => 'Anonymous donor', + )); $this->assertEqual($field->type, 'list_text', 'Field type is list_text.'); // Migrated list field. diff --git a/core/modules/migrate_drupal/tests/src/source/d6/ProfileFieldTest.php b/core/modules/migrate_drupal/tests/src/source/d6/ProfileFieldTest.php index 80728dfb7302afdf3d4463687f72feebf8c5a8b1..01e10da91d237f20d431a2eafa4f8ac35c30dfbf 100644 --- a/core/modules/migrate_drupal/tests/src/source/d6/ProfileFieldTest.php +++ b/core/modules/migrate_drupal/tests/src/source/d6/ProfileFieldTest.php @@ -49,7 +49,7 @@ class ProfileFieldTest extends MigrateSqlSourceTestCase { 'register' => 0, 'visibility' => 2, 'autocomplete' => 0, - 'options' => '', + 'options' => array(), ), array( 'fid' => 2, @@ -64,7 +64,7 @@ class ProfileFieldTest extends MigrateSqlSourceTestCase { 'register' => 0, 'visibility' => 2, 'autocomplete' => 0, - 'options' => '', + 'options' => array(), ), array( 'fid' => 3, @@ -79,7 +79,7 @@ class ProfileFieldTest extends MigrateSqlSourceTestCase { 'register' => 1, 'visibility' => 2, 'autocomplete' => 0, - 'options' => '', + 'options' => array(), ), );