![]() |
"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'); |
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.
|
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.
|
Sorry about that, forgot to include the plugin code:
Code:
global $vbulletin; Code:
IF ($vbulletin->userinfo['usergroupid'] == 9) Code:
Fatal error: Existing data passed is not an array |
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.
|
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. |
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.
|
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 :D. 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. |
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. |
So:
fetch_session_complete Code:
global $lowlevelundocheck; Code:
global $lowlevelundocheck; |
Hmm...well I guess we have to go back to Dave's question, what are you trying to do exactly? Unfortunately there doesn't seem to be any hook when a session object is created except the one you're using, and as I mentioned above, $vbulletin isn't ready yet at that point. I don't see why what you have above wouldn't work (you'd really want to have all the code except the "global $lowlevelundocheck;" inside the if, but that's just for efficiency). However, there are a couple of other places where session objects are created (login and logout) that happen after the global_setup_complete hook, and I don't know how those affect what you're doing.
I should have let Dave handle it, but I thought your problem might just be the global $vbulletin. |
I gather you did some standard debugging. As I said in another thread: If something does not work, start simple.
Have you tried setting your variable to something else than true, then printing the variable in the second plugin, to see if it is set? Have you tried an echo statement in your if clause, to see if the code is being run at all? Stuff like that. |
All times are GMT. The time now is 03:00 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 | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|