PDA

View Full Version : "Registry object is not an object in" with "fetch_session_complete"


Skyrider
06-02-2015, 05:40 AM
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:

$userdata->set('usergroupid', xx);
I've been getting the error message "Registry object is not an object in" -> "class_dm.php"

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?

require_once(DIR . '/includes/functions.php');
require_once(DIR . '/includes/class_core.php');
require_once('global.php');

Dave
06-02-2015, 11:00 AM
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.

kh99
06-02-2015, 11:47 AM
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.

Skyrider
06-02-2015, 04:53 PM
Sorry about that, forgot to include the plugin code:

global $vbulletin;

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

if (stuff here)
{
$dataman->set('usergroupid', 8);
$dataman->save();
}

For the sake of trying, I've replaced the main code of (stuff here) with:
IF ($vbulletin->userinfo['usergroupid'] == 9)

The bold is what I recently added, but getting this as a result:


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

Also tried $this->registry to replace vbulletin->userinfo, same message. Does this mean I need to include those php files? Or global already includes it, but the first "fatal error" is something I need to pay attention to.

kh99
06-02-2015, 07:29 PM
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.

Skyrider
06-02-2015, 07:45 PM
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.

kh99
06-02-2015, 11:24 PM
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.

Skyrider
06-03-2015, 05:27 AM
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.

kh99
06-03-2015, 08:46 AM
OK, so on hook fetch_session_complete you'd do this:
global $do_something;
$do_something = true;

Then in global_setup_complete:

global $do_something;
if ($do_something)
{
// your other code here
}


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.

Skyrider
06-04-2015, 06:55 AM
So:

fetch_session_complete
global $lowlevelundocheck;
$lowlevelundocheck = true;

global_setup_complete

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();
}
Unsure what I'm doing wrong, but nothing happens. It should move my test profile to usergroup ID (currently in another group)

kh99
06-04-2015, 09:57 AM
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.

cellarius
06-04-2015, 10:07 AM
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.