diff --git a/modules/taxonomy/taxonomy.install b/modules/taxonomy/taxonomy.install index 60a9b5d..36892c7 100644 --- a/modules/taxonomy/taxonomy.install +++ b/modules/taxonomy/taxonomy.install @@ -937,3 +937,37 @@ function taxonomy_update_7011(&$sandbox) { /** * @} End of "addtogroup updates-7.x-extra". */ + +/** + * Add unpublished nodes to the taxonomy index table. + */ +function taxonomy_update_7012(&$sandbox) { + if (!isset($sandbox['total'])) { + // Initialize state for future calls. + $sandbox['last'] = 0; + $sandbox['count'] = 0; + + $query = db_select('node_field_data', 'n') + ->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; + $nids = db_query_range('SELECT DISTINCT n.nid FROM {node} n INNER JOIN {taxonomy_index} t ON n.nid = t.nid WHERE n.status = :status', 0, $batch_size, array(':status' => NODE_NOT_PUBLISHED))->fetchCol(); + // 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/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 981649d..f4dd98a 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -1939,8 +1939,14 @@ function taxonomy_build_node_index($node) { $sticky = (int)(!empty($node->sticky)); } } - // We only maintain the taxonomy index for published nodes. - if ($status) { + $isDefaultRevision = $status; + if (module_exists('entity')) { + $entity_type = 'node'; + $entity = entity_load($entity_type, array($node->nid)); + $isDefaultRevision = (int) entity_revision_is_default($entity_type, $entity); + } + // We only maintain the taxonomy index for the default node revision. + if ($isDefaultRevision) { // Collect a unique list of all the term IDs from all node fields. $tid_all = array(); foreach (field_info_instances('node', $node->type) as $instance) {