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
|
id: d6_contact_category
|
||||||
label: Drupal 6 contact category configuration
|
label: Drupal 6 contact category configuration
|
||||||
|
|
||||||
source:
|
source:
|
||||||
plugin: d6_contact_category
|
plugin: d6_contact_category
|
||||||
|
|
||||||
process:
|
process:
|
||||||
id:
|
id:
|
||||||
-
|
-
|
||||||
|
@ -17,6 +15,5 @@ process:
|
||||||
recipients: recipients
|
recipients: recipients
|
||||||
reply: reply
|
reply: reply
|
||||||
weight: weight
|
weight: weight
|
||||||
|
|
||||||
destination:
|
destination:
|
||||||
plugin: entity:contact_category
|
plugin: entity:contact_category
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
id: d6_contact_settings
|
id: d6_contact_settings
|
||||||
label: Drupal 6 contact configuration
|
label: Drupal 6 contact configuration
|
||||||
source:
|
source:
|
||||||
plugin: variable
|
plugin: d6_contact_settings
|
||||||
variables:
|
variables:
|
||||||
- contact_default_status
|
- contact_default_status
|
||||||
- contact_hourly_threshold
|
- contact_hourly_threshold
|
||||||
process:
|
process:
|
||||||
user_default_enabled: contact_default_status
|
user_default_enabled: contact_default_status
|
||||||
'flood.limit': contact_hourly_threshold
|
'flood.limit': contact_hourly_threshold
|
||||||
|
default_category:
|
||||||
|
plugin: migration
|
||||||
|
migration: d6_contact_category
|
||||||
|
source: default_category
|
||||||
destination:
|
destination:
|
||||||
plugin: config
|
plugin: config
|
||||||
config_name: contact.settings
|
config_name: contact.settings
|
||||||
|
dependencies:
|
||||||
|
- d6_contact_category
|
||||||
|
|
|
@ -36,10 +36,28 @@ class Variable extends DrupalSqlBase {
|
||||||
$this->variables = $this->configuration['variables'];
|
$this->variables = $this->configuration['variables'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function runQuery() {
|
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() {
|
public function count() {
|
||||||
return intval($this->query()->countQuery()->execute()->fetchField() > 0);
|
return intval($this->query()->countQuery()->execute()->fetchField() > 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Drupal\migrate_drupal\Plugin\migrate\source\d6;
|
namespace Drupal\migrate_drupal\Plugin\migrate\source\d6;
|
||||||
|
|
||||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||||
|
use Drupal\migrate\Row;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drupal 6 contact category source from database.
|
* Drupal 6 contact category source from database.
|
||||||
|
@ -37,6 +38,13 @@ class ContactCategory extends DrupalSqlBase {
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function prepareRow(Row $row) {
|
||||||
|
$row->setSourceProperty('recipients', explode(',', $row->getSourceProperty('recipients')));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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',
|
'recipients' => 'admin@example.com',
|
||||||
'reply' => '',
|
'reply' => '',
|
||||||
'weight' => '0',
|
'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',
|
'selected' => '1',
|
||||||
))
|
))
|
||||||
->execute();
|
->execute();
|
||||||
|
|
|
@ -34,7 +34,6 @@ class MigrateContactCategoryTest extends MigrateDrupalTestBase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -56,8 +55,15 @@ class MigrateContactCategoryTest extends MigrateDrupalTestBase {
|
||||||
/** @var \Drupal\contact\Entity\Category $contact_category */
|
/** @var \Drupal\contact\Entity\Category $contact_category */
|
||||||
$contact_category = entity_load('contact_category', 'website_feedback');
|
$contact_category = entity_load('contact_category', 'website_feedback');
|
||||||
$this->assertEqual($contact_category->label, '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->reply, '');
|
||||||
$this->assertEqual($contact_category->weight, 0);
|
$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() {
|
public function setUp() {
|
||||||
parent::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');
|
$migration = entity_load('migration', 'd6_contact_settings');
|
||||||
$dumps = array(
|
$dumps = array(
|
||||||
$this->getDumpDirectory() . '/Drupal6ContactSettings.php',
|
$this->getDumpDirectory() . '/Drupal6ContactSettings.php',
|
||||||
|
$this->getDumpDirectory() . '/Drupal6ContactCategory.php',
|
||||||
);
|
);
|
||||||
$this->prepare($migration, $dumps);
|
$this->prepare($migration, $dumps);
|
||||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||||
|
@ -55,5 +64,6 @@ class MigrateContactConfigsTest extends MigrateDrupalTestBase {
|
||||||
$config = \Drupal::config('contact.settings');
|
$config = \Drupal::config('contact.settings');
|
||||||
$this->assertIdentical($config->get('user_default_enabled'), true);
|
$this->assertIdentical($config->get('user_default_enabled'), true);
|
||||||
$this->assertIdentical($config->get('flood.limit'), 3);
|
$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(
|
array(
|
||||||
'cid' => 1,
|
'cid' => 1,
|
||||||
'category' => 'contact category value 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',
|
'reply' => 'auto reply value 1',
|
||||||
'weight' => 0,
|
'weight' => 0,
|
||||||
'selected' => 0,
|
'selected' => 0,
|
||||||
|
@ -39,7 +39,7 @@ class ContactCategoryTest extends MigrateSqlSourceTestCase {
|
||||||
array(
|
array(
|
||||||
'cid' => 2,
|
'cid' => 2,
|
||||||
'category' => 'contact category value 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',
|
'reply' => 'auto reply value 2',
|
||||||
'weight' => 0,
|
'weight' => 0,
|
||||||
'selected' => 0,
|
'selected' => 0,
|
||||||
|
@ -63,6 +63,7 @@ class ContactCategoryTest extends MigrateSqlSourceTestCase {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
foreach ($this->expectedResults as $k => $row) {
|
foreach ($this->expectedResults as $k => $row) {
|
||||||
$this->databaseContents['contact'][$k] = $row;
|
$this->databaseContents['contact'][$k] = $row;
|
||||||
|
$this->databaseContents['contact'][$k]['recipients'] = implode(',', $row['recipients']);
|
||||||
}
|
}
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue