|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace floor12\backup\logic\processors; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use floor12\backup\Exceptions\BinaryNotFoundException; |
|
|
|
|
|
|
8
|
|
|
use floor12\backup\Exceptions\DsnParseException; |
|
9
|
|
|
use floor12\backup\models\IOPriority; |
|
10
|
|
|
use floor12\backup\Module; |
|
11
|
|
|
use Yii; |
|
12
|
|
|
use yii\db\Connection; |
|
13
|
|
|
|
|
14
|
|
|
abstract class DbProcessor |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var Connection |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $connection; |
|
20
|
|
|
/** |
|
21
|
|
|
* @var array |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $parsedDsn; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $backupFilePath; |
|
28
|
|
|
/** |
|
29
|
|
|
* @var Module |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $module; |
|
32
|
|
|
protected $username; |
|
33
|
|
|
protected $database; |
|
34
|
|
|
protected $host; |
|
35
|
|
|
protected $port; |
|
36
|
|
|
protected $io; |
|
37
|
|
|
protected $password; |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* DbProcessor constructor. |
|
42
|
|
|
* @param string $backupFilePath |
|
43
|
|
|
* @param Connection $connection |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct(string $backupFilePath, Connection $connection, $io = IOPriority::IDLE) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->parseDsn($connection->dsn); |
|
48
|
|
|
$this->backupFilePath = $backupFilePath; |
|
49
|
|
|
$this->username = $connection->username; |
|
50
|
|
|
$this->password = $connection->password; |
|
51
|
|
|
$this->module = Yii::$app->getModule('backup'); |
|
52
|
|
|
$this->io = $io; |
|
53
|
|
|
$this->init(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
protected function parseDsn(string $dsn) |
|
57
|
|
|
{ |
|
58
|
|
|
$dsn = substr($dsn, strpos($dsn, ':') + 1); |
|
59
|
|
|
$dsnParts = explode(';', $dsn); |
|
60
|
|
|
|
|
61
|
|
|
if (empty($dsnParts)) |
|
62
|
|
|
throw new DsnParseException(); |
|
63
|
|
|
|
|
64
|
|
|
foreach ($dsnParts as $part) { |
|
65
|
|
|
$row = explode('=', $part); |
|
66
|
|
|
if (isset($row[0]) && isset($row[1])) |
|
67
|
|
|
$this->parsedDsn[$row[0]] = $row[1]; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$this->host = $this->parsedDsn['host'] ?: null; |
|
71
|
|
|
$this->port = !empty($this->parsedDsn['port']) ? $this->parsedDsn['port'] : null; |
|
72
|
|
|
$this->database = $this->parsedDsn['dbname'] ?: null; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
protected function checkBinary(string $binary) |
|
76
|
|
|
{ |
|
77
|
|
|
if (!file_exists($binary) || !is_executable($binary)) |
|
78
|
|
|
throw new BinaryNotFoundException($binary); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function backup() |
|
82
|
|
|
{ |
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function restore() |
|
87
|
|
|
{ |
|
88
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function init() |
|
92
|
|
|
{ |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths