Commit c401cc39 authored by webchick's avatar webchick

Issue #2214313 by chx, ultimike, benjy | eliza411: Contact: Not all values are being migrated.

parent 181b1221
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
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
......@@ -36,10 +36,28 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
$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);
}
......
......@@ -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 @@ public function query() {
return $query;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$row->setSourceProperty('recipients', explode(',', $row->getSourceProperty('recipients')));
}
/**
* {@inheritdoc}
*/
......
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Plugin\migrate\source\d6\ContactSettings.
*/
namespace Drupal\migrate_drupal\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\Variable;
/**
* @MigrateSource(
* id = "d6_contact_settings"
* )
*/
class ContactSettings extends Variable {
/**
* {@inheritdoc}
*/
function runQuery() {
$default_category = $this->select('contact', 'c')
->fields('c', array('cid'))
->condition('selected', 1)
->execute()
->fetchField();
return new \ArrayIterator(array($this->values() + array('default_category' => $default_category)));
}
}
......@@ -73,6 +73,14 @@ public function load() {
'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();
......
......@@ -34,7 +34,6 @@ public static function getInfo() {
);
}
/**
* {@inheritdoc}
*/
......@@ -56,8 +55,15 @@ public function testContactCategory() {
/** @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);
}
}
......@@ -39,9 +39,18 @@ public static function getInfo() {
*/
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 @@ public function testContactSettings() {
$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');
}
}
......@@ -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 @@ public static function getInfo() {
protected function setUp() {
foreach ($this->expectedResults as $k => $row) {
$this->databaseContents['contact'][$k] = $row;
$this->databaseContents['contact'][$k]['recipients'] = implode(',', $row['recipients']);
}
parent::setUp();
}
......
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