diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install new file mode 100644 index 0000000..6914903 --- /dev/null +++ b/core/modules/taxonomy/taxonomy.install @@ -0,0 +1,47 @@ +condition('n.status', NODE_NOT_PUBLISHED); + $sandbox['total'] = $query->countQuery()->execute()->fetchField(); + } + if ($sandbox['total']) { + // Operate on every unpublished node, in batches. + $batch_size = 100; + $query = db_select('node_field_data', 'n'); + $query + ->fields('n', array('nid')) + ->condition('n.nid', $sandbox['last'], '>') + ->condition('n.status', NODE_NOT_PUBLISHED) + ->orderBy('n.nid', 'ASC') + ->range(0, $batch_size); + $nodes = $query->execute(); + // Build the taxonomy index for each node. + foreach ($nodes as $node) { + $node = node_load($node->nid); + taxonomy_build_node_index($node); + $sandbox['last'] = $node->nid; + } + $sandbox['count'] += $batch_size; + } + // Finish after all the unpublished nodes have been processed. + if ($sandbox['count'] < $sandbox['total']) { + $sandbox['#finished'] = FALSE; + } + else { + $sandbox['#finished'] = TRUE; + } +} diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 7a1ca65..9efa875 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -505,10 +505,11 @@ function taxonomy_build_node_index($node) { return; } - $status = $node->isPublished(); - $sticky = (int) $node->isSticky(); - // We only maintain the taxonomy index for published nodes. - if ($status && $node->isDefaultRevision()) { + // We only maintain the taxonomy index for the default node revision. + if ($node->isDefaultRevision()) { + $status = (int) $node->isPublished(); + $sticky = (int) $node->isSticky(); + // Collect a unique list of all the term IDs from all node fields. $tid_all = array(); $entity_reference_class = 'Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem'; @@ -530,7 +531,7 @@ function taxonomy_build_node_index($node) { if (!empty($tid_all)) { foreach ($tid_all as $tid) { db_merge('taxonomy_index') - ->key(array('nid' => $node->id(), 'tid' => $tid, 'status' => $node->isPublished())) + ->key(array('nid' => $node->id(), 'tid' => $tid, 'status' => $status)) ->fields(array('sticky' => $sticky, 'created' => $node->getCreatedTime())) ->execute(); }