PDA

View Full Version : Some way to edit a query without a hook?


BirdOPrey5
12-21-2010, 05:56 PM
So i've been updating my "All Topics" mod and got an excellent version going that needs no file edits working from vBulletin 3.6 through 4.0.7 just fine...

But in 4.0.8 (and I presume, above) vital code was changed in 1 part which kills my hopes for a mod requiring no file edits.

I'm looking at forumdisplay.php at the forumdiplay_query_threadscount hook. The relevant code is:


$hook_query_fields = $hook_query_joins = $hook_query_where = '';
($hook = vBulletinHook::fetch_hook('forumdisplay_query_thre adscount')) ? eval($hook) : false;

# Include visible IN (0,1,2) in order to hit upon the 4 column index
$threadscount = $db->query_first_slave("
SELECT COUNT(*) AS threads,
(
SELECT COUNT(*) AS newthread
FROM " . TABLE_PREFIX . "thread AS thread
WHERE forumid = $foruminfo[forumid]
AND lastpost > $lastread
AND open <> 10
AND sticky = 0
$prefix_filter
$visiblethreads
$globalignore
$limitothers
$datecut
$hook_query_where
) AS newthread
$hook_query_fields
FROM " . TABLE_PREFIX . "thread AS thread
$tachyjoin
$hook_query_joins
WHERE forumid = $foruminfo[forumid]
AND sticky = 0
$prefix_filter
$visiblethreads
$globalignore
$limitothers
$datecut
$hook_query_where
");
$totalthreads = $threadscount['threads'];
$newthreads = $threadscount['newthread'];


In previous versions I was able to use the $hook_query_where and $hook_query_join hooks to edit this database call however in 4.0.8 they added new code, the old code is here:


$hook_query_fields = $hook_query_joins = $hook_query_where = '';
($hook = vBulletinHook::fetch_hook('forumdisplay_query_thre adscount')) ? eval($hook) : false;

# Include visible IN (0,1,2) in order to hit upon the 4 column index
$threadscount = $db->query_first_slave("
SELECT COUNT(*) AS threads, SUM(IF(thread.lastpost > $lastread AND open <> 10, 1, 0)) AS newthread
$hook_query_fields
FROM " . TABLE_PREFIX . "thread AS thread
$tachyjoin
$hook_query_joins
WHERE forumid = $foruminfo[forumid]
AND sticky = 0
$prefix_filter
$visiblethreads
$globalignore
$limitothers
$datecut
$hook_query_where
");
$totalthreads = $threadscount['threads'];
$newthreads = $threadscount['newthread'];



As you can see in the new code the $hook_query_joins is not above the first WHERE statement but $hook_query_where is in both sections of code.

I thought about overriding the entire $threadcount variable in a plugin but there is no hook between the time the variable is given value and the time it's used.

Are there any other tricks for this? Basically I need to change WHERE forumid = $foruminfo[forumid] to WHERE forumid IN ($myforums)...

I know I don't usually visit the 4.x forums- let me find out what I've been missing. :D

Also I'm 98% this is impossible but I wanted to confirm before I make people do manual file edits.

Boofo
12-21-2010, 07:35 PM
No other way to do it other than a file edit, AFAIK. If you wanted to add something to $hook_query_where, then yes, a plugin would work fine. But to change the query itself would need a file edit.

BirdOPrey5
12-21-2010, 08:54 PM
Thanks... that's what I suspected... good news is I may not need to edit that query at all... Now I just have to deal with VB4 template difference... <no appropriate smiley exists for what I'm feeling right now.>

Boofo
12-21-2010, 10:02 PM
You'll get it. I have faith in you. ;)

Darkwaltz4
12-22-2010, 01:52 AM
Something very advanced and drastic (due to some reference juggling), but I've actually used successfully, is to temporarily override the $db variable :p that way you can intercept the query that it makes and pass along the one you actually want to the original $db variable. No file edits! But complicated :D

BirdOPrey5
12-22-2010, 02:29 AM
Wow.. if that's even half as hard as it sounds it's going to be beyond me... Luckily in this case after further evaluation I didn't need to change this particular query to begin with and the 1 query I had to alter I was still able to. So the VB4 version will not need file edits after all. :up: