Fix exception if sccpsettings table does not exist

Before the installer can create sccpsettings, FreePBX instantiates an SCCP_Manager object which requires sccpsettings.
Catch the exception and create the table
This commit is contained in:
steve-lad 2021-03-13 11:21:12 +01:00 committed by Diederik de Groot
parent d3ae6536d1
commit f4f11157e1
No known key found for this signature in database
GPG key ID: AFA728250A1BECD6
3 changed files with 40 additions and 15 deletions

View file

@ -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()

View file

@ -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("<li>" . _("Creating sccpsettings table...") . "</li>");
$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;
}

View file

@ -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 */