Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #11  
Old 05-22-2011, 05:27 PM
ZERO <ibis> ZERO <ibis> is offline
 
Join Date: Dec 2007
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh I had it generating txt files that outputted the values being passed to ensure they were working. I even had ones for various parts of the functions so I know it runs fine until it gets into that loop and does the if statement checks. However I feed that loop with hard coded values of lets say 16 for both paidsub_build and useradmin_update_save but it does not work on paidsub_build and does work on useradmin_update_save

It is mind blowing. Even with the variables set to the same values how can I get different results from the same function where the only difference is that it is being run on a different hook.

The part where is breaks down is here:
PHP Code:
$sbusergroups explode(","$sbmemgroups2);

foreach(
$sbusergroups as $sbgroup)
    {
        
$sbgroupint intval($sbgroup); 
The above code works fine in useradmin_update_save but breaks on paidsub_build even when they are for a fact processing the exact same input.

I got a b-day and graduation parties to get to today so I will deal with this more tomorrow. Thanks for all the help so far

--------------- Added [DATE]1306090100[/DATE] at [TIME]1306090100[/TIME] ---------------

Here is a good chunk of the functions (slightly edited)

PHP Code:
function first($userid$findstuff true$sbaid ""$sbmemgroups "")
{
    global 
$db$vB_Groups$sB_Groups$sB_Names$sB_Server$sB_WebClan$sB_WebDefault$sB_WebUpper$sB_WebProbation$sB_WebRoot$sbaidfield;

    
$fp fopen('d_userid.txt''w');
        
fwrite($fp$userid);
        
fclose($fp);    
    
    
    if (
$findstuff)
    {
        
$sbquery $db->query_read("
            SELECT " 
TABLE_PREFIX "userfield.field9
            FROM " 
TABLE_PREFIX "userfield
            WHERE " 
TABLE_PREFIX "userfield.userid = $userid
        "
);

        
$sbrow $db->fetch_array($sbquery);
        
$sbaid $sbrow['field9'];
        
        
$sbquery2 $db->query_read("
            SELECT membergroupids
            FROM " 
TABLE_PREFIX "user
            WHERE userid = 
$userid
        "
); 
        
        
$sbrow2 $db->fetch_array($sbquery2);
        
$sbmemgroups $sbrow2['membergroupids']; 
        
        
$fp fopen('data.txt''w');
        
fwrite($fp$sbmemgroups);
        
fclose($fp);
        
    }    
    
    
function2($userid$sbaid$sbmemgroups);
}

function 
function2($userid$sbaid$sbmemgroups)
{
    global 
$db$vB_Groups$sB_Groups$sB_Names$sB_Server$sB_WebClan$sB_WebDefault$sB_WebUpper$sB_WebProbation$sB_WebRoot$sbaidfield;
    
    
$fp fopen('data2.txt''w');
        
fwrite($fp$sbmemgroups);
        
fclose($fp);    
        
    
$sbmemgroups2 file_get_contents('data2.txt');
    
    
$sbusergroups explode(","$sbmemgroups2);

    
$sbnever false;
    
$sbalways false;
    
$sbpaid false;

    
//Determin what admin type the user is
    
foreach($sbusergroups as $sbgroup)
    {
        
$sbgroupint intval($sbgroup);

        if (
$sbgroupint == 10)
        {
            
$sbnever true;
        }
        else if (
$sbgroupint == 9)
        {
            
$sbalways true;
        }
        else if (
$sbgroupint == 16)
        {
        
$fp fopen('d_should_have_admin.txt''w');
                
fwrite($fp$sbgroupint);
                
fclose($fp);
            
$sbpaid true;
        }
    }

    
//Assign privlages to the selected type
    
if (!$sbnever)
    {
        if (
$sbalways || $sbpaid)
        {
        
$fp fopen('d_has_admin.txt''w');
                
fwrite($fp$sbpaid);
                
fclose($fp); 
The last line shown here never gets run on paidsub_build nor does the d_should_have_admin.txt this is even if I just read contents directly drom data2.txt from when it ran via the other hook and this applies to all variables not just the $sbmemgroups2

Something goes wrong in that foreach loop and only does so in paidsub_build even when the loop is fed with the same input.

While I am new to programing in vbb I have coded for years in general html php sourcepawn java ect and never have I seen a situation where you can feed a function the same input and get different outputs where there was not complex math or randomization involved... these results are blowing my mind and the only think I can think is that the function that the paidsub_hook is running in some how forcefully prevents the running of that loop. However, that would mean that we need to get a developer or someone that really understands the vb code in and out to explain just what is going wrong here.
Reply With Quote
  #12  
Old 05-22-2011, 05:59 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

First, you only use the TABLE_PREFIX for tables and not fields or columns (as in Kevin's post above which is proper).
Reply With Quote
  #13  
Old 05-22-2011, 06:08 PM
ZERO <ibis> ZERO <ibis> is offline
 
Join Date: Dec 2007
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I will make that change when I can but I can say it is not what is going wrong as that still outputs 6 as it should. I even bypassed it completely by just hardcoading $sbaid=6; in its place for a few runs. (as I make a post before jumping in the shower, I am actually writing post bys as I get ready for the day and try to get all this info posted up lol)

Thanks again for your help everyone, hopefully this can be figured out once I try out some new changes tomorrow.
Reply With Quote
  #14  
Old 05-23-2011, 01:10 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

FWIW I put this code in a plugin on both hooks and it worked in both places, both with and without 16 in the list of groups in data2.txt.

PHP Code:
$sbmemgroups2 file_get_contents('data2.txt'); 
     
$sbusergroups explode(","$sbmemgroups2); 

foreach(
$sbusergroups as $sbgroup
    { 
        
$sbgroupint intval($sbgroup); 

if (
$sbgroupint == 16
        { 
            
$sbpaid true
        } 
}

$fp fopen('output.txt'"w");
fwrite($fp"sbpaid = $sbpaid");
fclose($fp); 
Reply With Quote
  #15  
Old 05-23-2011, 05:26 PM
ZERO <ibis> ZERO <ibis> is offline
 
Join Date: Dec 2007
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Interesting that must mean that the issue is the variable that I was storing 16 in as that is the only difference. I will hard code in all numbers even for constant variables. In theory this should fix the problem.

--------------- Added [DATE]1306176320[/DATE] at [TIME]1306176320[/TIME] ---------------

Yea the issue is that when running in paidsub_build it randomly decides on its own if it is going to use constant variables or not.

I will now just hard code in all constant values in place of variables and hopefully that will then work.

--------------- Added [DATE]1306176915[/DATE] at [TIME]1306176915[/TIME] ---------------

Ok it appears to be working now. The issue is that for what ever reason within the paidsub_build hook you can not use any global variables other than $db so anything you want to use variable wise must be defined within the function. This is only the case with the paidsub_ hooks.

I now can move on to programing the rest which should be easy now that it is clear what the rules are for these functions.

Thank you all so much for you help, I could not have gotten this working without you!
Reply With Quote
  #16  
Old 05-23-2011, 06:17 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Glad you got it working. Yeah, the paidsub_build hook is in a function, so any globals you want to use would have to be declared with a "global" statement (except any vbulletin vars which might already be declared global in that function).

Edit: Oh, yeah, I do see you have the big list of globals in the code you posted a while back. Weird.
Reply With Quote
  #17  
Old 05-23-2011, 06:50 PM
ZERO <ibis> ZERO <ibis> is offline
 
Join Date: Dec 2007
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh they were declared with a global statement. They just did not work despite that but worked fine in other hooks...

Just a very strange glitch I never expected variables that were declared in a global statement to work on one hook but not on another. But whatever all I care about is the dam thing works now lol
Reply With Quote
Reply


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 07:56 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02484 seconds
  • Memory Usage 2,274KB
  • 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
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete