Update Uninstaller
Create Backup of SCCP tables Remove all tables Remove views and keys
This commit is contained in:
parent
808e676972
commit
09db30fe9f
|
@ -45,7 +45,7 @@ $db_config = Get_DB_config($sccp_compatible);
|
||||||
$sccp_db_ver = CheckSCCPManagerDBVersion();
|
$sccp_db_ver = CheckSCCPManagerDBVersion();
|
||||||
|
|
||||||
// BackUp Old config
|
// BackUp Old config
|
||||||
CreateBackUpConfig();
|
createBackUpConfig();
|
||||||
RenameConfig();
|
RenameConfig();
|
||||||
|
|
||||||
InstallDB_updateSchema($db_config);
|
InstallDB_updateSchema($db_config);
|
||||||
|
@ -708,7 +708,7 @@ function InstallDB_CreateSccpDeviceConfigView($sccp_compatible)
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
function CreateBackUpConfig()
|
function createBackUpConfig()
|
||||||
{
|
{
|
||||||
global $amp_conf;
|
global $amp_conf;
|
||||||
outn("<li>" . _("Creating Config BackUp") . "</li>");
|
outn("<li>" . _("Creating Config BackUp") . "</li>");
|
||||||
|
@ -718,7 +718,7 @@ function CreateBackUpConfig()
|
||||||
$dir = $cnf_int->get('ASTETCDIR');
|
$dir = $cnf_int->get('ASTETCDIR');
|
||||||
|
|
||||||
$fsql = $dir.'/sccp_backup_'.date("Ymd").'.sql';
|
$fsql = $dir.'/sccp_backup_'.date("Ymd").'.sql';
|
||||||
$result = exec('mysqldump '.$amp_conf['AMPDBNAME'].' --password='.$amp_conf['AMPDBPASS'].' --user='.$amp_conf['AMPDBUSER'].' --single-transaction >'.$fsql, $output);
|
$result = exec('mysqldump '.$amp_conf['AMPDBNAME'].' --password='.$amp_conf['AMPDBPASS'].' --user='.$amp_conf['AMPDBUSER'].' --single-transaction >'.$fsql);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$zip = new \ZipArchive();
|
$zip = new \ZipArchive();
|
||||||
|
@ -744,7 +744,7 @@ function CreateBackUpConfig()
|
||||||
outn("<li>" . _("Error Creating BackUp: ") . $filename ."</li>");
|
outn("<li>" . _("Error Creating BackUp: ") . $filename ."</li>");
|
||||||
}
|
}
|
||||||
unlink($fsql);
|
unlink($fsql);
|
||||||
outn("<li>" . _("Create Config BackUp: ") . $filename ."</li>");
|
outn("<li>" . _("Config backup created: ") . $filename ."</li>");
|
||||||
}
|
}
|
||||||
|
|
||||||
function RenameConfig()
|
function RenameConfig()
|
||||||
|
|
102
uninstall.php
102
uninstall.php
|
@ -36,46 +36,80 @@ if (!defined('FREEPBX_IS_AUTH')) {
|
||||||
|
|
||||||
global $db;
|
global $db;
|
||||||
$version = FreePBX::Config()->get('ASTVERSION');
|
$version = FreePBX::Config()->get('ASTVERSION');
|
||||||
|
global $sqlTables;
|
||||||
|
$sqlTables = array('sccpbuttonconfig','sccpdevice','sccpline','sccpuser','sccpsettings','sccpdevmodel');
|
||||||
|
createBackUpConfig();
|
||||||
|
|
||||||
out('Removing all Sccp_manager tables');
|
function createBackUpConfig()
|
||||||
$tables = array('sccpdevmodel', 'sccpsettings');
|
{
|
||||||
foreach ($tables as $table) {
|
global $amp_conf;
|
||||||
|
global $sqlTables;
|
||||||
|
outn("<li>" . _("Creating Config BackUp") . "</li>");
|
||||||
|
$cnf_int = \FreePBX::Config();
|
||||||
|
$backup_files = array('extensions','extconfig','res_mysql', 'res_config_mysql','sccp','sccp_hardware','sccp_extensions');
|
||||||
|
$backup_ext = array('_custom.conf', '_additional.conf','.conf');
|
||||||
|
$dir = $cnf_int->get('ASTETCDIR');
|
||||||
|
|
||||||
|
|
||||||
|
$sqlTables = array('sccpbuttonconfig','sccpdevice','sccpline','sccpuser','sccpsettings','sccpdevmodel');
|
||||||
|
$sqlTablesString = implode(' ',$sqlTables);
|
||||||
|
$sqlBuFile = $dir.'/sccp_backup_'.date("Ymd").'.sql';
|
||||||
|
$result = exec("mysqldump {$amp_conf['AMPDBNAME']} {$sqlTablesString}
|
||||||
|
--password={$amp_conf['AMPDBPASS']}
|
||||||
|
--user={$amp_conf['AMPDBUSER']}
|
||||||
|
--single-transaction >{$sqlBuFile}");
|
||||||
|
try {
|
||||||
|
$zip = new \ZipArchive();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
outn("<br>");
|
||||||
|
outn("<font color='red'>PHPx.x-zip not installed where x.x is the installed PHP version. Install it before continuing !</font>");
|
||||||
|
die_freepbx();
|
||||||
|
}
|
||||||
|
$filename = $dir . "/sccp_uninstall_backup" . date("Ymd"). ".zip";
|
||||||
|
if ($zip->open($filename, \ZIPARCHIVE::CREATE)) {
|
||||||
|
foreach ($backup_files as $file) {
|
||||||
|
foreach ($backup_ext as $b_ext) {
|
||||||
|
if (file_exists($dir . '/'.$file . $b_ext)) {
|
||||||
|
$zip->addFile($dir . '/'.$file . $b_ext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file_exists($sqlBuFile)) {
|
||||||
|
$zip->addFile($sqlBuFile);
|
||||||
|
}
|
||||||
|
$zip->close();
|
||||||
|
} else {
|
||||||
|
outn("<li>" . _("Error Creating BackUp: ") . $filename ."</li>");
|
||||||
|
outn("<br>");
|
||||||
|
outn("<font color='red'>PHPx.x-zip not installed where x.x is the installed PHP version. Install it before continuing !</font>");
|
||||||
|
die_freepbx();
|
||||||
|
}
|
||||||
|
unlink($sqlBuFile);
|
||||||
|
outn("<li>" . _("Config backup created: ") . $filename ."</li>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($version)) {
|
||||||
|
$check = $db->getRow("SELECT 1 FROM `kvstore` LIMIT 0", DB_FETCHMODE_ASSOC);
|
||||||
|
if (!(DB::IsError($check))) {
|
||||||
|
outn("<li>" . _("Deleting keys FROM kvstore..") . "</li>");
|
||||||
|
sql("DELETE FROM kvstore WHERE module = 'sccpsettings'");
|
||||||
|
sql("DELETE FROM kvstore WHERE module = 'Sccp_manager'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outn("<li>" . _('Removing all Sccp_manager tables') . "</li>");
|
||||||
|
foreach ($sqlTables as $table) {
|
||||||
$sql = "DROP TABLE IF EXISTS {$table}";
|
$sql = "DROP TABLE IF EXISTS {$table}";
|
||||||
$result = $db->query($sql);
|
$result = $db->query($sql);
|
||||||
if (DB::IsError($result)) {
|
if (DB::IsError($result)) {
|
||||||
die_freepbx($result->getDebugInfo());
|
die_freepbx($result->getDebugInfo());
|
||||||
}
|
}
|
||||||
|
$sql = "DROP VIEW IF EXISTS sccpdeviceconfig";
|
||||||
|
$result = $db->query($sql);
|
||||||
|
if (DB::IsError($result)) {
|
||||||
|
die_freepbx($result->getDebugInfo());
|
||||||
|
}
|
||||||
unset($result);
|
unset($result);
|
||||||
}
|
}
|
||||||
if (!empty($version)) {
|
outn("<li>" . _("Uninstall Complete") . "</li>");
|
||||||
// Woo, we have a version
|
return true;
|
||||||
$check = $db->getRow("SELECT 1 FROM `kvstore` LIMIT 0", DB_FETCHMODE_ASSOC);
|
|
||||||
if (!(DB::IsError($check))) {
|
|
||||||
//print_r("none, creating table :". $value);
|
|
||||||
echo "Deleting keys FROM kvstore..";
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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 */
|
|
||||||
|
|
||||||
/* DROP VIEW IF EXISTS`sccpdeviceconfig`;
|
|
||||||
DROP TABLE IF EXISTS `sccpbuttonconfig`;
|
|
||||||
DROP TABLE IF EXISTS `sccpdevice`;
|
|
||||||
DROP TABLE IF EXISTS `sccpdevmodel`;
|
|
||||||
DROP TABLE IF EXISTS `sccpline`;
|
|
||||||
DROP TABLE IF EXISTS `sccpsettings`;
|
|
||||||
DROP TABLE IF EXISTS `sccpuser`;
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
echo "done<br>\n";
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in a new issue