The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
"Registry object is not an object in" with "fetch_session_complete"
Now, as you are all aware.. I'm still learning a few things here and there. I recently got the idea to include some code into the fetch_session_complete hook for the users session. However, whenever I attempt to use any of my pre-existing code such as:
Code:
$userdata->set('usergroupid', xx); I've already included quite a few files, including the global.php file but clearly I'm doing something wrong here. Any pinpointers are welcome. I do really hope I can even alter the usergroup within the fetch_session_complete hook. Maybe I forgot to add more includes? Code:
require_once(DIR . '/includes/functions.php'); require_once(DIR . '/includes/class_core.php'); require_once('global.php'); |
#2
|
|||
|
|||
Do you have a better example of what exactly you're trying to do in the fetch_session_complete hook? The $userdata object is obviously non existent at that hook location, unless you included it somewhere yourself.
|
#3
|
|||
|
|||
Are you creating the $userdata in your plugin? If so, at that hook you should use $this->registry instead of $vbulletin, or else put a "global $vbulletin;" (without the quotes of course) before you use $vbulletin.
|
#4
|
|||
|
|||
Sorry about that, forgot to include the plugin code:
Code:
global $vbulletin; $dataman =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD); $dataman->set_existing($vbulletin->userinfo); if (stuff here) { $dataman->set('usergroupid', 8); $dataman->save(); } Code:
IF ($vbulletin->userinfo['usergroupid'] == 9) Code:
Fatal error: Existing data passed is not an array Called set_existing in /vbulletin/includes/class_core.php(4016) : eval()'d code on line 5 Called eval in /vbulletin/includes/class_core.php on line 4016 Called fetch_session in /vbulletin/includes/class_core.php on line 3757 Called vB_Session in /vbulletin/includes/init.php on line 647 Called require_once in /vbulletin/includes/class_bootstrap.php on line 101 Called init in /vbulletin/includes/class_bootstrap.php on line 72 Called bootstrap in /vbulletin/global.php on line 26 Called require_once in /vbulletin/forum.php on line 67 Called require in /vbulletin/index.php on line 43 in /vbulletin/includes/class_dm.php on line 265 |
#5
|
|||
|
|||
Oh, right. That hook is called in the middle of setting up $vbulletin, and the userdata hasn't been set yet. Is there any reason you need to use that hook? Maybe use something like global_setup_complete instead, if you can.
|
#6
|
|||
|
|||
The reason why I'm aiming for the session hook is because the session is only called when the session timer has elapsed, thus the php plugin would only be called for once every xx min/hours depending on the session settings I would use. Thus less queries in the end, rather than being called every single time the user browses the forums with, eg global_setup_complete.
If you have any other good hook or php code that only runs on the user eg, once per specified hours.. that'll be awesome. Though only when the user is browsing the forums. |
#7
|
|||
|
|||
Are you sure that hook's only called when a session has expired? It seems like a session object would have to be created every page load. But you could be right, I haven't studied it closely. Anyway, if it's true then one thing you could do is have a plugin using hook fetch_session_complete that just sets a global variable to true, then in global_setup_complete check that variable and only do the rest if it's true. I think that achieves the same thing except that $vbulletin will be completely set up when your code runs.
|
Благодарность от: | ||
MarkFL |
#8
|
|||
|
|||
Am I sure? No, but I have noticed that the fetch_session_complete hook is not called every time the use browses the forums or refreshes the page. Only after a specific time, so I figured it would have to do with the session time.
Got an example for both of them btw? Still a newbie at this . Like I said.. if you have any better replacements for this, I'm happy to hear it. if I would to include it into a hook like global_setup_complete, it would only check plugin every time the user refreshes the browser or browses through the forums. I prefer to avoid such constant checks, but rather do it in a timely matter. Unless of course a new hook can be created that only executes on the user once per hour, and only triggers once for the user when he browses the forums, and again after the hour expired and visits the forums again but doesn't check his profile after that hour expired, it has to be when he's active on the forums instead. |
#9
|
|||
|
|||
OK, so on hook fetch_session_complete you'd do this:
PHP Code:
PHP Code:
Obviously you can choose whatever variable name you want in place of $do_something. Choose something that's unlikely to conflict with an existing global. |
#10
|
|||
|
|||
So:
fetch_session_complete Code:
global $lowlevelundocheck; $lowlevelundocheck = true; Code:
global $lowlevelundocheck; $userdata_rank =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD); $userdata_rank->set_existing($vbulletin->userinfo); if ($lowlevelundocheck) { $userdata_rank->set('usergroupid', 2); $userdata_rank->save(); } |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|