Copy fix to core bug: Forum count incorrect when using access control modules

carnage - July 2, 2009 - 13:05
Project:Advanced Forum
Version:6.x-2.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:active
Description

duplicate of this bug: http://drupal.org/node/113611#comment-1764488

however it applies to advanced forum as well since the same query is used.

I 'fixed' the problem in this module as its easier to do in here than in anywhere else, patch attached.

AttachmentSize
adv_forum.patch667 bytes

#1

Michelle - July 2, 2009 - 13:22
Status:needs review» needs work

This patch subtracts lines that don't exist... Is it a bad patch or am I missing something? Assuming it's a bad patch and you're meaning to add the lines, can you give me some idea of what it's doing? I don't speak regex.

Thanks,

Michelle

#2

carnage - July 3, 2009 - 13:43

:s Must have fed the files into diff in the wrong order...

http://drupal.org/node/242605 this post explains in detail whats going on

The idea for the fix is that this rewrites a query that has access control added to it to only select distinct rows.

The $regex regex finds the INNER JOIN to the node access table and changes it to inner join a sub query instead as the join is now a subquery its possible to restrict it to DISTINCT values per node, fixing the issue.

Basically add these lines:
$regex = '#INNER JOIN \{node_access\} (na ON na.nid = n.nid) WHERE (.+) AND #'; //finds the offending join and added conditions to where
$replace = 'INNER JOIN ( SELECT DISTINCT na.nid FROM {node_access} na WHERE \2 ) \1 WHERE '; //replaces with subquery including DISTINCT moving the where conditions into the subquery.
$sql = preg_replace($regex,$replace,$sql);

after the db_rewrite_sql.

#3

Michelle - July 3, 2009 - 15:53
Status:needs work» needs review

That seems reasonable. I'll need to take some time to give it a good test before applying it to 1.x since that's a stable branch. I'd appreciate it if someone else out there could test it as well.

Michelle

#4

Michelle - July 30, 2009 - 01:30

3 weeks later, I gotta be honest. I don't see me getting time to do major testing with 1.x since I have my hands full with 2.x. Since I don't use access control modules, this isn't a priority for me, though I know it is for others. There's got to be someone else out there running node access modules that can give this a RTBC. Otherwise it's not likely to get in until 2.x.

Michelle

#5

dddave - August 9, 2009 - 17:53
Status:needs review» needs work

If carnage or Michelle could please submit a propper patch then I would be very willing to test it. I can apply patches but I might choke heavily on inserting something "by hand" without understanding of what I am doing. ;)

#6

Michelle - August 9, 2009 - 17:59

I discussed this on IRC with someone who's opinion I trust and he wasn't happy about the regex. Since I don't speak regex, I'm not thrilled about it, either. I'm hoping someone will come up with a better way of fixing this.

Michelle

#7

dddave - August 9, 2009 - 18:45

Ok. I'll stand put to test any patch that lands.

#8

Michelle - October 26, 2009 - 04:01
Title:Incorrect post counts when using access control modules» Copy fix to core bug: Forum count incorrect when using access control modules
Version:6.x-1.1» 6.x-2.x-dev
Category:bug report» task
Status:needs work» active

Looks like there's a lot of work being done on this in #113611: Forum count incorrect when using access control modules . Once it's sorted, I'll copy the solution. :)

Michelle

 
 

Drupal is a registered trademark of Dries Buytaert.