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

PostgresProcessor::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\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