Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 12-21-2010, 05:56 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Some way to edit a query without a hook?

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:

PHP Code:
    $hook_query_fields $hook_query_joins $hook_query_where '';
    (
$hook vBulletinHook::fetch_hook('forumdisplay_query_threadscount')) ? 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:

PHP Code:
$hook_query_fields $hook_query_joins $hook_query_where '';
    (
$hook vBulletinHook::fetch_hook('forumdisplay_query_threadscount')) ? 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.

Also I'm 98% this is impossible but I wanted to confirm before I make people do manual file edits.
Reply With Quote
  #2  
Old 12-21-2010, 07:35 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 12-21-2010, 08:54 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.>
Reply With Quote
  #4  
Old 12-21-2010, 10:02 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You'll get it. I have faith in you.
Reply With Quote
  #5  
Old 12-22-2010, 01:52 AM
Darkwaltz4's Avatar
Darkwaltz4 Darkwaltz4 is offline
 
Join Date: Oct 2002
Location: Chicago
Posts: 1,538
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Something very advanced and drastic (due to some reference juggling), but I've actually used successfully, is to temporarily override the $db variable 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
Reply With Quote
  #6  
Old 12-22-2010, 02:29 AM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:15 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.11413 seconds
  • Memory Usage 2,229KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete