-
Notifications
You must be signed in to change notification settings - Fork 10
/
Restore.php
49 lines (47 loc) · 2.61 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
<?php
namespace FreePBX\modules\Filestore;
use FreePBX\modules\Backup as Base;
class Restore Extends Base\RestoreBase{
private function updateEnabledKeys(&$array) {
foreach ($array as &$value) {
if (is_array($value)) {
$this->updateEnabledKeys($value); // Recursively check nested arrays
} elseif (isset($array['enabled']) && empty($array['enabled'])) {
$array['enabled'] = "yes"; // Set 'enabled' to 'yes' if empty
}
}
}
public function runRestore(){
$settings = $this->getConfigs();
$this->updateEnabledKeys($settings);
$this->importKVStore($settings);
}
public function processLegacy($pdo, $data, $tables, $unknownTables){
$this->log('Restoring only Legacy Backup FTP Servers to Filestore');
$this->RestoreLegacyFtpFilestore($pdo);
}
private function RestoreLegacyFtpFilestore($pdo){
// Check if table exists
$serverTableExists = $this->FreePBX->Filestore->checkTableExists('backup_servers');
$detailsTableExists = $this->FreePBX->Filestore->checkTableExists('backup_server_details');
if ($serverTableExists && $detailsTableExists) {
//backup_server,backup_server_details
$bkserver = "SELECT id,name,desc FROM backup_servers WHERE type='ftp'";
$sth = $pdo->query($bkserver,\PDO::FETCH_ASSOC);
$serversar = $sth->fetchAll();
$tableExists = $this->tableExists($pdo, 'backup_server_details');
if(!empty($serversar) && $tableExists) {
foreach($serversar as $ser){
$server = ['id'=>'','action'=>'add','timeout'=>30,'name'=>$ser['name'],'desc'=>$ser['desc'],'driver'=>'FTP'];
$bkserverd = "SELECT key,value FROM backup_server_details WHERE server_id='".$ser['id']."'";
$sth = $pdo->query($bkserverd,\PDO::FETCH_ASSOC);
$res = $sth->fetchAll();
foreach($res as $row) {
$server[$row['key']] = $row['value'];
}
$this->FreePBX->Filestore->addItem('FTP',$server);
}
}
}
}
}