vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   How does "Execution Order" in PHP code function? (https://vborg.vbsupport.ru/showthread.php?t=318748)

Skyrider 05-21-2015 03:47 PM

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?

cellarius 05-21-2015 05:19 PM

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.

Skyrider 05-21-2015 08:09 PM

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).

kh99 05-21-2015 08:24 PM

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.

Skyrider 05-21-2015 08:28 PM

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.

kh99 05-21-2015 08:40 PM

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).

Skyrider 05-21-2015 08:48 PM

Quote:

Originally Posted by kh99 (Post 2546123)
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....

kh99 05-21-2015 09:31 PM

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.

Skyrider 05-22-2015 07:29 AM

Guess I'll combine them instead with if/else. Works for me, but finding it very strange the execution order is not working properly.

kh99 05-22-2015 08:34 AM

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).


All times are GMT. The time now is 08:44 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.00982 seconds
  • Memory Usage 1,740KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete