Update to Drupal 8.1.5. For more information, see https://www.drupal.org/project/drupal/releases/8.1.5

This commit is contained in:
Pantheon Automation 2016-07-07 09:44:38 -07:00 committed by Greg Anderson
parent 13b6ca7cc2
commit 38ba7c357d
342 changed files with 7814 additions and 1534 deletions

View file

@ -13,10 +13,19 @@ process:
name: name
description: description
weight: weight
# Only attempt to stub real (non-zero) parents.
parent_id:
-
plugin: skip_on_empty
method: process
source: parent
-
plugin: migration
migration: d6_taxonomy_term
parent:
plugin: migration
migration: d6_taxonomy_term
source: parent
plugin: default_value
default_value: 0
source: '@parent_id'
changed: timestamp
destination:
plugin: entity:taxonomy_term

View file

@ -11,12 +11,22 @@ process:
migration: d7_taxonomy_vocabulary
source: vid
name: name
description: description
'description/value': description
'description/format': format
weight: weight
# Only attempt to stub real (non-zero) parents.
parent_id:
-
plugin: skip_on_empty
method: process
source: parent
-
plugin: migration
migration: d7_taxonomy_term
parent:
plugin: migration
migration: d7_taxonomy_term
source: parent
plugin: default_value
default_value: 0
source: '@parent_id'
changed: timestamp
destination:
plugin: entity:taxonomy_term

View file

@ -7,7 +7,11 @@ use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
/**
* @MigrateCckField(
* id = "taxonomy_term_reference"
* id = "taxonomy_term_reference",
* type_map = {
* "taxonomy_term_reference" = "entity_reference"
* },
* core = {6,7}
* )
*/
class TaxonomyTermReference extends CckFieldPluginBase {

View file

@ -47,10 +47,10 @@ class Term extends DrupalSqlBase {
$query = $this->select($this->termDataTable, 'td')
->fields('td')
->distinct()
->orderBy('tid');
->orderBy('td.tid');
if (isset($this->configuration['vocabulary'])) {
$query->condition('vid', $this->configuration['vocabulary'], 'IN');
$query->condition('td.vid', $this->configuration['vocabulary'], 'IN');
}
return $query;

View file

@ -377,7 +377,7 @@ function taxonomy_term_load_multiple(array $tids = NULL) {
* (optional) An array of entity IDs. If omitted, all entities are loaded.
*
* @return array
* An array of vocabulary objects, indexed by vid.
* An array of vocabulary objects, indexed by vid.
*/
function taxonomy_vocabulary_load_multiple(array $vids = NULL) {
return Vocabulary::loadMultiple($vids);
@ -532,7 +532,11 @@ function taxonomy_build_node_index($node) {
* Implements hook_ENTITY_TYPE_update() for node entities.
*/
function taxonomy_node_update(EntityInterface $node) {
// Always rebuild the node's taxonomy index entries on node save.
// If we're not dealing with the default revision of the node, do not make any
// change to the taxonomy index.
if (!$node->isDefaultRevision()) {
return;
}
taxonomy_delete_node_index($node);
taxonomy_build_node_index($node);
}

View file

@ -0,0 +1,121 @@
<?php
namespace Drupal\Tests\taxonomy\Kernel;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Kernel tests for taxonomy forward revisions.
*
* @group taxonomy
*/
class ForwardRevisionTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'node', 'user', 'text', 'field', 'system'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('user');
$this->installEntitySchema('node');
$this->installEntitySchema('taxonomy_term');
$this->installSchema('node', 'node_access');
}
/**
* Tests that the taxonomy index work correctly with forward revisions.
*/
public function testTaxonomyIndexWithForwardRevision() {
\Drupal::configFactory()->getEditable('taxonomy.settings')->set('maintain_index_table', TRUE)->save();
Vocabulary::create([
'name' => 'test',
'vid' => 'test',
])->save();
$term = Term::create([
'name' => 'term1',
'vid' => 'test',
]);
$term->save();
$term2 = Term::create([
'name' => 'term2',
'vid' => 'test',
]);
$term2->save();
NodeType::create([
'type' => 'page',
])->save();
FieldStorageConfig::create([
'entity_type' => 'node',
'field_name' => 'field_tags',
'type' => 'entity_reference',
'settings' => [
'target_type' => 'taxonomy_term',
],
])->save();
FieldConfig::create([
'field_name' => 'field_tags',
'entity_type' => 'node',
'bundle' => 'page',
])->save();
$node = Node::create([
'type' => 'page',
'title' => 'test_title',
'field_tags' => [$term->id()],
]);
$node->save();
$taxonomy_index = $this->getTaxonomyIndex();
$this->assertEquals($term->id(), $taxonomy_index[$node->id()]->tid);
// Normal new revision.
$node->setNewRevision(TRUE);
$node->isDefaultRevision(TRUE);
$node->field_tags->target_id = $term2->id();
$node->save();
$taxonomy_index = $this->getTaxonomyIndex();
$this->assertEquals($term2->id(), $taxonomy_index[$node->id()]->tid);
// Check that saving a forward (non-default) revision does not affect the
// taxonomy index.
$node->setNewRevision(TRUE);
$node->isDefaultRevision(FALSE);
$node->field_tags->target_id = $term->id();
$node->save();
$taxonomy_index = $this->getTaxonomyIndex();
$this->assertEquals($term2->id(), $taxonomy_index[$node->id()]->tid);
// Check that making the previously created forward-revision the default
// revision updates the taxonomy index correctly.
$node->isDefaultRevision(TRUE);
$node->save();
$taxonomy_index = $this->getTaxonomyIndex();
$this->assertEquals($term->id(), $taxonomy_index[$node->id()]->tid);
}
protected function getTaxonomyIndex() {
return \Drupal::database()->select('taxonomy_index')
->fields('taxonomy_index')
->execute()
->fetchAllAssoc('nid');
}
}

View file

@ -69,6 +69,17 @@ class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
),
);
$terms = Term::loadMultiple(array_keys($expected_results));
// Find each term in the tree.
$storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
$vids = array_unique(array_column($expected_results, 'vid'));
$tree_terms = [];
foreach ($vids as $vid) {
foreach ($storage->loadTree($vid) as $term) {
$tree_terms[$term->tid] = $term;
}
}
foreach ($expected_results as $tid => $values) {
/** @var Term $term */
$term = $terms[$tid];
@ -86,6 +97,10 @@ class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
}
$this->assertIdentical($parents, $values['parent']);
}
$this->assertArrayHasKey($tid, $tree_terms, "Term $tid exists in vocabulary tree");
$tree_term = $tree_terms[$tid];
$this->assertEquals($values['parent'], $tree_term->parents, "Term $tid has correct parents in vocabulary tree");
}
}

