From c401cc39fda954fd5696a7fa68779dbb98b52295 Mon Sep 17 00:00:00 2001 From: webchick Date: Mon, 12 May 2014 22:17:52 -0700 Subject: [PATCH] Issue #2214313 by chx, ultimike, benjy | eliza411: Contact: Not all values are being migrated. --- .../migrate.migration.d6_contact_category.yml | 3 -- .../migrate.migration.d6_contact_settings.yml | 8 ++++- .../Plugin/migrate/source/Variable.php | 20 ++++++++++++- .../migrate/source/d6/ContactCategory.php | 8 +++++ .../migrate/source/d6/ContactSettings.php | 30 +++++++++++++++++++ .../Tests/Dump/Drupal6ContactCategory.php | 8 +++++ .../Tests/d6/MigrateContactCategoryTest.php | 10 +++++-- .../Tests/d6/MigrateContactConfigsTest.php | 10 +++++++ .../Tests/source/d6/ContactCategoryTest.php | 5 ++-- 9 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/ContactSettings.php diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_contact_category.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_contact_category.yml index f4e8a39b3113..e73f6ad1f445 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_contact_category.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_contact_category.yml @@ -1,9 +1,7 @@ id: d6_contact_category label: Drupal 6 contact category configuration - source: plugin: d6_contact_category - process: id: - @@ -17,6 +15,5 @@ process: recipients: recipients reply: reply weight: weight - destination: plugin: entity:contact_category diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_contact_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_contact_settings.yml index 08a9daea88b1..65b0082419da 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_contact_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_contact_settings.yml @@ -1,13 +1,19 @@ id: d6_contact_settings label: Drupal 6 contact configuration source: - plugin: variable + plugin: d6_contact_settings variables: - contact_default_status - contact_hourly_threshold process: user_default_enabled: contact_default_status 'flood.limit': contact_hourly_threshold + default_category: + plugin: migration + migration: d6_contact_category + source: default_category destination: plugin: config config_name: contact.settings +dependencies: + - d6_contact_category diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/Variable.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/Variable.php index e66b4138f6b4..d6299997f28c 100644 --- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/Variable.php +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/Variable.php @@ -36,10 +36,28 @@ class Variable extends DrupalSqlBase { $this->variables = $this->configuration['variables']; } + /** + * {@inheritdoc} + */ protected function runQuery() { - return new \ArrayIterator(array(array_map('unserialize', $this->prepareQuery()->execute()->fetchAllKeyed()))); + return new \ArrayIterator(array($this->values())); } + /** + * Return the values of the variables specified in the plugin configuration. + * + * @return array + * An associative array where the keys are the variables specified in the + * plugin configuration and the values are the values found in the source. + * Only those values are returned that are actually in the database. + */ + protected function values() { + return array_map('unserialize', $this->prepareQuery()->execute()->fetchAllKeyed()); + } + + /** + * {@inheritdoc} + */ public function count() { return intval($this->query()->countQuery()->execute()->fetchField() > 0); } diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/ContactCategory.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/ContactCategory.php index 19e2dbac825a..74b783481818 100644 --- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/ContactCategory.php +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/ContactCategory.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 contact category source from database. @@ -37,6 +38,13 @@ class ContactCategory extends DrupalSqlBase { return $query; } + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + $row->setSourceProperty('recipients', explode(',', $row->getSourceProperty('recipients'))); + } + /** * {@inheritdoc} */ diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/ContactSettings.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/ContactSettings.php new file mode 100644 index 000000000000..ad0dc28f87dd --- /dev/null +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/ContactSettings.php @@ -0,0 +1,30 @@ +select('contact', 'c') + ->fields('c', array('cid')) + ->condition('selected', 1) + ->execute() + ->fetchField(); + return new \ArrayIterator(array($this->values() + array('default_category' => $default_category))); + } + +} diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ContactCategory.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ContactCategory.php index 541b6d2ddc70..d9db2479898a 100644 --- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ContactCategory.php +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ContactCategory.php @@ -73,6 +73,14 @@ class Drupal6ContactCategory extends Drupal6DumpBase { 'recipients' => 'admin@example.com', 'reply' => '', 'weight' => '0', + 'selected' => '0', + )) + ->values(array( + 'cid' => '2', + 'category' => 'Some other category', + 'recipients' => 'test@example.com', + 'reply' => 'Thanks for contacting us, we will reply ASAP!', + 'weight' => '1', 'selected' => '1', )) ->execute(); diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactCategoryTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactCategoryTest.php index 899d08ca68f2..dec8ff3b4f0e 100644 --- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactCategoryTest.php +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactCategoryTest.php @@ -34,7 +34,6 @@ class MigrateContactCategoryTest extends MigrateDrupalTestBase { ); } - /** * {@inheritdoc} */ @@ -56,8 +55,15 @@ class MigrateContactCategoryTest extends MigrateDrupalTestBase { /** @var \Drupal\contact\Entity\Category $contact_category */ $contact_category = entity_load('contact_category', 'website_feedback'); $this->assertEqual($contact_category->label, 'Website feedback'); - $this->assertEqual($contact_category->recipients, 'admin@example.com'); + $this->assertEqual($contact_category->recipients, array('admin@example.com')); $this->assertEqual($contact_category->reply, ''); $this->assertEqual($contact_category->weight, 0); + + $contact_category = entity_load('contact_category', 'some_other_category'); + $this->assertEqual($contact_category->label, 'Some other category'); + $this->assertEqual($contact_category->recipients, array('test@example.com')); + $this->assertEqual($contact_category->reply, 'Thanks for contacting us, we will reply ASAP!'); + $this->assertEqual($contact_category->weight, 1); } + } diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactConfigsTest.php index bd5650922e2a..fadaccce8ec3 100644 --- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactConfigsTest.php +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactConfigsTest.php @@ -39,9 +39,18 @@ class MigrateContactConfigsTest extends MigrateDrupalTestBase { */ public function setUp() { parent::setUp(); + // Add some id mappings for the dependent migrations. + $id_mappings = array( + 'd6_contact_category' => array( + array(array(1), array('website_feedback')), + array(array(2), array('some_other_category')), + ), + ); + $this->prepareIdMappings($id_mappings); $migration = entity_load('migration', 'd6_contact_settings'); $dumps = array( $this->getDumpDirectory() . '/Drupal6ContactSettings.php', + $this->getDumpDirectory() . '/Drupal6ContactCategory.php', ); $this->prepare($migration, $dumps); $executable = new MigrateExecutable($migration, new MigrateMessage()); @@ -55,5 +64,6 @@ class MigrateContactConfigsTest extends MigrateDrupalTestBase { $config = \Drupal::config('contact.settings'); $this->assertIdentical($config->get('user_default_enabled'), true); $this->assertIdentical($config->get('flood.limit'), 3); + $this->assertIdentical($config->get('default_category'), 'some_other_category'); } } diff --git a/core/modules/migrate_drupal/tests/Drupal/migrate_drupal/Tests/source/d6/ContactCategoryTest.php b/core/modules/migrate_drupal/tests/Drupal/migrate_drupal/Tests/source/d6/ContactCategoryTest.php index 870d1cbac1a6..7da67f7e2b90 100644 --- a/core/modules/migrate_drupal/tests/Drupal/migrate_drupal/Tests/source/d6/ContactCategoryTest.php +++ b/core/modules/migrate_drupal/tests/Drupal/migrate_drupal/Tests/source/d6/ContactCategoryTest.php @@ -31,7 +31,7 @@ class ContactCategoryTest extends MigrateSqlSourceTestCase { array( 'cid' => 1, 'category' => 'contact category value 1', - 'recipients' => 'admin@example.com,user@example.com', + 'recipients' => array('admin@example.com','user@example.com'), 'reply' => 'auto reply value 1', 'weight' => 0, 'selected' => 0, @@ -39,7 +39,7 @@ class ContactCategoryTest extends MigrateSqlSourceTestCase { array( 'cid' => 2, 'category' => 'contact category value 2', - 'recipients' => 'admin@example.com,user@example.com', + 'recipients' => array('admin@example.com','user@example.com'), 'reply' => 'auto reply value 2', 'weight' => 0, 'selected' => 0, @@ -63,6 +63,7 @@ class ContactCategoryTest extends MigrateSqlSourceTestCase { protected function setUp() { foreach ($this->expectedResults as $k => $row) { $this->databaseContents['contact'][$k] = $row; + $this->databaseContents['contact'][$k]['recipients'] = implode(',', $row['recipients']); } parent::setUp(); }