Issue #2997960 by plach, catch, franco cazzaro, longwave, logickal, larowlan, espurnes, benjifisher, bzrudi71: Missing taxonomy hierarchy items in 8.6.0 after running taxonomy_update_8502
parent
36ff61a766
commit
6a9a7fd01b
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Drupal\Core\Field\BaseFieldDefinition;
|
use Drupal\Core\Field\BaseFieldDefinition;
|
||||||
|
use Drupal\Core\Site\Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the custom taxonomy term hierarchy storage to a default storage.
|
* Convert the custom taxonomy term hierarchy storage to a default storage.
|
||||||
|
@ -28,6 +29,9 @@ function taxonomy_update_8502(&$sandbox) {
|
||||||
if (!isset($sandbox['current'])) {
|
if (!isset($sandbox['current'])) {
|
||||||
// Set batch ops sandbox.
|
// Set batch ops sandbox.
|
||||||
$sandbox['current'] = 0;
|
$sandbox['current'] = 0;
|
||||||
|
$sandbox['tid'] = -1;
|
||||||
|
$sandbox['delta'] = 0;
|
||||||
|
$sandbox['limit'] = Settings::get('entity_update_batch_size', 50);
|
||||||
$sandbox['max'] = $database->select('taxonomy_term_hierarchy')
|
$sandbox['max'] = $database->select('taxonomy_term_hierarchy')
|
||||||
->countQuery()
|
->countQuery()
|
||||||
->execute()
|
->execute()
|
||||||
|
@ -40,19 +44,20 @@ function taxonomy_update_8502(&$sandbox) {
|
||||||
$hierarchy = $select
|
$hierarchy = $select
|
||||||
->fields('h', ['tid', 'parent'])
|
->fields('h', ['tid', 'parent'])
|
||||||
->fields('d', ['vid', 'langcode'])
|
->fields('d', ['vid', 'langcode'])
|
||||||
->range($sandbox['current'], $sandbox['current'] + 100)
|
->range($sandbox['current'], $sandbox['limit'])
|
||||||
|
->orderBy('tid', 'ASC')
|
||||||
|
->orderBy('parent', 'ASC')
|
||||||
->execute()
|
->execute()
|
||||||
->fetchAll();
|
->fetchAll();
|
||||||
|
|
||||||
// Restore data.
|
// Restore data.
|
||||||
$insert = $database->insert('taxonomy_term__parent')
|
$insert = $database->insert('taxonomy_term__parent')
|
||||||
->fields(['bundle', 'entity_id', 'revision_id', 'langcode', 'delta', 'parent_target_id']);
|
->fields(['bundle', 'entity_id', 'revision_id', 'langcode', 'delta', 'parent_target_id']);
|
||||||
$tid = -1;
|
|
||||||
|
|
||||||
foreach ($hierarchy as $row) {
|
foreach ($hierarchy as $row) {
|
||||||
if ($row->tid !== $tid) {
|
if ($row->tid !== $sandbox['tid']) {
|
||||||
$delta = 0;
|
$sandbox['delta'] = 0;
|
||||||
$tid = $row->tid;
|
$sandbox['tid'] = $row->tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
$insert->values([
|
$insert->values([
|
||||||
|
@ -60,11 +65,11 @@ function taxonomy_update_8502(&$sandbox) {
|
||||||
'entity_id' => $row->tid,
|
'entity_id' => $row->tid,
|
||||||
'revision_id' => $row->tid,
|
'revision_id' => $row->tid,
|
||||||
'langcode' => $row->langcode,
|
'langcode' => $row->langcode,
|
||||||
'delta' => $delta,
|
'delta' => $sandbox['delta'],
|
||||||
'parent_target_id' => $row->parent,
|
'parent_target_id' => $row->parent,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$delta++;
|
$sandbox['delta']++;
|
||||||
$sandbox['current']++;
|
$sandbox['current']++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,16 @@ class TaxonomyParentUpdateTest extends UpdatePathTestBase {
|
||||||
* @see taxonomy_update_8503()
|
* @see taxonomy_update_8503()
|
||||||
*/
|
*/
|
||||||
public function testTaxonomyUpdateParents() {
|
public function testTaxonomyUpdateParents() {
|
||||||
|
// Force the update hook to only run one term per batch.
|
||||||
|
drupal_rewrite_settings([
|
||||||
|
'settings' => [
|
||||||
|
'entity_update_batch_size' => (object) [
|
||||||
|
'value' => 1,
|
||||||
|
'required' => TRUE,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
// Run updates.
|
// Run updates.
|
||||||
$this->runUpdates();
|
$this->runUpdates();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue