-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathRestore.php
61 lines (58 loc) · 2.04 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
<?php
namespace FreePBX\modules\Voicemail;
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();
$nfiles = 0;
foreach($files as $file){
if($file->getType() == 'voicemail' || $file->getType() == 'greeting'){
$filename = $file->getPathTo().'/'.$file->getFilename();
$source = $this->tmpdir.'/files'.$file->getPathTo().'/'.$file->getFilename();
$dest = $filename;
if(file_exists($source)){
@mkdir($file->getPathTo(),0755,true);
copy($source, $dest);
$nfiles++;
}
}
if($file->getType() == 'conf') {
$filename = $file->getPathTo().'/'.$file->getFilename();
$source = $this->tmpdir.'/files'.$file->getPathTo().'/'.$file->getFilename();
$dest = $filename;
if(file_exists($source)){
copy($source, $dest);
}
}
}
$this->log(sprintf(_("%s Files Restored"), $nfiles++),'INFO');
if(isset($configs['tables'])) {
$this->importTables($configs['tables']);
}
}
public function processLegacy($pdo, $data, $tables, $unknownTables) {
$this->restoreLegacyAll($pdo);
$finder = new Finder();
$fileSystem = new Filesystem();
$confdir = $this->FreePBX->Config->get_conf_setting('ASTETCDIR');
if(file_exists($this->tmpdir.'/etc/asterisk/voicemail.conf')) {
$fileSystem->copy($this->tmpdir.'/etc/asterisk/voicemail.conf', $confdir.'/voicemail.conf', true);
}
if(!file_exists($this->tmpdir.'/var/spool/asterisk/voicemail')) {
return;
}
$vmdir = $this->FreePBX->Config->get_conf_setting('ASTSPOOLDIR') . "/voicemail";
exec("rm -Rf ".$vmdir);
foreach ($finder->in($this->tmpdir.'/var/spool/asterisk/voicemail') as $item) {
if($item->isDir()) {
$fileSystem->mkdir($vmdir.'/'.$item->getRelativePathname());
continue;
}
$fileSystem->copy($item->getPathname(), $vmdir.'/'.$item->getRelativePathname(), true);
}
}
}