FolderBackupRestorer::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace floor12\backup\logic;
4
5
use floor12\backup\models\IOPriority;
6
use floor12\backup\Module;
7
use Yii;
8
use yii\base\Exception;
9
10
class FolderBackupRestorer
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $backupFilePath;
16
    /**
17
     * @var string
18
     */
19
    protected $targetFolder;
20
    /**
21
     * @var Module
22
     */
23
    protected $module;
24
    /**
25
     * DatabaseBackupMaker constructor.
26
     * @param string $backupFilePath
27
     * @param string $targetFolder
28
     * @throws Exception
29
     */
30
    public function __construct(string $backupFilePath, string $targetFolder, $io = IOPriority::IDLE)
31
    {
32
        if (!file_exists($backupFilePath))
33
            throw new Exception("Backup file don`t exist..");
34
35
        if (!file_exists($targetFolder))
36
            throw new Exception("Target folder don`t exist.");
37
38
        $this->backupFilePath = $backupFilePath;
39
        $this->targetFolder = $targetFolder;
40
41
        $this->module = Yii::$app->getModule('backup');
42
        $this->io = $io;
0 ignored issues
show
Bug Best Practice introduced by
The property io does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
43
    }
44
45
    /**
46
     * @return bool
47
     * @throws \Exception
48
     */
49
    public function execute()
50
    {
51
        $ionicePath = $this->module->binaries['ionice'];
52
        $unzipPath = $this->module->binaries['unzip'];
53
        $command = "cd {$this->targetFolder} && {$ionicePath} -c{$this->io} {$unzipPath} -o {$this->backupFilePath}";
54
        exec($command, $r);
55
        return true;
56
    }
57
}
58