vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Can write to datastore, but not retrieve. (https://vborg.vbsupport.ru/showthread.php?t=174723)

rob30UK 03-31-2008 06:27 PM

Can write to datastore, but not retrieve.
 
I made a cron which writes to the datastore, but I cannot retrieve it in any plugins.

Just to be sure Im not going mad I changed my cron code to a very very simple
Code:

<?php
build_datastore('glossary_links', 'thisistestdata');
?>

True enough when the cron is fired the data is entered into the datastore which I can see via phpmyadmin.

Now I have tried every which way that I can to retrieve this data and have tried several hook locations but no matter what I do I cannot retrieve the data from out the datastore again. I've tried
Code:

global $vbulletin;
$glossary_links = $vbulletin->glossary_links;

Nothing seems to work. Does anyone know the stupidly obvious thing that I am forgetting to do here?

Boofo 03-31-2008 06:37 PM

Use this to build the datastore:

Code:

build_datastore('glossary_links', serialize($glossary_links),1);

and this to fetch it:

Code:


 if (method_exists($vbulletin->datastore,'do_fetch'))
 { // Datastore extension exists, use it
  $vbulletin->datastore->do_fetch('glossary_links',$errors);
  if ($errors[0])
  { // Fetch failed, use original datastore
  $vbulletin->datastore->do_db_fetch("'glossary_links'");
  }
 }
 else
 { // No extension, use original datastore
  $vbulletin->datastore->do_db_fetch("'glossary_links'");
 }
 $glossary_links = $vbulletin->glossary_links;


rob30UK 03-31-2008 07:30 PM

Hi Boofo!!

Thank you very very much for your help this has been driving me insane for hours.
I still cant get it going though...

In my test, this cron builds the datastore:
Code:

<?php
$kwdStr="I will not show at the end of every post!";
build_datastore('glossary_links', serialize($kwdStr),1);
?>

and in postbit_display_complete I run this code
Code:

if (method_exists($vbulletin->datastore,'do_fetch'))
 { // Datastore extension exists, use it
  $vbulletin->datastore->do_fetch('glossary_links',$errors);
  if ($errors[0])
  { // Fetch failed, use original datastore
  $vbulletin->datastore->do_db_fetch("'glossary_links'");
  }
 }
 else
 { // No extension, use original datastore
  $vbulletin->datastore->do_db_fetch("'glossary_links'");
 }
 $glossary_links = $vbulletin->glossary_links;

$this->post['message'] .= $glossary_links;

Nothing has come through - the datastore should be appended to the end of every post (I've tested that code also with a normal string.. eg. I can append hello to every post with $this->post['message'] .= "hello";)

Am I doing something wrong when I try and output the data? It's a plain string I am storing in the datastore, not an array or anything.

Boofo 03-31-2008 07:35 PM

Why not just do a profile field for the info?

--------------- Added [DATE]1206995932[/DATE] at [TIME]1206995932[/TIME] ---------------

have you truied using $glossary_links instead of $this->post['message']?

rob30UK 03-31-2008 07:49 PM

hah well, I'm using it for more than just this, I just broke it right down above to try and get any form of datastore working.

No, what I am really doing is using the extra thread fields lite hack to add an extra field to threads in the glossary forum. The extra field takes a comma seperated list of keywords.

The keywords, or key phrases will then get automatically linked back to the thread whenever they occur in any post on the site. i use the extra thread field approach because our staff can easy add the linked terms when creating glossary threads.

My cron basically goes along once a day and caches the 'keywords' and 'threadid' for all threads (where that extra field isnt blank)

Everything up to this point works but I cant carry on because even though the data is in the database in the datastore table I cannot retrieve it no matter what I do. The alternative is to do a database SELECT from threads table where keywords (field1) != ''

I can of course code around not having a datastore, but the fact is we do have a datastore.... but it seems very difficult to use for 'custom' data. I still cant get it going.

this:- $vbulletin->mydatastoreitem
is it returned in the same variable type 'as entered' for instance if I pass a string to the datastore, will it return a string? Or does it always return an array, or something else?

Sorry if I am seeming a little thick, PHP isnt my usual sweetstuff.

Boofo 03-31-2008 08:00 PM

I'm new at the datastore stuff myself so I know what you are going through. I did a hack for my site that uses the datastore to retrieve top poster, top thread starter, etc. The code I gave you is from that. Paul M and cheesgrits helped me get to the point of it working like it should.

Here is how I do it:

glossary_links[datastoreitem]

and it display the piece of info from the datastore I have entered into it. Here is how I set it up to add the info to the db.

Code:

$options = array(
 'arcadegames' => 1,
 'arcadecats' => 1,
 'getthreadviews' => 1,
 'topposter' => 1,
 'topposterid' => 1,
 'toppostercount' => 1,
 'topposterpercent' => 1,
 'topstarter' => 1,
 'topstarterid' => 1,
 'topstartercount' => 1,
 'topthreadspercent' => 1,
 'getfileviewsun' => 1,
 'getfileviewsid' => 1,
 'getfileviews' => 1,
 'ref2' => 1,
 'topreferrerid' => 1,
 'ref' => 1,
 'lastupdate' => 1,
);
build_datastore('statscache', serialize($options),1);

That is the install code query I run when setting up the hack. You would put glossary_links where I have statscache.

And here is the uninstall code I use:

Code:


DELETE FROM " . TABLE_PREFIX . "datastore WHERE title = 'statscache' LIMIT 1


rob30UK 03-31-2008 08:15 PM

Ok, thats very helpful boofo.....

Could I see an example of how you are reading these items back from the datastore?
That would appear to be where i'm falling down....

Boofo 03-31-2008 09:19 PM

The code I gave you (if (method_exists($vbulletin->datastore,'do_fetch'))) is what I use to pull the info for display. I put that at the very beginning of my code and then set up the variables to be added to the datastore at a given time (every 15 minutes for my hack). If you have IM, PM me and I can send you the hack so you can look at how I did it if that will help you at all.

Marco van Herwaarden 04-01-2008 07:13 AM

PHP Code:

$kwdStr="I will not show at the end of every post!";
build_datastore('glossary_links'serialize($kwdStr),1); 

Why are you serializing a string. Serializing is done on an array.

Boofo 04-01-2008 07:39 AM

I think he is trying to update the datastore there.


All times are GMT. The time now is 03:59 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.00989 seconds
  • Memory Usage 1,747KB
  • 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
  • (8)bbcode_code_printable
  • (1)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