Issue #2214313 by chx, ultimike, benjy | eliza411: Contact: Not all values are being migrated.
parent
181b12210e
commit
c401cc39fd
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?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 @@ 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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue