General developer forum

admin setting

 
Picture of Hossein Poursaeedi
admin setting
 

hey guys,

i have 2 questions about admin stings ,

1- can we disable cache when we use  "admin_setting_configtext()" method?
2- is it allow which directly insert record in "config_plugins" table ??


thanks in advance.

 
Average of ratings: -
Davo
Re: admin setting
Core developersParticularly helpful MoodlersPlugin developers

1. I'm not really sure what cache you are wanting to disable - when using that function on a settings page, saving the form will clear the cache.

2. If you want to insert a record in config_plugins, then call set_config('setting name', 'value', 'mypluginname') - don't insert directly in the database as that will break the caching of variables.

 
Average of ratings: Useful (1)
Picture of Hossein Poursaeedi
Re: admin setting
 

Thanks for your reply .
for the first part i must say , i manually update it (configtext) field in DB , and when i check the field in setting , its still show previous data which is belong cache , (when i purge cache , will be fine), as i need to update a field , is that any method to update like "set_config" as you have said for inserting?


thanks

 
Average of ratings: -
Davo
Re: admin setting
Core developersParticularly helpful MoodlersPlugin developers
set_config() is the method for inserting a new entry in the mdl_config_plugins table - there is no other method provided by Moodle for doing so (there is certainly not another function call for clearing the config cache - that would be pointless as there is already the set_config() function that sets the value and updates the cache).


 
Average of ratings: Useful (1)
Picture of Hossein Poursaeedi
Re: admin setting
 

so what ,if we want to update a record? 
let say when we insert a setting by text field [admin_setting_configtext] , since we dont change first argument of this method , it will update same record, so let say i want to do same thing in the code, instead of inserting , just updating the record ? does moodle provide any function? otherwise i should manually  update  and clear cache.

 
Average of ratings: -
Davo
Re: admin setting
Core developersParticularly helpful MoodlersPlugin developers

I'm not really sure how many other ways I can put this.

If you want to insert / update / delete a record in mdl_config_plugins, use set_config() - don't manually access that DB table as this will mean the cache will be out of date.

You can look at the code for it if you really want - it's all available here: https://github.com/moodle/moodle/blob/master/lib/moodlelib.php#L1383

As you can clearly see from the code - if there is no entry for that config setting, then a new record will be inserted, if there is an existing value, then it will be updated and if the value you are setting is null, then the existing record will be deleted or not inserted (as appropriate).


 
Average of ratings: -