@@ -66,8 +66,9 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function getFullPath() |
68 | 68 | { |
69 | - if (!$this->filename) |
|
70 | - return; |
|
69 | + if (!$this->filename) { |
|
70 | + return; |
|
71 | + } |
|
71 | 72 | return Yii::$app->getModule('backup')->backupRootPath . DIRECTORY_SEPARATOR . $this->filename; |
72 | 73 | } |
73 | 74 | |
@@ -78,8 +79,9 @@ discard block |
||
78 | 79 | public function updateFileSize() |
79 | 80 | { |
80 | 81 | $this->size = 0; |
81 | - if (file_exists($this->getFullPath())) |
|
82 | - $this->size = filesize($this->getFullPath()); |
|
82 | + if (file_exists($this->getFullPath())) { |
|
83 | + $this->size = filesize($this->getFullPath()); |
|
84 | + } |
|
83 | 85 | } |
84 | 86 | |
85 | 87 | /** |
@@ -72,12 +72,12 @@ discard block |
||
72 | 72 | 'filename', |
73 | 73 | [ |
74 | 74 | 'attribute' => 'status', |
75 | - 'content' => function (Backup $model) { |
|
75 | + 'content' => function(Backup $model) { |
|
76 | 76 | return BackupStatus::getLabel($model->status); |
77 | 77 | } |
78 | 78 | ], |
79 | 79 | [ |
80 | - 'content' => function (Backup $model) { |
|
80 | + 'content' => function(Backup $model) { |
|
81 | 81 | $html = ' '; |
82 | 82 | if (file_exists($model->getFullPath())) |
83 | 83 | $html .= Html::tag('span', IconHelper::CHECK, ['title' => 'Файл найден', 'style' => 'color:#38b704;']); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | 'size:size', |
99 | 99 | [ |
100 | 100 | 'contentOptions' => ['class' => 'text-right'], |
101 | - 'content' => function (Backup $model) { |
|
101 | + 'content' => function(Backup $model) { |
|
102 | 102 | $html = Html::a(IconHelper::PLAY, null, [ |
103 | 103 | 'class' => 'btn btn-default btn-sm', |
104 | 104 | 'title' => Yii::t('app.f12.backup', 'Restore'), |
@@ -79,17 +79,19 @@ |
||
79 | 79 | [ |
80 | 80 | 'content' => function (Backup $model) { |
81 | 81 | $html = ' '; |
82 | - if (file_exists($model->getFullPath())) |
|
83 | - $html .= Html::tag('span', IconHelper::CHECK, ['title' => 'Файл найден', 'style' => 'color:#38b704;']); |
|
84 | - else |
|
85 | - $html .= Html::tag('span', IconHelper::EXCLAMATION, ['title' => 'Файл не найден', 'style' => 'color:#eca70b;']); |
|
82 | + if (file_exists($model->getFullPath())) { |
|
83 | + $html .= Html::tag('span', IconHelper::CHECK, ['title' => 'Файл найден', 'style' => 'color:#38b704;']); |
|
84 | + } else { |
|
85 | + $html .= Html::tag('span', IconHelper::EXCLAMATION, ['title' => 'Файл не найден', 'style' => 'color:#eca70b;']); |
|
86 | + } |
|
86 | 87 | |
87 | 88 | $html .= ' '; |
88 | 89 | |
89 | - if (is_writable($model->getFullPath())) |
|
90 | - $html .= Html::tag('span', IconHelper::CHECK, ['title' => 'Права на запись найден', 'style' => 'color:#38b704;']); |
|
91 | - else |
|
92 | - $html .= Html::tag('span', IconHelper::EXCLAMATION, ['title' => 'Нет прав на запись', 'style' => 'color:#eca70b;']); |
|
90 | + if (is_writable($model->getFullPath())) { |
|
91 | + $html .= Html::tag('span', IconHelper::CHECK, ['title' => 'Права на запись найден', 'style' => 'color:#38b704;']); |
|
92 | + } else { |
|
93 | + $html .= Html::tag('span', IconHelper::EXCLAMATION, ['title' => 'Нет прав на запись', 'style' => 'color:#eca70b;']); |
|
94 | + } |
|
93 | 95 | |
94 | 96 | |
95 | 97 | return $html; |
@@ -31,8 +31,9 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function __construct(string $backupFilePath, Connection $connection) |
33 | 33 | { |
34 | - if (!file_exists($backupFilePath)) |
|
35 | - throw new Exception("Backup file don`t exist."); |
|
34 | + if (!file_exists($backupFilePath)) { |
|
35 | + throw new Exception("Backup file don`t exist."); |
|
36 | + } |
|
36 | 37 | |
37 | 38 | $this->backupFilePath = $backupFilePath; |
38 | 39 | $this->connection = $connection; |
@@ -53,8 +54,9 @@ discard block |
||
53 | 54 | $lines = gzfile($this->backupFilePath); |
54 | 55 | |
55 | 56 | foreach ($lines as $line) { |
56 | - if (substr($line, 0, 2) == '--' || $line == '') |
|
57 | - continue; |
|
57 | + if (substr($line, 0, 2) == '--' || $line == '') { |
|
58 | + continue; |
|
59 | + } |
|
58 | 60 | $this->sql .= $line; |
59 | 61 | if (substr(trim($line), -1, 1) == ';') { |
60 | 62 | $this->connection->createCommand($this->sql)->execute(); |
@@ -32,11 +32,13 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function __construct(string $backupFilePath, string $targetFolder) |
34 | 34 | { |
35 | - if (file_exists($backupFilePath)) |
|
36 | - throw new Exception("Backup file exists."); |
|
35 | + if (file_exists($backupFilePath)) { |
|
36 | + throw new Exception("Backup file exists."); |
|
37 | + } |
|
37 | 38 | |
38 | - if (!file_exists($targetFolder)) |
|
39 | - throw new Exception("Target folder not exists."); |
|
39 | + if (!file_exists($targetFolder)) { |
|
40 | + throw new Exception("Target folder not exists."); |
|
41 | + } |
|
40 | 42 | |
41 | 43 | $this->backupFilePath = $backupFilePath; |
42 | 44 | $this->targetFolder = $targetFolder; |
@@ -50,13 +52,15 @@ discard block |
||
50 | 52 | */ |
51 | 53 | public function execute() |
52 | 54 | { |
53 | - if ($this->ionice) |
|
54 | - exec(" cd {$this->targetFolder} && " . $this->ionice . " zip -r -0 {$this->backupFilePath} *"); |
|
55 | - else |
|
56 | - exec("cd {$this->targetFolder} && zip -r -0 {$this->backupFilePath} *", $tmo); |
|
55 | + if ($this->ionice) { |
|
56 | + exec(" cd {$this->targetFolder} && " . $this->ionice . " zip -r -0 {$this->backupFilePath} *"); |
|
57 | + } else { |
|
58 | + exec("cd {$this->targetFolder} && zip -r -0 {$this->backupFilePath} *", $tmo); |
|
59 | + } |
|
57 | 60 | |
58 | - if ($this->chmod) |
|
59 | - chmod($this->backupFilePath, $this->chmod); |
|
61 | + if ($this->chmod) { |
|
62 | + chmod($this->backupFilePath, $this->chmod); |
|
63 | + } |
|
60 | 64 | return true; |
61 | 65 | } |
62 | 66 | } |
63 | 67 | \ No newline at end of file |
@@ -42,16 +42,19 @@ |
||
42 | 42 | { |
43 | 43 | $this->_configs = Yii::$app->getModule('backup')->configs; |
44 | 44 | |
45 | - if (!is_array($this->_configs) || !sizeof($this->_configs)) |
|
46 | - throw new InvalidConfigException('Backup module need to be configured with `config array`'); |
|
45 | + if (!is_array($this->_configs) || !sizeof($this->_configs)) { |
|
46 | + throw new InvalidConfigException('Backup module need to be configured with `config array`'); |
|
47 | + } |
|
47 | 48 | |
48 | 49 | foreach ($this->_configs as $config) { |
49 | - if (isset($config['id']) && $config['id'] == $model->config_id) |
|
50 | - $this->_currentConfig = $config; |
|
50 | + if (isset($config['id']) && $config['id'] == $model->config_id) { |
|
51 | + $this->_currentConfig = $config; |
|
52 | + } |
|
51 | 53 | } |
52 | 54 | |
53 | - if (!$this->_currentConfig) |
|
54 | - throw new \ErrorException("Config `{$model->config_id}` not found."); |
|
55 | + if (!$this->_currentConfig) { |
|
56 | + throw new \ErrorException("Config `{$model->config_id}` not found."); |
|
57 | + } |
|
55 | 58 | |
56 | 59 | $this->_model = $model; |
57 | 60 | $this->backupFilePath = Yii::getAlias(Yii::$app->getModule('backup')->backupFolder . DIRECTORY_SEPARATOR . $this->_model->filename); |
@@ -51,8 +51,7 @@ |
||
51 | 51 | */ |
52 | 52 | public function execute() |
53 | 53 | { |
54 | - $this->dumper = new $this->dumperClass |
|
55 | - ( |
|
54 | + $this->dumper = new $this->dumperClass( |
|
56 | 55 | $this->connection->dsn, |
57 | 56 | $this->connection->username, |
58 | 57 | $this->connection->password, |
@@ -37,8 +37,9 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function __construct(string $backupFilePath, Connection $connection, string $dumperClass = Mysqldump::class) |
39 | 39 | { |
40 | - if (file_exists($backupFilePath)) |
|
41 | - throw new Exception("Backup file exists."); |
|
40 | + if (file_exists($backupFilePath)) { |
|
41 | + throw new Exception("Backup file exists."); |
|
42 | + } |
|
42 | 43 | |
43 | 44 | $this->backupFilePath = $backupFilePath; |
44 | 45 | $this->connection = $connection; |
@@ -59,8 +60,9 @@ discard block |
||
59 | 60 | ['compress' => Mysqldump::GZIP] |
60 | 61 | ); |
61 | 62 | $this->dumper->start($this->backupFilePath); |
62 | - if (Yii::$app->getModule('backup')->chmod) |
|
63 | - chmod($this->backupFilePath, Yii::$app->getModule('backup')->chmod); |
|
63 | + if (Yii::$app->getModule('backup')->chmod) { |
|
64 | + chmod($this->backupFilePath, Yii::$app->getModule('backup')->chmod); |
|
65 | + } |
|
64 | 66 | return true; |
65 | 67 | } |
66 | 68 | } |
67 | 69 | \ No newline at end of file |
@@ -23,11 +23,13 @@ |
||
23 | 23 | */ |
24 | 24 | public function __construct(string $backupFilePath, string $targetFolder) |
25 | 25 | { |
26 | - if (!file_exists($backupFilePath)) |
|
27 | - throw new Exception("Backup file don`t exist.."); |
|
26 | + if (!file_exists($backupFilePath)) { |
|
27 | + throw new Exception("Backup file don`t exist.."); |
|
28 | + } |
|
28 | 29 | |
29 | - if (!file_exists($targetFolder)) |
|
30 | - throw new Exception("Target folder don`t exist."); |
|
30 | + if (!file_exists($targetFolder)) { |
|
31 | + throw new Exception("Target folder don`t exist."); |
|
32 | + } |
|
31 | 33 | |
32 | 34 | $this->backupFilePath = $backupFilePath; |
33 | 35 | $this->targetFolder = $targetFolder; |
@@ -47,16 +47,19 @@ discard block |
||
47 | 47 | $this->dumperClass = $dumperClass; |
48 | 48 | $this->configs = Yii::$app->getModule('backup')->configs; |
49 | 49 | |
50 | - if (!is_array($this->configs) || !sizeof($this->configs)) |
|
51 | - throw new InvalidConfigExceptionAlias('Backup module need to be configured with `config array`'); |
|
50 | + if (!is_array($this->configs) || !sizeof($this->configs)) { |
|
51 | + throw new InvalidConfigExceptionAlias('Backup module need to be configured with `config array`'); |
|
52 | + } |
|
52 | 53 | |
53 | 54 | foreach ($this->configs as $config) { |
54 | - if (isset($config['id']) && $config['id'] == $config_id) |
|
55 | - $this->currentConfig = $config; |
|
55 | + if (isset($config['id']) && $config['id'] == $config_id) { |
|
56 | + $this->currentConfig = $config; |
|
57 | + } |
|
56 | 58 | } |
57 | 59 | |
58 | - if (!$this->currentConfig) |
|
59 | - throw new InvalidConfigExceptionAlias("Config `{$config_id}` not found."); |
|
60 | + if (!$this->currentConfig) { |
|
61 | + throw new InvalidConfigExceptionAlias("Config `{$config_id}` not found."); |
|
62 | + } |
|
60 | 63 | } |
61 | 64 | |
62 | 65 | /** |
@@ -116,8 +119,9 @@ discard block |
||
116 | 119 | */ |
117 | 120 | protected function deleteOldFiles() |
118 | 121 | { |
119 | - if (!isset($this->currentConfig['limit']) || empty($this->currentConfig['limit'])) |
|
120 | - return false; |
|
122 | + if (!isset($this->currentConfig['limit']) || empty($this->currentConfig['limit'])) { |
|
123 | + return false; |
|
124 | + } |
|
121 | 125 | |
122 | 126 | $backups = Backup::find() |
123 | 127 | ->where(['config_id' => $this->currentConfig['id']]) |
@@ -125,9 +129,10 @@ discard block |
||
125 | 129 | ->offset($this->currentConfig['limit']) |
126 | 130 | ->all(); |
127 | 131 | |
128 | - if ($backups) |
|
129 | - foreach ($backups as $backup) |
|
132 | + if ($backups) { |
|
133 | + foreach ($backups as $backup) |
|
130 | 134 | $backup->delete(); |
135 | + } |
|
131 | 136 | } |
132 | 137 | |
133 | 138 | /** Generate filename |
@@ -66,14 +66,16 @@ discard block |
||
66 | 66 | $this->backupRootPath = Yii::getAlias($this->backupFolder); |
67 | 67 | |
68 | 68 | try { |
69 | - if (!file_exists($this->backupRootPath)) |
|
70 | - mkdir($this->backupRootPath); |
|
69 | + if (!file_exists($this->backupRootPath)) { |
|
70 | + mkdir($this->backupRootPath); |
|
71 | + } |
|
71 | 72 | } catch (ErrorException $e) { |
72 | 73 | throw new ErrorException("Backup folder not exists. Its impossible to create it because of permission error."); |
73 | 74 | } |
74 | 75 | |
75 | - if (!is_writable($this->backupRootPath)) |
|
76 | - throw new ErrorException("Backup folder is not writeble."); |
|
76 | + if (!is_writable($this->backupRootPath)) { |
|
77 | + throw new ErrorException("Backup folder is not writeble."); |
|
78 | + } |
|
77 | 79 | |
78 | 80 | $this->checkDb(); |
79 | 81 | $this->registerTranslations(); |
@@ -85,9 +87,10 @@ discard block |
||
85 | 87 | */ |
86 | 88 | public function checkConfig(string $config_id) |
87 | 89 | { |
88 | - foreach (Yii::$app->getModule('backup')->configs as $config) |
|
89 | - if ($config['id'] == $config_id) |
|
90 | + foreach (Yii::$app->getModule('backup')->configs as $config) { |
|
91 | + if ($config['id'] == $config_id) |
|
90 | 92 | return true; |
93 | + } |
|
91 | 94 | return false; |
92 | 95 | } |
93 | 96 |