Issues (81)

src/logic/FolderBackupMaker.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace floor12\backup\logic;
4
5
use floor12\backup\Exceptions\FolderDumpException;
6
use floor12\backup\models\IOPriority;
7
use floor12\backup\Module;
8
use Yii;
9
use yii\base\Exception;
10
11
class FolderBackupMaker
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $backupFilePath;
17
    /**
18
     * @var string
19
     */
20
    protected $targetFolder;
21
    /**
22
     * @var string
23
     */
24
    protected $io;
25
    /**
26
     * @var Module
27
     */
28
    protected $module;
29
30
    /**
31
     * DatabaseBackupMaker constructor.
32
     * @param string $backupFilePath
33
     * @param string $targetFolder
34
     * @throws Exception
35
     */
36
    public function __construct(string $backupFilePath, string $targetFolder, $io = IOPriority::IDLE)
37
    {
38
        if (file_exists($backupFilePath))
39
            throw new Exception("Backup file exists.");
40
41
        if (!file_exists($targetFolder))
42
            throw new Exception("Target folder not exists.");
43
44
        $this->module = Yii::$app->getModule('backup');
45
        $this->backupFilePath = $backupFilePath;
46
        $this->targetFolder = $targetFolder;
47
        $this->io = $io;
48
    }
49
50
    /**
51
     * @return bool
52
     * @throws \Exception
53
     * @throws FolderDumpException
54
     */
55
    public function execute()
56
    {
57
        $ionicePath = $this->module->binaries['ionice'];
58
        $zipPath = $this->module->binaries['zip'];
59
        $command = "cd {$this->targetFolder} && {$ionicePath} -c{$this->io} {$zipPath} -r -0 {$this->backupFilePath} * > /dev/null";
60
        exec($command);
61
        if (!file_exists($this->backupFilePath))
62
            throw new FolderDumpException();
63
64
        if ($this->module->chmod)
65
            chmod($this->backupFilePath, $this->module->chmod);
0 ignored issues
show
$this->module->chmod of type string is incompatible with the type integer expected by parameter $permissions of chmod(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
            chmod($this->backupFilePath, /** @scrutinizer ignore-type */ $this->module->chmod);
Loading history...
66
67
        return true;
68
    }
69
}
70