diff --git a/core/modules/taxonomy/src/Tests/Update/TaxonomyUpdateTest.php b/core/modules/taxonomy/src/Tests/Update/TaxonomyUpdateTest.php index 866fa07..037b7f9 100644 --- a/core/modules/taxonomy/src/Tests/Update/TaxonomyUpdateTest.php +++ b/core/modules/taxonomy/src/Tests/Update/TaxonomyUpdateTest.php @@ -15,11 +15,6 @@ class TaxonomyUpdateTest extends UpdatePathTestBase { /** - * {@inheritdoc} - */ - protected $profile = 'standard'; - - /** * The database connection. * * @var \Drupal\Core\Database\Connection @@ -31,7 +26,7 @@ class TaxonomyUpdateTest extends UpdatePathTestBase { */ public function setDatabaseDumpFiles() { $this->databaseDumpFiles = [ - __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', + __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz', ]; } @@ -46,8 +41,9 @@ protected function setUp() { /** * Tests taxonomy term parents update. * - * @see taxonomy_update_8001() - * @see taxonomy_post_update_parents() + * @see taxonomy_update_8201() + * @see taxonomy_update_8202() + * @see taxonomy_update_8203() */ public function testTaxonomyUpdateParents() { $tids = $this->createTerms(); @@ -137,7 +133,7 @@ protected function createView() { $file = __DIR__ . '/../../../tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_parent.yml'; $config = Yaml::decode(file_get_contents($file)); - $this->container->get('database')->insert('config') + $this->db->insert('config') ->fields(['collection', 'name', 'data']) ->values([ 'collection' => '', diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 9616467..2c8e6cc 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -6,20 +6,86 @@ */ /** + * @addtogroup updates-8.2.x + * @{ + */ + +/** * Convert the custom taxonomy term hierarchy storage to a default storage. */ -function taxonomy_update_8001(&$sandbox = NULL) { - // Update entity definition. +function taxonomy_update_8201() { $manager = \Drupal::entityDefinitionUpdateManager(); /** @var \Drupal\Core\Field\BaseFieldDefinition $definition */ $definition = $manager->getFieldStorageDefinition('parent', 'taxonomy_term'); $definition->setCustomStorage(FALSE); $manager->updateFieldStorageDefinition($definition); + // Update the entity type because a new interface was added to Term entity. + $manager->updateEntityType($manager->getEntityType('taxonomy_term')); +} + +/** + * Copy hierarchy from {taxonomy_term_hierarchy} to {taxonomy_term__parent}. + */ +function taxonomy_update_8202(&$sandbox) { + $database = \Drupal::database(); + + if (!isset($sandbox['current'])) { + // Set batch ops sandbox. + $sandbox['current'] = 0; + $sandbox['max'] = $database->select('taxonomy_term_hierarchy') + ->countQuery() + ->execute() + ->fetchField(); + } - $factory = \Drupal::configFactory(); - // Update views with a low level API. - foreach ($factory->listAll('views.view.') as $id) { - $view = $factory->getEditable($id); + // Save the hierarchy. + $select = $database->select('taxonomy_term_hierarchy', 'h'); + $select->join('taxonomy_term_data', 'd', 'h.tid = d.tid'); + $hierarchy = $select + ->fields('h', ['tid', 'parent']) + ->fields('d', ['vid', 'langcode']) + ->range($sandbox['current'], $sandbox['current'] + 100) + ->execute() + ->fetchAll(); + + // Restore data. + $insert = $database->insert('taxonomy_term__parent') + ->fields(['bundle', 'entity_id', 'revision_id', 'langcode', 'delta', 'parent_target_id']); + $tid = -1; + foreach ($hierarchy as $row) { + if ($row->tid !== $tid) { + $delta = 0; + $tid = $row->tid; + } + $insert->values([ + 'bundle' => $row->vid, + 'entity_id' => $row->tid, + 'revision_id' => $row->tid, + 'langcode' => $row->langcode, + 'delta' => $delta, + 'parent_target_id' => $row->parent, + ]); + $delta++; + $sandbox['current']++; + } + $insert->execute(); + + $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['current'] / $sandbox['max']); + + if ($sandbox['#finished'] >= 1) { + // Drop the legacy table. + $database->schema()->dropTable('taxonomy_term_hierarchy'); + return t('Taxonomy term hierarchy converted.'); + } +} + +/** + * Update views to use {taxonomy_term__parent} in relationships. + */ +function taxonomy_update_8203() { + $config_factory = \Drupal::configFactory(); + foreach ($config_factory->listAll('views.view.') as $id) { + $view = $config_factory->getEditable($id); $changed = FALSE; foreach ($view->get('display') as $display_id => &$display) { $path = "display.$display_id.display_options.relationships.parent.table"; @@ -32,5 +98,8 @@ function taxonomy_update_8001(&$sandbox = NULL) { $view->save(TRUE); } } - } + +/** + * @} End of "addtogroup updates-8.2.x". + */ diff --git a/core/modules/taxonomy/taxonomy.post_update.php b/core/modules/taxonomy/taxonomy.post_update.php deleted file mode 100644 index 018960d..0000000 --- a/core/modules/taxonomy/taxonomy.post_update.php +++ /dev/null @@ -1,72 +0,0 @@ -select('taxonomy_term_hierarchy') - ->countQuery() - ->execute() - ->fetchField(); - } - - // Save the hierarchy. - $select = $database->select('taxonomy_term_hierarchy', 'h'); - $select->join('taxonomy_term_data', 'd', 'h.tid = d.tid'); - $hierarchy = $select - ->fields('h', ['tid', 'parent']) - ->fields('d', ['vid', 'langcode']) - ->range($sandbox['current'], $sandbox['current'] + 100) - ->execute() - ->fetchAll(); - - // Restore data. - $insert = $database->insert('taxonomy_term__parent') - ->fields(['bundle', 'entity_id', 'revision_id', 'langcode', 'delta', 'parent_target_id']); - $tid = -1; - foreach ($hierarchy as $row) { - if ($row->tid !== $tid) { - $delta = 0; - $tid = $row->tid; - } - $insert->values([ - 'bundle' => $row->vid, - 'entity_id' => $row->tid, - 'revision_id' => $row->tid, - 'langcode' => $row->langcode, - 'delta' => $delta, - 'parent_target_id' => $row->parent, - ]); - $delta++; - $sandbox['current']++; - } - $insert->execute(); - - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['current'] / $sandbox['max']); - - if ($sandbox['#finished'] >= 1) { - // Drop the legacy table. - $database->schema()->dropTable('taxonomy_term_hierarchy'); - return t('Taxonomy term hierarchy converted.'); - } - -} - -/** - * @} End of "addtogroup updates-8.2.x". - */