diff --git a/modules/taxonomy/taxonomy.install b/modules/taxonomy/taxonomy.install index 60a9b5d..c720652 100644 --- a/modules/taxonomy/taxonomy.install +++ b/modules/taxonomy/taxonomy.install @@ -937,3 +937,51 @@ function taxonomy_update_7011(&$sandbox) { /** * @} End of "addtogroup updates-7.x-extra". */ + +/** + * Add entity_revision_is_default 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', '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 WHERE n.status = :status', 0, $batch_size, array(':status' => NODE_NOT_PUBLISHED))->fetchCol(); + // Build the taxonomy index for each node. + foreach ($nids as $nid) { + $node = node_load($nid); + $isDefaultRevision = $node->status; + $isOriginal = FALSE; + //Check for node translation that is original translation, not a second or third or fourth node translation. + //Otherwise if is entity translation or not translated is ok. + if ($node->tnid == 0 || $node->tnid == $nid) { + $isOriginal = TRUE; + } + if (module_exists('entity')) { + $entity_type = 'node'; + $entity = entity_load($entity_type, array($node->nid)); + $isDefaultRevision = (int) entity_revision_is_default($entity_type, $entity); + } + if($isDefaultRevision && $isOriginal) { + taxonomy_build_node_index($node); + } + $sandbox['last'] = $node->nid; + } + $sandbox['count'] += $batch_size; + } + // Finish after all the unpublished and entity_revision_is_default 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..7600fbb 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -1939,8 +1939,22 @@ function taxonomy_build_node_index($node) { $sticky = (int)(!empty($node->sticky)); } } - // We only maintain the taxonomy index for published nodes. - if ($status) { + $isDefaultRevision = $status; + $isOriginal = TRUE; + if (module_exists('entity')) { + $entity_type = 'node'; + $entity = entity_load($entity_type, array($node->nid)); + $isDefaultRevision = (int) entity_revision_is_default($entity_type, $entity); + //Check for node translation that is original, not a second or third or fourth node translation. + //Otherwise if is entity translation or not translated is ok. + if ($node->tnid == 0 || $node->tnid == $nid) { + $isOriginal = TRUE; + } else { + $isOriginal = FALSE; + } + } + // We only maintain the taxonomy index for the default node revision. + if ($isDefaultRevision && $isOriginal) { // 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) {