From ff1c451fe1e703868c3ee97fb752d407e9686ed0 Mon Sep 17 00:00:00 2001 From: steve-lad <72376554+steve-lad@users.noreply.github.com> Date: Thu, 24 Jun 2021 10:02:26 +0200 Subject: [PATCH] Update Installer and Sccp_manager Construct Move initial defaults reading from Construct to Install Move initVarFromXml to helper functions - no longer used as defaults should come from db Remove extraneous initialisations from Sccp_manager - these are now handled in Installer Save TFTP structure to sccpsettings in Installer Pass tftp_root to extconfigs ( if changed or uninitialised, was not written back to settingsFromDb before being passed to extconfigs --- Sccp_manager.class.php | 105 ++-------------------------- install.php | 41 ++++++++--- module.xml | 2 +- sccpManClasses/extconfigs.class.php | 36 +++++----- sccpManTraits/helperFunctions.php | 51 ++++++++++++++ 5 files changed, 106 insertions(+), 129 deletions(-) diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index e5d77ad..26dc630 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -139,34 +139,10 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { return; } - $this->sccpvalues = $this->dbinterface->get_db_SccpSetting(); // Overwrite Exist - $this->initializeSccpPath(); - $this->initVarfromDefs(); + $this->sccpvalues = $this->dbinterface->get_db_SccpSetting(); //Initialise core settings + $this->initializeSccpPath(); //Set required Paths + $this->updateTimeZone(); // Get timezone from FreePBX $this->initTftpLang(); - - if (!empty($this->sccpvalues['SccpDBmodel'])) { - if ($this->sccpvalues['sccp_compatible']['data'] > $this->sccpvalues['SccpDBmodel']['data']) { - $this->sccpvalues['sccp_compatible']['data'] = $this->sccpvalues['SccpDBmodel']['data']; - } - } - // Load Advanced Form Constructor Data - if (empty($this->sccpvalues['displayconfig'])) { - $xml_vars = __DIR__ . '/conf/sccpgeneral.xml.v' . $this->sccpvalues['sccp_compatible']['data']; - } else { - $xml_vars = __DIR__ . '/conf/' . $this->sccpvalues['displayconfig']['data'] . '.xml.v' . $this->sccpvalues['sccp_compatible']['data']; - } - if (!file_exists($xml_vars)) { - $xml_vars = __DIR__ . '/conf/sccpgeneral.xml'; - } - if (file_exists($xml_vars)) { - $this->xml_data = simplexml_load_file($xml_vars); - $this->initVarfromXml(); // Overwrite Exist - } - - //if (get_class($freepbx) === 'FreePBX') { - // only save settings when building a new FreePBX object - $this->saveSccpSettings(); - //} } /* @@ -199,73 +175,13 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { * Load config vars from base array */ - public function initVarfromDefs() { - foreach ($this->extconfigs->getExtConfig('sccpDefaults') as $key => $value) { - if (empty($this->sccpvalues[$key])) { - $this->sccpvalues[$key] = array('keyword' => $key, 'data' => $value, 'type' => '0', 'seq' => '0'); - } - } + public function updateTimeZone() { // Check timezone has not been changed in FreePBX and update if has if ($this->sccpvalues['ntp_timezone'] != \date_default_timezone_get()) { $this->sccpvalues['ntp_timezone'] = array('keyword' => 'ntp_timezone', 'seq'=>95, 'type' => 2, 'data' => \date_default_timezone_get()); } } - /* - * Load config vars from xml - */ - - public function initVarfromXml() { - if ((array) $this->xml_data) { - foreach ($this->xml_data->xpath('//page_group') as $item) { - foreach ($item->children() as $child) { - $seq = 0; - if (!empty($child['seq'])) { - $seq = (string) $child['seq']; - } - if ($seq < 99) { - if ($child['type'] == 'IE') { - foreach ($child->xpath('input') as $value) { - $tp = 0; - if (empty($value->value)) { - $datav = (string) $value->default; - } else { - $datav = (string) $value->value; - } - if (strtolower($value->type) == 'number') { - $tp = 1; - } - if (empty($this->sccpvalues[(string) $value->name])) { - $this->sccpvalues[(string) $value->name] = array('keyword' => (string) $value->name, 'data' => $datav, 'type' => $tp, 'seq' => $seq); - } - } - } - if ($child['type'] == 'IS' || $child['type'] == 'IED') { - if (empty($child->value)) { - $datav = (string) $child->default; - } else { - $datav = (string) $child->value; - } - if (empty($this->sccpvalues[(string) $child->name])) { - $this->sccpvalues[(string) $child->name] = array('keyword' => (string) $child->name, 'data' => $datav, 'type' => '2', 'seq' => $seq); - } - } - if (in_array($child['type'], array('SLD', 'SLS', 'SLT', 'SL', 'SLM', 'SLZ', 'SLTZN', 'SLA'))) { - if (empty($child->value)) { - $datav = (string) $child->default; - } else { - $datav = (string) $child->value; - } - if (empty($this->sccpvalues[(string) $child->name])) { - $this->sccpvalues[(string) $child->name] = array('keyword' => (string) $child->name, 'data' => $datav, 'type' => '2', 'seq' => $seq); - } - } - } - } - } - } - } - /* * Show form information - General */ @@ -957,11 +873,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { */ function initializeSccpPath() { - $driver_revision = array('0' => '', '430' => '.v431', '431' => '.v432', '432' => '.v432', '433' => '.v433' . $this->sccp_branch); - $ver_id = $this->aminterface->get_compatible_sccp(); - if (!empty($this->sccpvalues['SccpDBmodel'])) { - $ver_id = $this->sccpvalues['SccpDBmodel']['data']; - } + $this->sccppath = array( 'asterisk' => $this->sccpvalues['asterisk_etc_path']['data'], 'tftp_path' => $this->sccpvalues['tftp_path']['data'], @@ -973,11 +885,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { 'tftp_softkey' => $this->sccpvalues['tftp_softkey']['data'] ); - $driver = $this->FreePBX->Core->getAllDriversInfo(); - - $this->sccpvalues['sccp_compatible'] = array('keyword' => 'sccp_compatible', 'data' => $ver_id, 'type' => '1', 'seq' => '99'); - $driver = $this->FreePBX->Core->getAllDriversInfo(); // Check that Sccp Driver has been updated by above - $read_config = $this->cnf_read->getConfig('sccp.conf'); $this->sccp_conf_init['general'] = $read_config['general']; foreach ($read_config as $key => $value) { @@ -1317,7 +1224,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { break; case "netlang": // Remove Key case "tftp_path": - case "sccp_compatible": + case "sccp_compatible": // This is equal to SccpDBmodel break; default: if (!empty($value['data'])) { diff --git a/install.php b/install.php index d5d380a..db9cff0 100644 --- a/install.php +++ b/install.php @@ -8,7 +8,7 @@ global $db; global $amp_conf; global $version; global $aminterface; -global $extConfigs; +global $extconfigs; global $mobile_hw; global $useAmiForSoftKeys; global $settingsFromDb; @@ -23,11 +23,14 @@ $db_config = ''; $sccp_version = array(); $cnf_int = \FreePBX::Config(); +// Do not create Sccp_Manager object as not required. +// Only include required classes and create anonymous class for thisInstaller + $thisInstaller = new class{ use \FreePBX\modules\Sccp_Manager\sccpManTraits\helperFunctions; }; -$requiredClasses = array('amiinterface', 'extconfigs'); +$requiredClasses = array('aminterface', 'extconfigs'); foreach ($requiredClasses as $className) { $class = "\\FreePBX\\Modules\\Sccp_manager\\$className"; if (!class_exists($class, false)) { @@ -38,6 +41,7 @@ foreach ($requiredClasses as $className) { } } +// Get current default settings from db $stmt = $db->prepare("SELECT * FROM sccpsettings"); $stmt->execute(); $settingsFromDb = $stmt->fetchAll(\PDO::FETCH_ASSOC); @@ -45,11 +49,18 @@ foreach ($settingsFromDb as $key => $rowArray) { $settingsFromDb[$rowArray['keyword']] = $rowArray; unset($settingsFromDb[$key]); } +// Check that required settings are initialised and update db and $settingsFromDb if not +foreach ($extconfigs->getExtConfig('sccpDefaults') as $key => $value) { + if (empty($settingsFromDb[$key])) { + $settingsFromDb[$key] = array('keyword' => $key, 'data' => $value, 'type' => 0, 'seq' => 0); -// Do not create Sccp_Manager object as not required. -// Only include required classes - - + $sql = "REPLACE INTO sccpsettings (keyword, data, seq, type) VALUES ('{$key}', '{$value}', 0, 0)"; + $results = $db->query($sql); + if (DB::IsError($results)) { + die_freepbx(_("Error updating sccpsettings: $key")); + } + } +} CheckAsteriskVersion(); $sccp_version = CheckChanSCCPCompatible(); @@ -871,7 +882,7 @@ function checkTftpServer() { global $db; global $cnf_int; global $settingsFromDb; - global $extConfigs; + global $extconfigs; global $thisInstaller; $confDir = $cnf_int->get('ASTETCDIR'); // TODO: add option to use external server @@ -886,6 +897,8 @@ function checkTftpServer() { outn("