Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-05-2013, 11:29 PM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Question about serialized data and the datastore table

I'm working on a project for the admin CP that requires permission from the site owner / super admin so I don't want to put the settings in settings > options. I thought of creating a new table but as I researched how the various vB options are stored for use I see they are serialized and put in the datastore table. Somewhere this table is queried and the options unserialized to be available as $vbulletin->options. I want to do something similar and store my project settings this way as $vbulletin->my_project

If I go this route I see no reason to build a new table for my settings. Is there any reason I should have my settings in a new table if they're in datastore?

But most importantly, where is the datastore table queried and how do I unserialize my project settings (i.e., what hook location)?
Reply With Quote
  #2  
Old 08-06-2013, 08:22 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Function build_datastore() in includes/functions.php has a function build_datastore(). It has a parameter to automatically unserialize the data when it's read. You can arrange for your datastore item to be read back in (and unserialized) by adding it to $new_datastore_fetch[] at hook init_startup. If you want it only to be read in the admincp, you can check for VB_AREA == 'AdminCP'.

Just for the record, the settings are kept in the 'setting' table and automatically built in to the settings datastore item when they are edited. So I think another option might be to add your settings to the setting table but put a value for grouptitle that doesn't exist in the settinggroup table, then I think they won't be displayed. (But now that I think about it more, I'm not sure what the advantage of that would be.)
Reply With Quote
  #3  
Old 08-06-2013, 12:38 PM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I had gotten as far as build_datastore() but couldn't find where was queried. Your idea almost did it but you have to do it like this:

Code:
$datastore_fetch[] = "'my_project'";
Notice the nested quotes. I haven't followed it all the way through but I suspect the single quotes are there so it can be used in an eval to create $vbulletin->my_project from the serialized data stored under 'my_project' in datastore.

Code:
336   ($hook = vBulletinHook::fetch_hook('init_startup')) ? eval($hook) : false; 
337	
338	 if (!empty($datastore_fetch))
339	 {
340	     // Remove the single quotes that $datastore_fetch required
341	     foreach ($datastore_fetch AS $value)
342	     {
343	         $new_datastore_fetch[] = substr($value, 1, -1); 
344	     }
345	 }
My first idea here was to build all my options in settings > options then manually delete (not with the [delete] link) the setting group so it wouldn't show in settings>options. It still worked but I looked at the product xml file and it won't export the options if the group name is deleted.

Another idea I was tinkering with was to gather all the settings into an array in the code block to which the form submits , then serialize the array and write it to a file my_project/settings.txt. My project has its own my_project/global.php that is required by the other files, and in there it would read the file and unserialized the data into a settings array for all the other files. Either approach would work but I think I'll go with using datastore just to be more like vBulletin coding.

Thanks for the help.
Reply With Quote
  #4  
Old 08-06-2013, 01:51 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nerbert View Post
Notice the nested quotes. I haven't followed it all the way through but I suspect the single quotes are there so it can be used in an eval to create $vbulletin->my_project from the serialized data stored under 'my_project' in datastore.

That might be. You can actually set $new_datastore_fetch[] directly and not use the extra quotes if you'd rather. Looks like they decided to leave $datastore_fetch[] the same so as not to break old mods.
Reply With Quote
  #5  
Old 08-06-2013, 02:28 PM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
That might be. You can actually set $new_datastore_fetch[] directly and not use the extra quotes if you'd rather. Looks like they decided to leave $datastore_fetch[] the same so as not to break old mods.
I tried that and it didn't work (but maybe something else was wrong at the time). I think it needs $new_datastore_fetch (without single quotes) to know it should read that row in datastore and $datastore_fetch (with single quotes) to create $vbulletin->my_project with some sort of eval() code.

Anyway, I have it working more or less. Thanks again.
Reply With Quote
  #6  
Old 08-06-2013, 02:38 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nerbert View Post
I tried that and it didn't work (but maybe something else was wrong at the time).
You know, someone else said the same thing once, even after I tested it myself and it seemed to work. I guess there must be something I don't understand about it.
Reply With Quote
  #7  
Old 08-06-2013, 03:17 PM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You're right, that does work. I must have had another problem at the time. But I think I'll stick with the nested quoting anyway in case older versions need that. I'm hoping this will work in vB3. Some time when I don't have a dozen windows open I might follow through and see how all that works
Reply With Quote
  #8  
Old 08-06-2013, 05:39 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Good point, i hadn't thought of that. I checked vb3.8.7 and it has $new_datastore_fetch, but vb3.8.3 doesn't.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:31 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.11029 seconds
  • Memory Usage 2,234KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete