vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Get value from datastore. (https://vborg.vbsupport.ru/showthread.php?t=103523)

deathemperor 12-22-2005 02:02 PM

Get value from datastore.
 
I defined and add 2 new datastores, I successfully added it into the datastore table (totalthreads and totalposts) now I try using

$totalthreads1 = vb_number_format(unserialize($datastorecache['totalthreads']));
$totalposts1 = vb_number_format(unserialize($datastorecache['totalposts']));

to get the value back but I somehow can't, anyone knows a way ?

The Geek 12-22-2005 02:05 PM

Quote:

Originally Posted by deathemperor
I defined and add 2 new datastores, I successfully added it into the datastore table (totalthreads and totalposts) now I try using


$totalthreads1 = vb_number_format(unserialize($datastorecache['totalthreads']));
$totalposts1 = vb_number_format(unserialize($datastorecache['totalposts']));

to get the value back but I somehow can't, anyone knows a way ?

How did you save it to that datastore?

ie

build_datastore('my_datastore', serialize($myvalues));

Or did you just save it manually into the datastore?

deathemperor 12-22-2005 02:29 PM

of course I use build_datastore(), tried both ways:

$vbulletin->total['totalposts'] = $totalposts;
$vbulletin->total['totalthreads'] = $totalthreads;
build_datastore('total', serialize($vbulletin->total));

and

build_datastore('total', serialize($totalposts));
build_datastore('total', serialize($totalthreads));

the first one, I can get the value right after I use build_datastore, but I can't get it anywhere else. with the 2nd I have no idea how to get it

well I made it.

I borrow one datastore: maxloggedin and add 2 new value totalposts and totalthreads.

I wonder if there is a way to define a brand new datastore.

The Geek 12-22-2005 03:34 PM

You did, its called 'total'.
However the current problem with the datastore and the hook system is that you need to tell vB which 'datastores' you want caching. The problem being that you CANT do this without file edits as all hooks come AFTER the datastore is created.
Your only solution is to do what you did (hijack another 'datastore' that is cached by default) or manually query the datastore:

$myds = $db->query_read("SELECT data FROM " . TABLE_PREFIX . "datastore WHERE title ='mydatastore'");

$mydatastore = unserialize($myds['data']);

Bit of a bugger really :)

merk 12-22-2005 08:22 PM

Yeh, theres no way to manually retrieve a datastore item without adding it to the $specialtemplates array (which has to be done at code time, cant be done at runtime) without doing a query.

Paul M 12-22-2005 08:42 PM

The correct way would be to use this;

PHP Code:

$vbulletin->datastore->fetch(array('totalposts''totalthreads')); 

As previously stated, this will add a query;


Another way is to add

PHP Code:

$specialtemplates[]='totalposts';
$specialtemplates[]='totalthreads'

To the bottom of your config.php file.

merk 12-22-2005 09:00 PM

Actually datastore->fetch is VERY BAD as per my bug report, which they wont fix, http://www.vbulletin.com/forum/bugs3...iew&bugid=1390

Marco van Herwaarden 12-23-2005 05:20 AM

Until a better solution comes up, in my plugins i simply check if the datastoreitem is already loaded, if not just use 1 simple query to retrieve it and add it to the datastore yourself. This will require max. 1 very simple query that will add hardly any processing time.

Paul M 12-23-2005 05:28 AM

Quote:

Originally Posted by merk
Actually datastore->fetch is VERY BAD as per my bug report, which they wont fix, http://www.vbulletin.com/forum/bugs3...iew&bugid=1390

If it's in the init startup hook then I doubt any default items have been changed.

merk 12-23-2005 05:55 AM

Not all my datastore items are retrieved from there, though you shouldnt rely on that :)

I just made a function to do it for me that currently calls a query just like Marco said above.


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.01020 seconds
  • Memory Usage 1,737KB
  • 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
  • (2)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete