vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Question about serialized data and the datastore table (https://vborg.vbsupport.ru/showthread.php?t=300868)

nerbert 08-05-2013 11:29 PM

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

kh99 08-06-2013 08:22 AM

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.)

nerbert 08-06-2013 12:38 PM

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.

kh99 08-06-2013 01:51 PM

Quote:

Originally Posted by nerbert (Post 2437508)
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.

nerbert 08-06-2013 02:28 PM

Quote:

Originally Posted by kh99 (Post 2437514)
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.

kh99 08-06-2013 02:38 PM

Quote:

Originally Posted by nerbert (Post 2437518)
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.

nerbert 08-06-2013 03:17 PM

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

kh99 08-06-2013 05:39 PM

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.


All times are GMT. The time now is 09:58 AM.

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.02648 seconds
  • Memory Usage 1,736KB
  • 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_code_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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