Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi!
I have edited the default groups directory view and made it a table view. I have added the OG: Group: Post Count which shows the node counts within the group.
Problem: Public nodes are counted twice.
Thanks
Comments
Comment #1
roald CreditAttribution: roald commentedDid some more research:
Apparently the number of nodes for each group comes from this query (dev_ is my table prefixes):
SELECT COUNT(*)
FROM dev_node n
INNER JOIN dev_og_ancestry oga ON n.nid = oga.nid
INNER JOIN dev_node_access na ON na.nid = n.nid
WHERE (na.grant_view >= 1
AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid = 0 AND na.realm = 'og_public') OR (na.gid = 51 AND na.realm = 'og_subscriber') OR (na.gid = 42 AND na.realm = 'og_subscriber')))
AND ( n.status = 1 AND oga.group_nid = 51 )
Looking at the rows returned by SELECT * from the same query shows me that each node is returned twice, one with realm = og_public and one with realm = og_subscriber, which in fact doubles the counted number of rows for public nodes.
Changing the query into the following seems to do the trick:
SELECT COUNT(distinct n.nid)
FROM dev_node n
INNER JOIN dev_og_ancestry oga ON n.nid = oga.nid
INNER JOIN dev_node_access na ON na.nid = n.nid
WHERE (na.grant_view >= 1
AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid = 0 AND na.realm = 'og_public') OR (na.gid = 51 AND na.realm = 'og_subscriber') OR (na.gid = 42 AND na.realm = 'og_subscriber')))
AND ( n.status = 1 AND oga.group_nid = 51 )
Honestly I'm not 100% sure it is the OG-module that builds this query, but at least DEVEL refers to og_handler_post_count
Hoping this is sufficiant to fix the issue
Thanks
Comment #2
roald CreditAttribution: roald commentedBelieve it or not, seems that I was able to fix the issue myself:
og_views.inc line 1198:
Exchanged
$cnt = db_result(db_query(db_rewrite_sql("SELECT COUNT(*) FROM {node} n INNER JOIN {og_ancestry} oga ON n.nid = oga.nid WHERE n.status = 1 AND oga.group_nid = %d $where"), $data->nid, $fielddata['options'] ));
with
$cnt = db_result(db_query(db_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {og_ancestry} oga ON n.nid = oga.nid WHERE n.status = 1 AND oga.group_nid = %d $where"), $data->nid, $fielddata['options'] ));
Maybe someone can review my work and implement the changes if it seems correct :-)
Thanks
Comment #3
roald CreditAttribution: roald commentedChanged category to bug-report
Comment #4
moshe weitzman CreditAttribution: moshe weitzman commentedcommitted. thanks.
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.