forked from FreePBX-ContributedModules/endpointman
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRestore.php
66 lines (57 loc) · 2.2 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
<?php
namespace FreePBX\modules\Endpointman;
use FreePBX\modules\Backup as Base;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Component\Finder\Finder;
class Restore Extends Base\RestoreBase{
public function runRestore(){
$configs = $this->getConfigs();
$files = $this->getFiles();
/*
foreach ($configs['data'] as $category) {
$this->FreePBX->Endpointman->addCategoryById($category['id'], $category['category'], $category['type']);
$this->FreePBX->Endpointman->updateCategoryById($category['id'], $category['type'], $category['random'], $category['application'], $category['format']);
}
*/
$this->importAdvancedSettings($config['settings']);
foreach ($files as $file) {
$filename = $file->getPathTo().'/'.$file->getFilename();
if(file_exists($filename)){
continue;
}
copy($this->tmpdir.'/files/'.$file->getPathTo().'/'.$file->getFilename(), $filename);
}
}
public function processLegacy($pdo, $data, $tables, $unknownTables){
$this->restoreLegacyAdvancedSettings($pdo);
if(version_compare_freepbx($this->getVersion(),"13","ge")) {
$this->restoreLegacyDatabase($pdo);
}
else{
}
if(!file_exists($this->tmpdir.'/'.$this->FreePBX->Endpointman->PHONE_MODULES_PATH)) {
return;
}
$endpoint_dir_data = $this->FreePBX->Endpointman->PHONE_MODULES_PATH.'/endpoint';
$endpoint_dir_temp = $this->FreePBX->Endpointman->PHONE_MODULES_PATH.'/temp';
shell_exec("rm -rf $endpoint_dir_data 2>&1");
shell_exec("rm -rf $endpoint_dir_temp 2>&1");
$finder = new Finder();
$fileSystem = new Filesystem();
foreach ($finder->in($this->tmpdir.'/'.$endpoint_dir_data) as $item) {
if($item->isDir()) {
$fileSystem->mkdir($endpoint_dir_data.'/'.$item->getRelativePathname());
continue;
}
$fileSystem->copy($item->getPathname(), $endpoint_dir_data.'/'.$item->getRelativePathname(), true);
}
foreach ($finder->in($this->tmpdir.'/'.$endpoint_dir_temp) as $item) {
if($item->isDir()) {
$fileSystem->mkdir($endpoint_dir_temp.'/'.$item->getRelativePathname());
continue;
}
$fileSystem->copy($item->getPathname(), $endpoint_dir_temp.'/'.$item->getRelativePathname(), true);
}
}
}