-
Notifications
You must be signed in to change notification settings - Fork 19
/
Restore.php
55 lines (50 loc) · 2.09 KB
/
Restore.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace FreePBX\modules\Cdr;
use FreePBX\modules\Backup as Base;
class Restore Extends Base\RestoreBase{
public function runRestore(){
$configs = $this->getConfigs();
$files = $this->getFiles();
$tablename = $this->FreePBX->Config->get('CDRDBTABLENAME') ?: 'cdr';
$dbhandle = $this->FreePBX->Cdr->getCdrDbHandle();
$dbhandle->query("TRUNCATE $tablename");
if(isset($configs['settings'])) {
$this->importAdvancedSettings($configs['settings']);
}
if(isset($config['kvstore'])) {
$this->importKVStore($config['kvstore']);
}
if($this->FreePBX->Config()->get('TRANSIENTCDR')){
$this->FreePBX->Cdr->removeCdrTrigger();
$dumpres = $this->restoreDataFromDump($tablename, $this->tmpdir, $files);
$this->FreePBX->Cdr->createCdrTrigger();
} else {
$dumpres = $this->restoreDataFromDump($tablename, $this->tmpdir, $files);
}
return $dumpres;
}
public function processLegacy($pdo, $data, $tables, $unknownTables){
global $amp_conf;
$cdrname = $this->FreePBX->Config->get('CDRDBNAME') ?: 'asteriskcdrdb';
$tablename = $this->FreePBX->Config->get('CDRDBTABLENAME') ?: 'cdr';
$cdrhost = $this->FreePBX->Config->get('CDRDBHOST') ?: $amp_conf['AMPDBHOST'];
$cdruser = $this->FreePBX->Config->get('CDRDBUSER') ?: $amp_conf['AMPDBUSER'];
$cdrpass = $this->FreePBX->Config->get('CDRDBPASS') ?: $amp_conf['AMPDBPASS'];
$cdrport = $this->FreePBX->Config->get('CDRDBPORT') ?: $amp_conf['AMPDBPORT'];
$cdrport = empty($cdrport) ? '' : ';port=' . $cdrport;
try {
$connection = new \Database('mysql:dbname='.$cdrname.';host='.$cdrhost.$cdrport, $cdruser,$cdrpass);
} catch(\Exception $e) {
return ["status" => false, "message" => $e->getMessage()];
}
$sth = $connection->query("SHOW TABLES");
$res = $sth->fetchAll(\PDO::FETCH_ASSOC);
foreach($res as $loadedTables){
if ($loadedTables['Tables_in_asteriskcdrdb'] == $tablename){
$truncate = "DROP TABLE asteriskcdrdb.".$tablename;
$this->FreePBX->Database->query($truncate);
$loadedTables = $pdo->query("ALTER TABLE asterisktemp.".$tablename." RENAME TO asteriskcdrdb.".$tablename);
}
}
}
}