From 8dc1175b371536289c5ea89eb8a448afb8f392d2 Mon Sep 17 00:00:00 2001
From: steve-lad <72376554+steve-lad@users.noreply.github.com>
Date: Sun, 8 Aug 2021 09:03:05 +0200
Subject: [PATCH] Update installer to add parent extensions to sccpline if they
exist
Previously ignored sccp extensions in freepbx devices and so created 'orphans'. Now create rows for sccpline for devices that already exist as sccp extensions in devices.
Remove dbug code
---
Sccp_manager.class.php | 2 --
install.php | 57 ++++++++++++++++++++----------
module.xml | 2 +-
sccpManClasses/Sccp.class.php.v433 | 1 -
sccpManTraits/ajaxHelper.php | 2 --
5 files changed, 40 insertions(+), 24 deletions(-)
diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php
index 3a2fd47..686b332 100644
--- a/Sccp_manager.class.php
+++ b/Sccp_manager.class.php
@@ -383,7 +383,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
function getPhoneButtons($get_settings, $ref_id = '', $ref_type = 'sccpdevice') {
// get Model Buttons info
- dbug($get_settings);
$res = array();
$def_feature = array('parkinglot' => array('name' => 'P.slot', 'value' => 'default'),
'devstate' => array('name' => 'Coffee', 'value' => 'coffee'),
@@ -494,7 +493,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
}
}
}
- dbug($res);
return $res;
}
diff --git a/install.php b/install.php
index be1ea80..16d5f1a 100644
--- a/install.php
+++ b/install.php
@@ -63,8 +63,8 @@ InstallDB_updateSchema($db_config);
cleanUpSccpSettings();
InstallDB_createButtonConfigTrigger();
-InstallDB_CreateSccpDeviceConfigView($sccp_compatible);
-createViewSccplineconfig();
+InstallDbCreateViews($sccp_compatible);
+installDbPopulateSccpline();
InstallDB_updateDBVer($sccp_compatible);
if ($chanSCCPWarning) {
outn("
");
@@ -323,7 +323,6 @@ function Get_DB_config($sccp_compatible)
$db_config_v4['sccpdevice'] = array_merge($db_config_v4['sccpdevice'],$db_config_v5['sccpdevice']);
$db_config_v4['sccpline'] = array_merge($db_config_v4['sccpline'],$db_config_v5['sccpline']);
$db_config_v4['sccpsettings'] = $db_config_v5['sccpsettings'];
- dbug($db_config_v4['sccpdevice']);
}
return $db_config_v4;
}
@@ -497,7 +496,6 @@ function InstallDB_updateSchema($db_config)
if (!empty($sql_rename)) {
outn("
" . _("Renaming table columns ") . $tabl_name ."");
$sql_rename = "ALTER TABLE {$tabl_name} " . substr($sql_rename, 0, -2);
- dbug($sql_rename);
try {
$check = $db->query($sql_rename);
} catch (\Exception $e) {
@@ -697,7 +695,7 @@ function InstallDB_updateDBVer($sccp_compatible)
return true;
}
-function InstallDB_CreateSccpDeviceConfigView($sccp_compatible)
+function InstallDbCreateViews($sccp_compatible)
{
global $db;
outn("" . _("(Re)Create sccpdeviceconfig view") . "");
@@ -746,16 +744,12 @@ function InstallDB_CreateSccpDeviceConfigView($sccp_compatible)
LEFT JOIN sccpuser sccpuser ON ( sccpuser.name = sccpdevice.loginname )
GROUP BY sccpdevice.name;";
}
-
- $results = $db->query($sql);
- if (DB::IsError($results)) {
+ $stmt = $db->prepare($sql);
+ $stmt->execute();
+ if (DB::IsError($stmt)) {
die_freepbx(sprintf(_("Error updating sccpdeviceconfig view. Command was: %s; error was: %s "), $sql, $results->getMessage()));
}
- return true;
-}
-function createViewSccplineconfig() {
- global $db;
outn("" . _("(Re)Create sccplineconfig view") . "");
$sql = "DROP VIEW IF EXISTS sccplineconfig;
@@ -769,13 +763,44 @@ function createViewSccplineconfig() {
sccpline.directed_pickup, sccpline.directed_pickup_context, sccpline.pickup_modeanswer, sccpline.amaflags, sccpline.dnd, sccpline.setvar,
sccpline.namedcallgroup, sccpline.namedpickupgroup, sccpline.phonecodepage, sccpline.videomode
FROM sccpline";
- $results = $db->query($sql);
- if (DB::IsError($results)) {
+ $stmt = $db->prepare($sql);
+ $stmt->execute();
+ if (DB::IsError($stmt)) {
die_freepbx(sprintf(_("Error updating sccplineconfig view. Command was: %s; error was: %s "), $sql, $results->getMessage()));
}
return true;
}
+function installDbPopulateSccpline() {
+ // Lines in Sccp_manager are devices in FreePbx. Need to ensure that these two tables are synchronised on install
+ global $db;
+ $freePbxExts = array ();
+ $sccpExts =array();
+ $sql = "SELECT id AS name, user AS accountcode, description AS label FROM devices WHERE tech='sccp'";
+ $stmt = $db->prepare($sql);
+ $stmt->execute();
+ $freePbxExts = $stmt->fetchAll(\PDO::FETCH_ASSOC|\PDO::FETCH_UNIQUE);
+
+ $sql = "SELECT name, accountcode, label FROM sccpline";
+ $stmt = $db->prepare($sql);
+ $stmt->execute();
+ $sccpExts = $stmt->fetchAll(\PDO::FETCH_ASSOC|\PDO::FETCH_UNIQUE);
+ $linesToCreate = array_diff_assoc($freePbxExts, $sccpExts);
+
+ foreach ($linesToCreate as $key => $valArr) {
+ $stmt = $db->prepare("INSERT into sccpline (name, accountcode, description, label) VALUES (:name, :accountcode, :description, :label)");
+ $stmt->bindParam(':name',$key,\PDO::PARAM_STR);
+ $description = "{$valArr['label']} <{$key}>";
+ $stmt->bindParam(':accountcode',$valArr['accountcode'],\PDO::PARAM_STR);
+ $stmt->bindParam(':description',$description,\PDO::PARAM_STR);
+ $stmt->bindParam(':label',$valArr['label'],\PDO::PARAM_STR);
+ $stmt->execute();
+ if (DB::IsError($stmt)) {
+ die_freepbx(sprintf(_("Error inserting into sccpline. Command was: %s; error was: %s "), $stmt, $stmt->getMessage()));
+ }
+ }
+}
+
function createBackUpConfig()
{
global $amp_conf;
@@ -1047,10 +1072,6 @@ function cleanUpSccpSettings() {
}
}
*/
- // TODO: It seems that DOCUMENT ROOT is not always set so maybe should switch to AMPWEBROOT.
- // need to declare amp_conf global each time.
- //global $amp_conf;
- //dbug($amp_conf['AMPWEBROOT']);
// Clean up sccpsettings to remove legacy values.
$xml_vars = $amp_conf['AMPWEBROOT'] . "/admin/modules/sccp_manager/conf/sccpgeneral.xml.v{$sccp_compatible}";
$thisInstaller->xml_data = simplexml_load_file($xml_vars);
diff --git a/module.xml b/module.xml
index 8e060ab..bdd0e5a 100644
--- a/module.xml
+++ b/module.xml
@@ -1,7 +1,7 @@
sccp_manager
SCCP Manager
- 14.3.0.5
+ 14.3.0.6
setup
SCCP Connectivity
Steve Lad, Alex GP
diff --git a/sccpManClasses/Sccp.class.php.v433 b/sccpManClasses/Sccp.class.php.v433
index 4cf7d9f..f5d2517 100644
--- a/sccpManClasses/Sccp.class.php.v433
+++ b/sccpManClasses/Sccp.class.php.v433
@@ -111,7 +111,6 @@ class Sccp extends \FreePBX\modules\Core\Driver {
public function addDevice($id, $settings) {
// This is actually save line and is used by add and edit.
- dbug($settings);
$add_fld = array ("name"=>'label',"outboundcid"=>'cid_num',"langcode"=>'language',"extdisplay"=>'description','devinfo_mailbox'=>'mailbox');
$settings['cid_num']['value'] = '';
$settings['cid_name']['value'] = '';
diff --git a/sccpManTraits/ajaxHelper.php b/sccpManTraits/ajaxHelper.php
index eee0b42..4c37482 100644
--- a/sccpManTraits/ajaxHelper.php
+++ b/sccpManTraits/ajaxHelper.php
@@ -400,7 +400,6 @@ trait ajaxHelper {
}
function handleSubmit($request, $validateonly = false) {
- dbug($request);
$hdr_prefix = 'sccp_';
$hdr_arprefix = 'sccp-ar_';
$save_settings = array();
@@ -690,7 +689,6 @@ trait ajaxHelper {
}
function saveSccpDevice($get_settings, $validateonly = false) {
- dbug($get_settings);
$hdr_prefix = 'sccp_hw_';
$hdr_arprefix = 'sccp_hw-ar_';
$hdr_vendPrefix = 'sccp_hw_vendorconfig';