From d8183ce9fe14e0c02e4c66b904b4a43cc4b9d7dc Mon Sep 17 00:00:00 2001 From: John Volk Date: Mon, 14 Aug 2023 19:37:46 -0400 Subject: [PATCH 1/2] Add CompareArrays helper function to help with nested arrays --- sccpManTraits/helperFunctions.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sccpManTraits/helperFunctions.php b/sccpManTraits/helperFunctions.php index fdbdd42..17d33f6 100644 --- a/sccpManTraits/helperFunctions.php +++ b/sccpManTraits/helperFunctions.php @@ -288,7 +288,13 @@ trait helperfunctions { return $sccp_conf_init; } - + public function compareArrays(array $a, array $b){ + if (array_diff_assoc($a, $b)===[]) { + return 0; + } + return ($a>$b)?1:-1; + } + public function checkTftpMapping(){ exec('in.tftpd -V', $tftpInfo); $info['TFTP Server'] = array('Version' => 'Not Found', 'about' => 'Mapping not available'); From 7183c01a226b47dbea89c4006f006876c3c5b5fe Mon Sep 17 00:00:00 2001 From: John Volk Date: Mon, 14 Aug 2023 19:50:22 -0400 Subject: [PATCH 2/2] Save only config differences back to DB On each page load the sccpsettings table would get truncated and repopulated with the same data causing a big bottleneck. Now we will only attempt to save settings to the DB that have changed. --- Sccp_manager.class.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index 3cd6ebd..ef4d9dc 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -95,6 +95,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { private $cnf_wr = null; public $sccppath = array(); public $sccpvalues = array(); + private $dbsccpvalues = array(); public $sccp_conf_init = array(); public $xml_data; public $class_error; //error construct @@ -136,6 +137,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } $this->sccpvalues = $this->dbinterface->get_db_SccpSetting(); //Initialise core settings + $this->dbsccpvalues = $this->sccpvalues; //Copy settings from DB for future reference $this->initializeSccpPath(); //Set required Paths $this->updateTimeZone(); // Get timezone from FreePBX //$this->findInstLangs(); @@ -800,9 +802,9 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { */ private function saveSccpSettings($save_value = array()) { - + $diffToSave = array_udiff_assoc($this->sccpvalues, $this->dbsccpvalues, array($this, "compareArrays")); if (empty($save_value)) { - $this->dbinterface->write('sccpsettings', $this->sccpvalues, 'replace'); //Change to replace as clearer + $this->dbinterface->write('sccpsettings', $diffToSave, 'update'); } else { $this->dbinterface->write('sccpsettings', $save_value, 'update'); }