MysqlProcessor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A restore() 0 10 2
A backup() 0 12 3
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 $port = 3306;
14
15
    public function backup(): void
16
    {
17
        $mysqldumpPath = $this->module->binaries['mysqldump'];
18
        $gzipPath = $this->module->binaries['gzip'];
19
        $ionicePath = $this->module->binaries['ionice'];
20
        $this->checkBinary($mysqldumpPath);
21
        $this->checkBinary($gzipPath);
22
        $this->checkBinary($ionicePath);
23
        $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}";
24
        (exec($command));
25
        if (!file_exists($this->backupFilePath) || filesize($this->backupFilePath) < 100)
26
            throw new MysqlDumpException();
27
    }
28
29
    public function restore(array $tableNames = []): void
30
    {
31
        $mysqlPath = $this->module->binaries['mysql'];
32
        $zcatPath = $this->module->binaries['zcat'];
33
        $this->checkBinary($zcatPath);
34
        $this->checkBinary($mysqlPath);
35
        $command = "{$zcatPath} {$this->backupFilePath} | {$mysqlPath} -h {$this->host} -P {$this->port} -u {$this->username} -p{$this->password} {$this->database}";
36
        exec($command, $return);
37
        if (!empty($return))
38
            throw new PostgresDumpException();
39
    }
40
}
41