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:
parent
3362f5a7cf
commit
cc8eb549d0
|
@ -150,12 +150,30 @@ class dbinterface
|
||||||
public function get_db_SccpSetting()
|
public function get_db_SccpSetting()
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
|
try {
|
||||||
$stmt = $db->prepare('SELECT keyword, data, type, seq FROM sccpsettings ORDER BY type, seq');
|
$stmt = $db->prepare('SELECT keyword, data, type, seq FROM sccpsettings ORDER BY type, seq');
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
foreach ($stmt->fetchAll() as $var) {
|
foreach ($stmt->fetchAll() as $var) {
|
||||||
$mysccpvalues[$var['keyword']] = array('keyword' => $var['keyword'], 'data' => $var['data'], 'seq' => $var['seq'], 'type' => $var['type']);
|
$mysccpvalues[$var['keyword']] = array('keyword' => $var['keyword'], 'data' => $var['data'], 'seq' => $var['seq'], 'type' => $var['type']);
|
||||||
}
|
}
|
||||||
return $mysccpvalues;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_db_sysvalues()
|
public function get_db_sysvalues()
|
||||||
|
|
19
install.php
19
install.php
|
@ -27,7 +27,6 @@ if (!class_exists($class, false)) {
|
||||||
if (class_exists($class, false)) {
|
if (class_exists($class, false)) {
|
||||||
$srvinterface = new $class();
|
$srvinterface = new $class();
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get_DB_config($sccp_compatible)
|
function Get_DB_config($sccp_compatible)
|
||||||
{
|
{
|
||||||
global $mobile_hw;
|
global $mobile_hw;
|
||||||
|
@ -484,16 +483,16 @@ function InstallDB_sccpsettings()
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
outn("<li>" . _("Creating sccpsettings table...") . "</li>");
|
outn("<li>" . _("Creating sccpsettings table...") . "</li>");
|
||||||
$sql = "CREATE TABLE IF NOT EXISTS `sccpsettings` (
|
$stmt = $db-> prepare('CREATE TABLE IF NOT EXISTS sccpsettings (
|
||||||
`keyword` VARCHAR (50) NOT NULL default '',
|
keyword VARCHAR (50) NOT NULL,
|
||||||
`data` VARCHAR (255) NOT NULL default '',
|
data VARCHAR (255) NOT NULL,
|
||||||
`seq` TINYINT (1),
|
seq TINYINT (1),
|
||||||
`type` TINYINT (1) NOT NULL default '0',
|
type TINYINT (1) NOT NULL,
|
||||||
PRIMARY KEY (`keyword`,`seq`,`type`)
|
PRIMARY KEY (keyword, seq, type )
|
||||||
);";
|
);');
|
||||||
$check = $db->query($sql);
|
$check = $stmt->execute();
|
||||||
if (DB::IsError($check)) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,14 @@ if (!empty($version)) {
|
||||||
sql("DELETE FROM kvstore WHERE module = 'sccpsettings'");
|
sql("DELETE FROM kvstore WHERE module = 'sccpsettings'");
|
||||||
sql("DELETE FROM kvstore WHERE module = 'Sccp_manager'");
|
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 */
|
/* 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 */
|
/* So that you know if it is safe to drop/delete them */
|
||||||
|
|
Loading…
Reference in a new issue