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

PostgresProcessor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 13
c 1
b 0
f 1
dl 0
loc 25
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A backup() 0 8 2
A restore() 0 7 2
A init() 0 3 2
1
<?php
2
3
4
namespace floor12\backup\logic\processors;
5
6
7
use floor12\backup\Exceptions\PostgresDumpException;
8
9
class PostgresProcessor extends DbProcessor
10
{
11
12
    public function backup()
13
    {
14
        $binaryPath = $this->module->binaries['pg_dump'];
15
        $ionicePath = $this->module->binaries['ionice'];
16
        $command = "PGPASSWORD='{$this->password}' {$ionicePath} -c{$this->io} {$binaryPath} -h {$this->host} -p {$this->port} -U {$this->username} -Fc -Z1 {$this->database} -f {$this->backupFilePath}";
17
        exec($command, $return);
18
        if (!empty($return))
19
            throw new PostgresDumpException();
20
    }
21
22
    public function restore()
23
    {
24
        $binaryPath = $this->module->binaries['pg_restore'];
25
        $command = "PGPASSWORD='{$this->password}' {$binaryPath} -c -Fc -j 4 -h {$this->host} -p {$this->port} -U {$this->username}  -d {$this->database} {$this->backupFilePath}";
26
        exec($command, $return);
27
        if (!empty($return))
28
            throw new PostgresDumpException();
29
    }
30
31
    public function init()
32
    {
33
        $this->port = $this->port ?: 5432;
34
    }
35
}
36