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
d3ae6536d1
commit
f4f11157e1
|
@ -149,12 +149,30 @@ class dbinterface
|
|||
public function get_db_SccpSetting()
|
||||
{
|
||||
global $db;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public function get_db_sysvalues()
|
||||
|
|
17
install.php
17
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,14 +486,14 @@ 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");
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue