Add apply button on 2.3 pkg xml framework
-
Hi,
Since dansguardian package on 2.x, I've implemented the 'apply changes' on packages using pkg framework.
After bootstrap move on 2.3, in order to get the same functionality I've started using functions mark_subsystem_dirty, check_subsystem_drity, etc.
The procedure below shows how to add this function to any package gui based on pkg framework.
On each package xml file, add a function call to check dirty state.
<custom_php_resync_config_command>sync_package_e2guardian();</custom_php_resync_config_command> <custom_php_command_before_form>e2guardian_check_config();</custom_php_command_before_form>
On package.inc file, create the check config state function
function e2guardian_check_config() { global $savemsg, $config; if (!isset($config['installedpackages']['e2guardian']['config'][0]['enable'])) { return 1; } if (isset($_REQUEST['apply'])) { e2guardian_start("no", false, true); return; } if (is_subsystem_dirty('e2guardian')) { $savemsg = gettext("E2guardian configuration has been changed.") . " " . gettext("The changes must be applied for them to take effect."); $savemsg .= "<a> </a>"; } return 0; } **On the place you call the code to write files and/or restart the service, replace it with mark_subsystem_dirty('your_package')**
function sync_package_e2guardian($via_rpc = "no", $install_process = false) {
global $config, $g;
.
. /all code stuff and checks.../
.
//mark config changes
mark_subsystem_dirty('e2guardian');
}**Under the function you created to separate save from apply changes on your package inc file, clean the 'dirty' state**
function e2guardian_start($via_rpc = "no", $install_process = false, $force_start = false) {
global $g, $config, $savemsg;clear_subsystem_dirty('e2guardian');
.
.
.The image attached shows the result.  