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

MysqlProcessor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
eloc 20
c 1
b 0
f 1
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A restore() 0 10 2
A backup() 0 12 3
A init() 0 3 2
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