Modifying a configuration string 'live'.

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
deggy
Posts: 5
Joined: 26 Jul 2019, 01:56

Modifying a configuration string 'live'.

Post by deggy »

I'm working on a feature to allow emails to be easily turned on and off. As an administrator sometimes I need to carry out bulk updates that all team members are aware off - on these occasions I needed to be able to temporarily disable emails in an intuitive way without constantly going into the configuration file.

I'll share my work when completed, but I am wondering what the best way is to set the configuration strings (in this case '$g_enable_email_notification') 'on-the-fly' is? Is there some way that endures through a login session of setting that string to a value other than the one contained in config_inc.php and having it easily revert to the default value on logout?

At the moment I'm using cookies, but I'd need to modify less code if I could manipulate the string value on a per-session basis.

Thanks,

Dan
atrol
Site Admin
Posts: 8353
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Modifying a configuration string 'live'.

Post by atrol »

To disable / set in databse

Code: Select all

config_set( 'enable_email_notification', OFF, auth_get_current_user_id() );
to delete / revert to setting in config_inc.php

Code: Select all

config_delete( 'enable_email_notification', auth_get_current_user_id() );
Please use Search before posting and read the Manual
deggy
Posts: 5
Joined: 26 Jul 2019, 01:56

Re: Modifying a configuration string 'live'.

Post by deggy »

OK, thanks.

That solution, I assume, makes that selection global for the period that the user is online (therefore, somebody else on another session will still not have emails sent in response to actions like bugnotes being updates).

My solution currently sets a cookie on the user's machine. When the user toggles a button this sets the cookie value (and the value of the cookie is then reflexted in the text and colour of the button which I have in the menu bar). The cookie is also then queried by various functions in email_api.php (for example, in email_generic_to_recipients

Code: Select all

if( OFF == config_get( 'enable_email_notification' )  || $_COOKIE["auditmanager_email_send"] == 'nosend' )
The thinking is that this will then generally send the email according to the settings of

Code: Select all

$enable_email_notification
but will honor the cookie for individual sessions if it has been set. PHP of course will just ignore the check if the cooke doesn't exist.

There's a little bit of jQuery in there too.

Is there a more graceful way to do this that means I don't need to modify 5 functions within email_api.php?

Image
Image
atrol
Site Admin
Posts: 8353
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Modifying a configuration string 'live'.

Post by atrol »

deggy wrote: 26 Aug 2019, 00:04 That solution, I assume, makes that selection global for the period that the user is online
Did you try or do you assume?
I didn't try, but I expect that the setting is just used for the current user (auth_get_current_user_id())
Please use Search before posting and read the Manual
Post Reply