Issue #2903007 by rakesh.gectcr, dipakmdhrm, maxocub, dillix, masipila, quietone, phenaproxima: [D7] Forum containers are migrated as forums

8.5.x
Nathaniel Catchpole 2017-10-09 12:54:39 +01:00
parent 4210adf6b9
commit 2c7b21d24b
4 changed files with 41 additions and 8 deletions

View File

@ -30,6 +30,7 @@ process:
plugin: default_value
default_value: 0
source: '@parent_id'
forum_container: is_container
changed: timestamp
destination:
plugin: entity:taxonomy_term

View File

@ -70,6 +70,11 @@ class Term extends FieldableEntity {
->fetchCol();
$row->setSourceProperty('parent', $parents);
// Determine if this is a forum container.
$forum_container_tids = $this->variableGet('forum_containers', []);
$current_tid = $row->getSourceProperty('tid');
$row->setSourceProperty('is_container', in_array($current_tid, $forum_container_tids));
return parent::prepareRow($row);
}

View File

@ -16,6 +16,7 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
public static $modules = [
'comment',
'datetime',
'forum',
'image',
'link',
'menu_ui',
@ -71,17 +72,19 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
* The value the migrated entity field should have.
* @param int $expected_term_reference_tid
* The term reference id the migrated entity field should have.
* @param bool $expected_container_flag
* The term should be a container entity.
*/
protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL) {
protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL, $expected_container_flag = 0) {
/** @var \Drupal\taxonomy\TermInterface $entity */
$entity = Term::load($id);
$this->assertTrue($entity instanceof TermInterface);
$this->assertIdentical($expected_label, $entity->label());
$this->assertIdentical($expected_vid, $entity->bundle());
$this->assertEqual($expected_description, $entity->getDescription());
$this->assertInstanceOf(TermInterface::class, $entity);
$this->assertEquals($expected_label, $entity->label());
$this->assertEquals($expected_vid, $entity->bundle());
$this->assertEquals($expected_description, $entity->getDescription());
$this->assertEquals($expected_format, $entity->getFormat());
$this->assertEqual($expected_weight, $entity->getWeight());
$this->assertIdentical($expected_parents, $this->getParentIDs($id));
$this->assertEquals($expected_weight, $entity->getWeight());
$this->assertEquals($expected_parents, $this->getParentIDs($id));
$this->assertHierarchy($expected_vid, $id, $expected_parents);
if (!is_null($expected_field_integer_value)) {
$this->assertTrue($entity->hasField('field_integer'));
@ -91,6 +94,9 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
$this->assertTrue($entity->hasField('field_integer'));
$this->assertEquals($expected_term_reference_tid, $entity->field_term_reference->target_id);
}
if ($entity->hasField('forum_container')) {
$this->assertEquals($expected_container_flag, $entity->forum_container->value);
}
}
/**
@ -102,9 +108,17 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
$this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.', 'filtered_html');
$this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 'full_html', 0, [3], 6);
$this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', NULL, 3);
$this->assertEntity(6, 'Games', 'forums', '', NULL, 4);
$this->assertEntity(6, 'Games', 'forums', '', NULL, 4, [], NULL, NULL, 1);
$this->assertEntity(7, 'Minecraft', 'forums', '', NULL, 1, [6]);
$this->assertEntity(8, 'Half Life 3', 'forums', '', NULL, 0, [6]);
// Verify that we still can create forum containers after the migration.
$term = Term::create(['vid' => 'forums', 'name' => 'Forum Container', 'forum_container' => 1]);
$term->save();
// Reset the forums tree data so this new term is included in the tree.
unset($this->treeData['forums']);
$this->assertEntity(19, 'Forum Container', 'forums', '', NULL, 0, [], NULL, NULL, 1);
}
/**

View File

@ -31,6 +31,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'name' => 'name value 1',
'description' => 'description value 1',
'weight' => 0,
'is_container' => FALSE,
],
[
'tid' => 2,
@ -38,6 +39,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'name' => 'name value 2',
'description' => 'description value 2',
'weight' => 0,
'is_container' => TRUE,
],
[
'tid' => 3,
@ -45,6 +47,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'name' => 'name value 3',
'description' => 'description value 3',
'weight' => 0,
'is_container' => FALSE,
],
[
'tid' => 4,
@ -52,6 +55,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'name' => 'name value 4',
'description' => 'description value 4',
'weight' => 1,
'is_container' => FALSE,
],
[
'tid' => 5,
@ -59,6 +63,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'name' => 'name value 5',
'description' => 'description value 5',
'weight' => 1,
'is_container' => FALSE,
],
[
'tid' => 6,
@ -66,6 +71,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'name' => 'name value 6',
'description' => 'description value 6',
'weight' => 0,
'is_container' => TRUE,
],
[
'tid' => 7,
@ -73,6 +79,7 @@ class TermTest extends MigrateSqlSourceTestBase {
'name' => 'name value 7',
'description' => 'description value 7',
'weight' => 0,
'is_container' => TRUE,
],
];
$tests[0]['source_data']['taxonomy_term_hierarchy'] = [
@ -149,6 +156,12 @@ class TermTest extends MigrateSqlSourceTestBase {
'delta' => 0,
],
];
$tests[0]['source_data']['variable'] = [
[
'name' => 'forum_containers',
'value' => 'a:3:{i:0;s:1:"5";i:1;s:1:"6";i:2;s:1:"7";}',
],
];
// The expected results.
$tests[0]['expected_data'] = [