summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-10-09 11:54:39 (GMT)
committerNathaniel Catchpole2017-10-09 11:54:39 (GMT)
commit2c7b21d24b0b7bd0ef4dd56e3f1bd86930f4b372 (patch)
tree67a6b66bbad4589ee556424ac99f778a28d80c7e
parent4210adf6b9e9660f67b369747fac886a19945eda (diff)
Issue #2903007 by rakesh.gectcr, dipakmdhrm, maxocub, dillix, masipila, quietone, phenaproxima: [D7] Forum containers are migrated as forums
-rw-r--r--core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml1
-rw-r--r--core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php5
-rw-r--r--core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php30
-rw-r--r--core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermTest.php13
4 files changed, 41 insertions, 8 deletions
diff --git a/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml b/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml
index 99004df..46f9f20 100644
--- a/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml
+++ b/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml
@@ -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
diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php b/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php
index a9711a1..93b0fc4 100644
--- a/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php
+++ b/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php
@@ -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);
}
diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php
index 207b528..474969d 100644
--- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php
+++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php
@@ -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);
}
/**
diff --git a/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermTest.php b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermTest.php
index be905d9..dd22672 100644
--- a/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermTest.php
+++ b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermTest.php
@@ -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'] = [