If enabled the creation of new revisions to the nodes, the module considers not the number of nodes, and the number of revisions, which is false. It should be added to the query to calculate the expression

Now it looks:

SELECT COUNT(nid) FROM {term_node} WHERE tid = %d

It should be:

SELECT COUNT(<strong>DISTINCT</strong> nid) FROM {term_node} WHERE tid = %d

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ChemAli’s picture

Sorry, correct code:

SELECT COUNT(DISTINCT nid) FROM {term_node} WHERE tid = %d

ChemAli’s picture

The module counts unpublished nodes too, which is wrong in most cases and requires correction.

eliosh’s picture

Node count is also wrng when using i18n.
I have a vocab with " Localize terms. Terms are common for all languages, but their name and description may be localized. " multilanguage settings, so i have the same tid for each translation.

When looking the site in english, it shows term in english. If looking the site in italian, i saw term in italian. OK

But if i activate NODE COUNT setting, it shows (2) nodes with a predefined term, while instead it's only one (per language).

I hope I was clear in my explanation.

eliosh’s picture

i think that a query like this probably will solve the problem (at least for me :-D )

from :

$total_parent = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $tid_parent));

...

$total_child = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $tid_child));

to

$total_parent = db_result(db_query("select count(distinct(n.tnid)) from {term_node} tn inner join {node} n on tn.nid = n.nid where tid=%d and n.status=1", $tid_parent));

...

$total_child = db_result(db_query("select count(distinct(n.tnid)) from {term_node} tn inner join {node} n on tn.nid = n.nid where tid=%d and n.status=1", $tid_child));

lurkerfilms’s picture

FileSize
2.08 KB

Yes this is a bug because revisions were not taken into consideration.

Instead of doing DISTINCT in the query, the following condition should be added to the two queries that do the count:

AND n.vid = tn.vid

This only looks at the current revision and ignores all the historic revisions.

Likewise the term_has_nodes should do likewise.

Patch is attached.

fax8’s picture

@lurkerfilms seems you patched another module not taxonomy_block

fax8’s picture

Status: Active » Needs review
FileSize
1.24 KB

Attached a patch with the fixes in #4 which seems to work fine

fax8’s picture

FileSize
1.24 KB

Mmm.. seems that the patch above really didn't fix anything. Please test the following one.

tregismoreira’s picture

Version: 6.x-1.0-beta4 » 6.x-1.0-beta6

I downloaded the taxonomy_block-6.x-1.0-beta6 and the problem with duplicity on behalf of reviews (the original subject of this topic) is still occurring. Looking at the code, I could see that was already implemented the solution for the counting of nodes not published but was not implemented solution for nodes with revisions.

So I changed the code as follows.

Line 105, from:

$sql_count_parents = "SELECT COUNT (tn.nid) FROM {tn} term_node "

to:
$sql_count_parents = "SELECT COUNT (DISTINCT (tn.nid)) FROM {tn} term_node "

Line 114, from:

$sql_count_childs = "SELECT count (td.tid) from {} td term_data "

to:
$sql_count_childs = "SELECT count (DISTINCT (td.tid)) from {} td term_data "

For me, this change solved the problem. Anyone can evaluate and create a patch?

fax8’s picture

FileSize
1.09 KB

Good work tregismoreira. Attached there is a patch with your changes. I also fixed some bad parenthesis.

This is a critical issue for this module. Any maintainer willing to commit this issue and release another version?

studgate’s picture

this patch works perfectly.

BBC’s picture

I'll second that. Works for me as well.