-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathRestore.php
87 lines (78 loc) · 2.67 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace FreePBX\modules\Userman;
use FreePBX\modules\Backup as Base;
class Restore Extends Base\RestoreBase{
public function runRestore(){
$configs = $this->getConfigs();
if ( array_key_exists('kvstore', $configs) ) { $this->importKVStore($configs['kvstore']); }
if ( array_key_exists('settings', $configs) ) { $this->importAdvancedSettings($configs['settings']); }
if ( array_key_exists('modulexml', $configs) )
{
// Recovery > Email Settings
$this->log(_("Importing Module XML userman"));
$sql = "REPLACE INTO module_xml (`id`, `data`) VALUES('userman_data', ?)";
$sth = $this->FreePBX->Database->prepare($sql);
$sth->execute([json_encode($configs['modulexml'], JSON_THROW_ON_ERROR)]);
}
$this->processData($configs['usermantables']);
}
public function processLegacy($pdo, $data, $tables, $unknownTables){
$version = 14;
if(version_compare_freepbx($this->getVersion(),"13","lt") && version_compare_freepbx($this->getVersion(),"12","gt")) {
$version = 12;
}
if(version_compare_freepbx($this->getVersion(),"12","lt")) {
$version = 10;//super legacy 11,10
}
$defaultDir = false;
if($version < 14) {
$directory = $this->FreePBX->Userman->getDefaultDirectory();
$defaultDir = $directory['id'];
}
$usermandata = $this->FreePBX->Userman->dumpData($pdo,$version);
$this->log(_("Processing Legacy Userman tables"));
$this->processData($usermandata,$defaultDir);
return $this;
}
public function processData($usermantables, $defaultDir = false){
foreach ($usermantables as $table => $datas) {
if ($table == 'userman_directories' || $table == 'userman_users') {
if($defaultDir) {
$addDir = ["auth" => $defaultDir];
$datawithDir = [];
foreach ($datas as $data) {
$datawithDir[] = array_merge($data,$addDir);
}
}
if($defaultDir) {
$this->addDataToTableFromArray($table,$datawithDir);
}
else {
$this->addDataToTableFromArray($table,$datas);
}
}
if ($table == 'userman_groups') {
$cleandata = [];
foreach($datas as $row) {
$row['users'] = stripslashes((string) $row['users']);
$cleandata[] = $row;
}
$this->addDataToTableFromArray($table,$cleandata);
}
if ($table == 'userman_groups_settings' || $table == 'userman_users_settings') {
unset($cleandata);
$cleandata = [];
foreach($datas as $row) {
if ($row['type'] == 'json-arr') {
$row['val'] = stripslashes((string) $row['val']);
}
$cleandata[] = $row;
}
$this->addDataToTableFromArray($table,$cleandata);
}
if ($table == 'userman_template_settings' || $table == 'userman_ucp_templates') {
$this->addDataToTableFromArray($table, $datas);
}
}
}
}