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

Reply
 
Thread Tools Display Modes
  #1  
Old 05-21-2015, 03:47 PM
Skyrider Skyrider is offline
 
Join Date: Feb 2006
Location: Netherlands
Posts: 1,392
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How does "Execution Order" in PHP code function?

I closed / removed my previous thread regarding this, thinking I wouldn't be needing it anymore.. but I think I was wrong. I've wrote a code, and give each of them an Execution order number..

First one: 1
Second plugin: 2

Running a very identical code, with:
Code:
$dataman->set('usergroupid', xx);
included. Now for some reason, after logging in (hook: login_process on both plugins) the second plugin with execution order 2 appears to beat execution order 1. I've tested both plugins and they work as intended..

Now.. the question is, why is the second one being executed faster then the first one? I included a:

Code:
IF $vbulletin->userinfo['usergroupid'] == xx)
to prevent any other usergroups being moved other than the one I selected. Even if I increase the second plugin's execution order, it still beats the first order. Can someone please explain why it does this?
Reply With Quote
  #2  
Old 05-21-2015, 05:19 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not sure I'm following you.

The execution order is just the order of execution (sorry to state the obvious), meaning:
execution order 1: executed first.
execution order 2: executed second.
The same as if you would put both codes into a php file one after the other, or if you would put both code lines into one plugin.

If you run virtually the same code with just a different value, than the second run will just overwrite the first.
Reply With Quote
  #3  
Old 05-21-2015, 08:09 PM
Skyrider Skyrider is offline
 
Join Date: Feb 2006
Location: Netherlands
Posts: 1,392
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Already mentioned that in my post at the bottom:

Quote:
to prevent any other usergroups being moved other than the one I selected.

yadacodehere
I included a code to prevent that second in overriding it.

Part of the first code:

Code:
$dataman =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
$dataman->set_existing($vbulletin->userinfo); 

if xxxxxx AND $vbulletin->userinfo['usergroupid'] == 13)

{
$dataman->set('usergroupid', 47);
$dataman->save();
}
Second code:

Code:
$dataman =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
$dataman->set_existing($vbulletin->userinfo); 

if xxxx AND $vbulletin->userinfo['usergroupid'] == 13)

{
$dataman->set('usergroupid', 37);
$dataman->save();
}
As you can see, both has an IF check if the user is in usergroup 13, and the second code moves the user to that usergroup.. Now, unless I did something wrong with the coding here.. the second code should not override the first one at all. As I mentioned in my post above, separately they work as a charm. (one disabled, other enabled, and the other way around).
Reply With Quote
  #4  
Old 05-21-2015, 08:24 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, like cellarius said, it's just the order they are executed in. All the code for all plugins on a given hook gets built in to one string, according to the execution order, then it's exec'd when that hook is reached. I've never heard anyone complain that the execution order didn't work right.

Is there a reason you have more than one plugin on a hook, rather than putting it all in one? I've done that myself sometimes just to organize things, but if you're having problems you could try putting it all in one plugin. In any case, we'd probably have to see more code to help you figure out what's going on.
Reply With Quote
  #5  
Old 05-21-2015, 08:28 PM
Skyrider Skyrider is offline
 
Join Date: Feb 2006
Location: Netherlands
Posts: 1,392
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

As you mentioned, doing it to organize things. Easier overview. I've put 'most' of the code in the above post (as an edit).. the xxx's are just other variables to check. But that's stating the obvious. The xxx's in both are almost identical, except for 1 check. But dunno why the second would beat the first execution order.
Reply With Quote
  #6  
Old 05-21-2015, 08:40 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So how did you determine that they were running in the wrong order?

If you wanted to you could actually see the code that's being executed by using something like var_dump($hook).
Reply With Quote
  #7  
Old 05-21-2015, 08:48 PM
Skyrider Skyrider is offline
 
Join Date: Feb 2006
Location: Netherlands
Posts: 1,392
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
So how did you determine that they were running in the wrong order?

If you wanted to you could actually see the code that's being executed by using something like var_dump($hook).
Well, seeing they are 2 different usergroups in the plugins.. it's easy to check where the user has been moved to. Also set up 2 different notices in those 2 groups. I multiple time ran the same check, execution 2 beats 1 (from my view anyway). Even if I alter execution to eg, 4, and leave the first one on 1, 4 beats 1.

I'm not a 'pro' regarding all of this.. Still learning, that's for sure.

Never used var_dump($hook) before, would the code display on a single page and only that single plugin? or....
Reply With Quote
  #8  
Old 05-21-2015, 09:31 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, using var_dump() will output whenever the code is run, and the way vbulletin works is it builds all the output into a string then sends it at the end, so the result would be that something you print out will come out before anything else and likely cause errors as well. Sometimes for debugging i do something like var_dump() a variable then call die, and you'll get a page with nothing else on it, but of course you only want to do that on a test forum. You could also open a file and write stuff to it, then look at the file after. Anyway, if you do decide to try to display that, $hook has all the code for that hook so you only need to var_dump it in one of the plugins.

You might want to temporarily put all the code in one plugin and disable the others, just to rule out the multiple plugins as a potential source of the problem.
Reply With Quote
  #9  
Old 05-22-2015, 07:29 AM
Skyrider Skyrider is offline
 
Join Date: Feb 2006
Location: Netherlands
Posts: 1,392
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Guess I'll combine them instead with if/else. Works for me, but finding it very strange the execution order is not working properly.
Reply With Quote
  #10  
Old 05-22-2015, 08:34 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, wait. were you saying that you depend on $vbulletin->userinfo['usergroupid'] == 13 being false in the second one to prevent it from running if the first one already did? Because using the datamanager to change the usergroup will not change $vbulletin->userinfo['usergroupid'] (I don't think).
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 05:23 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.04310 seconds
  • Memory Usage 2,260KB
  • Queries Executed 11 (?)
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
  • (4)bbcode_code
  • (2)bbcode_quote
  • (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
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_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