Commit 753f2255 authored by alexpott's avatar alexpott

Issue #2281539 by ultimike, benjy | brockfanning: Fixed D6->D8 Profile field (list selection).

parent 4111c2e3
......@@ -18,6 +18,7 @@ process:
textfield: text
textarea: text_long
url: link
settings.allowed_values: options
cardinality:
plugin: static_map
default_value: 1
......
......@@ -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}
*/
......
......@@ -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')
......
......@@ -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";}'),
......
......@@ -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.');
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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.
......
......@@ -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(),
),
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment