diff --git a/Sccp_manager.inc/dbinterface.class.php b/Sccp_manager.inc/dbinterface.class.php index 8bbd930..d362149 100644 --- a/Sccp_manager.inc/dbinterface.class.php +++ b/Sccp_manager.inc/dbinterface.class.php @@ -149,12 +149,30 @@ class dbinterface public function get_db_SccpSetting() { global $db; - $stmt = $db->prepare('SELECT keyword, data, type, seq FROM sccpsettings ORDER BY type, seq'); - $stmt->execute(); - foreach ($stmt->fetchAll() as $var) { - $mysccpvalues[$var['keyword']] = array('keyword' => $var['keyword'], 'data' => $var['data'], 'seq' => $var['seq'], 'type' => $var['type']); + try { + $stmt = $db->prepare('SELECT keyword, data, type, seq FROM sccpsettings ORDER BY type, seq'); + $stmt->execute(); + foreach ($stmt->fetchAll() as $var) { + $mysccpvalues[$var['keyword']] = array('keyword' => $var['keyword'], 'data' => $var['data'], 'seq' => $var['seq'], 'type' => $var['type']); + } + return $mysccpvalues; + } catch(\PDOException $e) { + // sccpsettings table does not yet exist. FreePBX is instantiating + // a SCCP_Manager object from the Installer before the installer can + // create the table so will create here. + $stmt = $db-> prepare('CREATE TABLE IF NOT EXISTS sccpsettings ( + keyword VARCHAR (50) NOT NULL, + data VARCHAR (255) NOT NULL, + seq TINYINT (1), + type TINYINT (1) NOT NULL default 0, + PRIMARY KEY (keyword, seq, type ) + );'); + $check = $stmt->execute(); + if (\DB::IsError($check)) { + die_freepbx("Can not create sccpsettings table, error: $check\n"); + } + return array(); } - return $mysccpvalues; } public function get_db_sysvalues() diff --git a/install.php b/install.php index 54d2dca..daa9063 100644 --- a/install.php +++ b/install.php @@ -27,7 +27,6 @@ if (!class_exists($class, false)) { if (class_exists($class, false)) { $srvinterface = new $class(); } - function Get_DB_config($sccp_compatible) { global $mobile_hw; @@ -487,16 +486,16 @@ function InstallDB_sccpsettings() { global $db; outn("
  • " . _("Creating sccpsettings table...") . "
  • "); - $sql = "CREATE TABLE IF NOT EXISTS `sccpsettings` ( - `keyword` VARCHAR (50) NOT NULL default '', - `data` VARCHAR (255) NOT NULL default '', - `seq` TINYINT (1), - `type` TINYINT (1) NOT NULL default '0', - PRIMARY KEY (`keyword`,`seq`,`type`) - );"; - $check = $db->query($sql); + $stmt = $db-> prepare('CREATE TABLE IF NOT EXISTS sccpsettings ( + keyword VARCHAR (50) NOT NULL, + data VARCHAR (255) NOT NULL, + seq TINYINT (1), + type TINYINT (1) NOT NULL, + PRIMARY KEY (keyword, seq, type ) + );'); + $check = $stmt->execute(); if (DB::IsError($check)) { - die_freepbx("Can not create sccpsettings table, error:$check\n"); + die_freepbx("Can not create sccpsettings table, error: $check\n"); } return true; } diff --git a/uninstall.php b/uninstall.php index 0a58e13..6974b3b 100644 --- a/uninstall.php +++ b/uninstall.php @@ -56,6 +56,14 @@ if (!empty($version)) { sql("DELETE FROM kvstore WHERE module = 'sccpsettings'"); sql("DELETE FROM kvstore WHERE module = 'Sccp_manager'"); } + // By accessing the database, we have recreated sccpsettings table so now delete + // Need to rewrite this uninstaller. + $sql = "DROP TABLE IF EXISTS sccpsettings"; + $result = $db->query($sql); + if (DB::IsError($result)) { + die_freepbx($result->getDebugInfo()); + } + unset($result); /* Comment: Maybe save in sccpsettings, if the chan_sccp tables already existed in the database or if they were created by install.php */ /* So that you know if it is safe to drop/delete them */