vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   "Registry object is not an object in" with "fetch_session_complete" (https://vborg.vbsupport.ru/showthread.php?t=318916)

Skyrider 06-02-2015 05:40 AM

"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 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?

Code:

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:

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:
Code:

IF ($vbulletin->userinfo['usergroupid'] == 9)
The bold is what I recently added, but getting this as a result:

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

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:
PHP Code:

global $do_something;
$do_something true

Then in global_setup_complete:
PHP Code:

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
Code:

global $lowlevelundocheck;
$lowlevelundocheck = true;

global_setup_complete
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();
}

Unsure what I'm doing wrong, but nothing happens. It should move my test profile to usergroup ID (currently in another group)


All times are GMT. The time now is 01:10 PM.

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.01088 seconds
  • Memory Usage 1,746KB
  • 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
  • (7)bbcode_code_printable
  • (2)bbcode_php_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