View file

@ -15,6 +15,13 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
public static $modules = array('taxonomy', 'text');
/**
* The cached taxonomy tree items, keyed by vid and tid.
*
* @var array
*/
protected $treeData = [];
/**
* {@inheritdoc}
*/
@ -35,34 +42,38 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
* The parent vocabulary the migrated entity should have.
* @param string $expected_description
* The description the migrated entity should have.
* @param string $expected_format
* The format the migrated entity should have.
* @param int $expected_weight
* The weight the migrated entity should have.
* @param array $expected_parents
* The parent terms the migrated entity should have.
*/
protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_weight = 0, $expected_parents = []) {
protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, $expected_parents = []) {
/** @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->getVocabularyId());
$this->assertEqual($expected_description, $entity->getDescription());
$this->assertEquals($expected_format, $entity->getFormat());
$this->assertEqual($expected_weight, $entity->getWeight());
$this->assertIdentical($expected_parents, $this->getParentIDs($id));
$this->assertHierarchy($expected_vid, $id, $expected_parents);
}
/**
* Tests the Drupal 7 taxonomy term to Drupal 8 migration.
*/
public function testTaxonomyTerms() {
$this->assertEntity(1, 'General discussion', 'forums', '', 2);
$this->assertEntity(2, 'Term1', 'test_vocabulary', 'The first term.');
$this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.');
$this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 0, [3]);
$this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', 3);
$this->assertEntity(6, 'Games', 'forums', '', 4);
$this->assertEntity(7, 'Minecraft', 'forums', '', 1, [6]);
$this->assertEntity(8, 'Half Life 3', 'forums', '', 0, [6]);
$this->assertEntity(1, 'General discussion', 'forums', '', NULL, 2);
$this->assertEntity(2, 'Term1', 'test_vocabulary', 'The first term.', 'filtered_html');
$this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.', 'filtered_html');
$this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 'full_html', 0, [3]);
$this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', NULL, 3);
$this->assertEntity(6, 'Games', 'forums', '', NULL, 4);
$this->assertEntity(7, 'Minecraft', 'forums', '', NULL, 1, [6]);
$this->assertEntity(8, 'Half Life 3', 'forums', '', NULL, 0, [6]);
}
/**
@ -78,4 +89,28 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
return array_keys(\Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($tid));
}
/**
* Assert that a term is present in the tree storage, with the right parents.
*
* @param string $vid
* Vocabular ID.
* @param int $tid
* ID of the term to check.
* @param array $parent_ids
* The expected parent term IDs.
*/
protected function assertHierarchy($vid, $tid, array $parent_ids) {
if (!isset($this->treeData[$vid])) {
$tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);
$this->treeData[$vid] = [];
foreach ($tree as $item) {
$this->treeData[$vid][$item->tid] = $item;
}
}
$this->assertArrayHasKey($tid, $this->treeData[$vid], "Term $tid exists in taxonomy tree");
$term = $this->treeData[$vid][$tid];
$this->assertEquals($parent_ids, array_filter($term->parents), "Term $tid has correct parents in taxonomy tree");
}
}