diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 00f2bacd0b..cef0487af8 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -195,3 +195,52 @@ function taxonomy_update_8701() { $storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('parent', 'taxonomy_term'); $entity_definition_update_manager->updateFieldStorageDefinition($storage_definition); } + +/** + * Sets published status for terms, where "status" is NULL. + */ +function taxonomy_update_8702(&$sandbox) { + // There can be terms with NULL status after "taxonomy_update_8601". + // Force them to be published. + /** @var \Drupal\taxonomy\TermStorageInterface $term_storage */ + $term_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); + + // Prepare sandbox. + if (!isset($sandbox['total'])) { + $terms_with_null_status = $term_storage + ->getQuery() + ->notExists('status') + ->count() + ->execute(); + + $sandbox['total'] = $terms_with_null_status; + $sandbox['current'] = 0; + } + + // Do not continue if no broken terms. + if (empty($sandbox['total'])) { + $sandbox['#finished'] = 1; + + return t('No terms with NULL status is found.'); + } + + $limit = 50; + + $term_ids = $term_storage + ->getQuery() + ->notExists('status') + ->range($sandbox['current'], $limit) + ->execute(); + $term_entities = $term_storage->loadMultiple($term_ids); + /** @var \Drupal\taxonomy\TermInterface $term */ + foreach ($term_entities as $term) { + $term->set('status', TRUE); + $term->save(); + + $sandbox['current']++; + } + + $sandbox['#finished'] = ($sandbox['current'] / $sandbox['total']); + + return t('@count terms statuses processed.', ['@count' => $sandbox['current']]); +}