PostgresProcessor::init()   A
last analyzed

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
10
    extends DbProcessor
11
    implements DbProcessorInterface
12
{
13
14
    public $port = 5432;
15
16
    public function backup(): void
17
    {
18
        $binaryPath = $this->module->binaries['pg_dump'];
19
        $ionicePath = $this->module->binaries['ionice'];
20
        $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}";
21
        exec($command, $return);
22
        if (!empty($return))
23
            throw new PostgresDumpException();
24
    }
25
26
    public function restore(array $tableNames = []): void
27
    {
28
        $binaryPath = $this->module->binaries['pg_restore'];
29
        $command = "PGPASSWORD='{$this->password}' {$binaryPath} -c -Fc -j 4 -h {$this->host} -p {$this->port} -U {$this->username}  -d {$this->database} {$this->backupFilePath}";
30
        exec($command, $return);
31
        if (!empty($return))
32
            throw new PostgresDumpException();
33
    }
34
35
    public function init()
36
    {
37
        $this->port = $this->port ?: 5432;
38
    }
39
}
40