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 06-26-2014, 05:48 PM
burtonmiller burtonmiller is offline
 
Join Date: Jun 2014
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default save_settings failing vb 4.2

Trying to modify a settings option in a plugin - vb 4.2

Trying to call something like the following in a plugin - which is getting called on admin_options_processing_build:

$some_options = array('first_option' => 0);

save_settings($some_options);

Have tried many permutations. Errors result in every case. A memory error when I save the options (in dashboard) is the current problem. In no case have I gotten the options to actually save.

I am not a vb expert - and I am surprised how tricky it is to do something this seemingly simple.
Reply With Quote
  #2  
Old 06-26-2014, 06:14 PM
ForceHSS ForceHSS is offline
 
Join Date: Apr 2008
Posts: 6,357
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And the name of the plugin is? Also check server error logs if you not sure where to get them ask your host. If you don't know what you are doing best to leave it alone and ask in here how to change some coding so you don't crash your forums
Reply With Quote
  #3  
Old 06-26-2014, 06:30 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need to provide us with a better sample of code to digest. What is the memory error?

Reply With Quote
  #4  
Old 06-26-2014, 06:36 PM
burtonmiller burtonmiller is offline
 
Join Date: Jun 2014
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am making a new product (mod). We are doing them for several CMS's and Forum platforms.

There is very little code in it right now. To prove it, i made the smallest possible product, with just an option, and a plugin that tries to modify it - on a vanilla install 4.2.2. I have attached the xml file for this test product.

What I am looking for the shortest plugin code that will save an arbitrary option in an arbitrary product.

And here is the error:

Attached Files
File Type: xml product-test_saving_options.xml (1.6 KB, 3 views)
Reply With Quote
  #5  
Old 06-26-2014, 06:45 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think your problem is that calling save_settings() ends up executing hook admin_options_processing_build, so you have an infinite loop.
Reply With Quote
  #6  
Old 06-26-2014, 07:22 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
I think your problem is that calling save_settings() ends up executing hook admin_options_processing_build, so you have an infinite loop.
I was guessing the same after reading and looking at the hook, but I figured I needed a better explanation first.

Now that I see the memory error, I am pretty sure we are right. Lets take a look at the code and find out.

--------------- Added 26 Jun 2014 at 13:27 ---------------

Quote:
Originally Posted by burtonmiller View Post
I am making a new product (mod). We are doing them for several CMS's and Forum platforms.

There is very little code in it right now. To prove it, i made the smallest possible product, with just an option, and a plugin that tries to modify it - on a vanilla install 4.2.2. I have attached the xml file for this test product.

What I am looking for the shortest plugin code that will save an arbitrary option in an arbitrary product.

And here is the error:

In essence you are calling save_settings() from the save_settings() function. Take a look at "includes/adminfunctions_options.php" #642. You will see your hook is in the same function. The function is looping until it exhausts the memory. There is no need to call save_settings(), because after your hook the settings are written to the database.
Reply With Quote
  #7  
Old 06-26-2014, 07:38 PM
burtonmiller burtonmiller is offline
 
Join Date: Jun 2014
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK - that makes sense.

But I tried calling save_settings() from several other hooks - and could never get it to work.

I have a series of operations that I need to call in global_bootstrap_init_complete, but when I tried to save_settings there it just failed completely.

Is there a general alternative so that I can save an option in my code? I would like it work in all 4.x versions

Code anyone?
Reply With Quote
  #8  
Old 06-26-2014, 07:55 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Most likely you did not include the dependencies, in order to call save_settings();

I have not tried to do what you are doing, so I do not have an answer for you off the top of my head.

--------------- Added 26 Jun 2014 at 14:10 ---------------

//Noticed this function from class_upgrade - might be what you are looking for.
PHP Code:
function set_option($varname$grouptitle$value)
{
include_once 
DIR '/includes/adminfunctions_options.php';
$values = array($varname => $value);
save_settings($values);

Reply With Quote
  #9  
Old 06-27-2014, 06:18 PM
burtonmiller burtonmiller is offline
 
Join Date: Jun 2014
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That was close, but here is what actually worked. You pushed me in the right direction
------
include_once DIR . '/includes/adminfunctions.php';

include_once DIR . '/includes/adminfunctions_options.php';

function set_test_save_option($varname, $value)
{
$values = array($varname => $value);
save_settings($values);
}

set_test_save_option('test_saving_options_flag', 'Some Value');
------

This plugin is hooked to 'admin_complete', which seems to be a safe place to modify options. So, when you change an option, this code will get fired afterwards, and the option panel will reflect your changes.
Reply With Quote
Благодарность от:
tbworld
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 08:28 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.04078 seconds
  • Memory Usage 2,269KB
  • Queries Executed 14 (?)
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
  • (1)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (1)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (1)postbit_attachment
  • (9)postbit_onlinestatus
  • (9)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_postinfo_query
  • fetch_postinfo
  • 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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete