Test Failed
Push — master ( eaa667...0d9623 )
by Evgenii
38:52
created

MysqlProcessor::init()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 1
nop 0
1
<?php
2
3
4
namespace floor12\backup\logic\processors;
5
6
7
use floor12\backup\Exceptions\MysqlDumpException;
8
use floor12\backup\Exceptions\PostgresDumpException;
9
10
class MysqlProcessor extends DbProcessor
11
{
12
13
    public function init()
14
    {
15
        $this->port = $this->port ?: 3306;
16
    }
17
18
    public function backup()
19
    {
20
        $mysqldumpPath = $this->module->binaries['mysqldump'];
21
        $gzipPath = $this->module->binaries['gzip'];
22
        $ionicePath = $this->module->binaries['ionice'];
23
        $this->checkBinary($mysqldumpPath);
24
        $this->checkBinary($gzipPath);
25
        $this->checkBinary($ionicePath);
26
        $command = "{$ionicePath} -c{$this->io} {$mysqldumpPath} -h {$this->host} -P {$this->port} -u {$this->username}  -p{$this->password}  {$this->database} | {$gzipPath} -9 -c > {$this->backupFilePath}";
27
        (exec($command));
28
        if (!file_exists($this->backupFilePath) || filesize($this->backupFilePath) < 100)
29
            throw new MysqlDumpException();
30
    }
31
32
    public function restore()
33
    {
34
        $mysqlPath = $this->module->binaries['mysql'];
35
        $zcatPath = $this->module->binaries['zcat'];
36
        $this->checkBinary($zcatPath);
37
        $this->checkBinary($mysqlPath);
38
        $command = "{$zcatPath} {$this->backupFilePath} | {$mysqlPath} -h {$this->host} -P {$this->port} -u {$this->username} -p{$this->password} {$this->database}";
39
        exec($command, $return);
40
        if (!empty($return))
41
            throw new PostgresDumpException();
42
    }
43
}
44