If the node comments module is never installed (i.e. a special installation profile is used), the table "node_comment_statistics" is never created. Because of this, the node reindex process causes a sql error "Table 'drupal_usitech.node_comment_statistics' doesn't exist query: SELECT MAX(comment_count) FROM node_comment_statistics".

This is triggered by line 1781 of node.module:

variable_set('node_cron_comments_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}'))));

You will also notice line 1169-1171 properly ignores this if the module is missing:

if (module_exists('comment')) {
        $ranking['node_rank_comments'] = t('Number of comments');
      }

A simple workaround would be to replace:

variable_set('node_cron_comments_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}'))));

with:

variable_set('node_cron_comments_scale', module_exists('comment') ? 1.0 / max(1, db_result(db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}'))) : 1);

CommentFileSizeAuthor
#2 comment_installed_check.patch1.83 KBastoltz

Comments

astoltz’s picture

Looks like this isn't the only change that's needed. It's also referenced around line 1229:

      if ($weight = (int)variable_get('node_rank_recent', 5)) {
        // Exponential decay with half-life of 6 months, starting at last indexed node
        $ranking[] = '%d * POW(2, (GREATEST(MAX(n.created), MAX(n.changed), MAX(c.last_comment_timestamp)) - %d) * 6.43e-8)';
        $arguments2[] = $weight;
        $arguments2[] = (int)variable_get('node_cron_last', 0);
        $join2 .= ' LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
        $stats_join = TRUE;
        $total += $weight;
      }
      if ($weight = (int)variable_get('node_rank_recent', 5)) {
        // Exponential decay with half-life of 6 months, starting at last indexed node
        $ranking[] = '%d * POW(2, (GREATEST(MAX(n.created), MAX(n.changed)' . (module_exists('comment') ? ', MAX(c.last_comment_timestamp)' : '') . ') - %d) * 6.43e-8)';
        $arguments2[] = $weight;
        $arguments2[] = (int)variable_get('node_cron_last', 0);
        
        if (module_exists('comment')) {
          $join2 .= ' LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
        }
        
        $stats_join = TRUE;
        $total += $weight;
      }
astoltz’s picture

Status: Active » Needs review
StatusFileSize
new1.83 KB

Patch submitted

dpearcefl’s picture

Is this still an issue using current Drupal 6?

Status: Needs review » Needs work

The last submitted patch, comment_installed_check.patch, failed testing.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.