@@ -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; |
@@ -101,8 +101,9 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function actionBackup($config_id) |
103 | 103 | { |
104 | - if (!Yii::$app->getModule('backup')->checkConfig($config_id)) |
|
105 | - throw new NotFoundHttpException(Yii::t('app.f12.backup', 'Backup config is not found.')); |
|
104 | + if (!Yii::$app->getModule('backup')->checkConfig($config_id)) { |
|
105 | + throw new NotFoundHttpException(Yii::t('app.f12.backup', 'Backup config is not found.')); |
|
106 | + } |
|
106 | 107 | |
107 | 108 | Yii::createObject(BackupCreate::class, [$config_id])->run(); |
108 | 109 | |
@@ -138,8 +139,9 @@ discard block |
||
138 | 139 | protected function getBackup(int $id) |
139 | 140 | { |
140 | 141 | $this->model = Backup::findOne($id); |
141 | - if (!$this->model) |
|
142 | - throw new NotFoundHttpException(Yii::t('app.f12.backup', 'Backup is not found.')); |
|
142 | + if (!$this->model) { |
|
143 | + throw new NotFoundHttpException(Yii::t('app.f12.backup', 'Backup is not found.')); |
|
144 | + } |
|
143 | 145 | } |
144 | 146 | |
145 | 147 | /** |
@@ -150,8 +152,9 @@ discard block |
||
150 | 152 | { |
151 | 153 | $headers = Yii::$app->request->getHeaders(); |
152 | 154 | $authTokens = Yii::$app->getModule('backup')->authTokens; |
153 | - if (!empty($headers[self::HEADER_NAME]) && in_array($headers[self::HEADER_NAME], $authTokens)) |
|
154 | - return true; |
|
155 | + if (!empty($headers[self::HEADER_NAME]) && in_array($headers[self::HEADER_NAME], $authTokens)) { |
|
156 | + return true; |
|
157 | + } |
|
155 | 158 | throw new ForbiddenHttpException(); |
156 | 159 | } |
157 | 160 |
@@ -101,8 +101,9 @@ |
||
101 | 101 | { |
102 | 102 | $config_id = 'backup_test_folder'; |
103 | 103 | $creator = new BackupCreate($config_id); |
104 | - for ($i = 0; $i < 5; $i++) |
|
105 | - $creator->run(); |
|
104 | + for ($i = 0; $i < 5; $i++) { |
|
105 | + $creator->run(); |
|
106 | + } |
|
106 | 107 | } |
107 | 108 | |
108 | 109 |
@@ -81,14 +81,16 @@ discard block |
||
81 | 81 | $this->backupRootPath = Yii::getAlias($this->backupFolder); |
82 | 82 | |
83 | 83 | try { |
84 | - if (!file_exists($this->backupRootPath)) |
|
85 | - mkdir($this->backupRootPath); |
|
84 | + if (!file_exists($this->backupRootPath)) { |
|
85 | + mkdir($this->backupRootPath); |
|
86 | + } |
|
86 | 87 | } catch (ErrorException $e) { |
87 | 88 | throw new ErrorException("Backup folder not exists. Its impossible to create it because of permission error."); |
88 | 89 | } |
89 | 90 | |
90 | - if (!is_writable($this->backupRootPath)) |
|
91 | - throw new ErrorException("Backup folder is not writable."); |
|
91 | + if (!is_writable($this->backupRootPath)) { |
|
92 | + throw new ErrorException("Backup folder is not writable."); |
|
93 | + } |
|
92 | 94 | |
93 | 95 | $this->checkSqliteDb(); |
94 | 96 | $this->registerTranslations(); |
@@ -129,9 +131,10 @@ discard block |
||
129 | 131 | */ |
130 | 132 | public function checkConfig(string $config_id) |
131 | 133 | { |
132 | - foreach (Yii::$app->getModule('backup')->configs as $config) |
|
133 | - if ($config['id'] == $config_id) |
|
134 | + foreach (Yii::$app->getModule('backup')->configs as $config) { |
|
135 | + if ($config['id'] == $config_id) |
|
134 | 136 | return true; |
137 | + } |
|
135 | 138 | return false; |
136 | 139 | } |
137 | 140 |
@@ -47,8 +47,9 @@ |
||
47 | 47 | */ |
48 | 48 | public function backup() |
49 | 49 | { |
50 | - if (file_exists($this->backupFilePath)) |
|
51 | - throw new Exception("Backup file exists."); |
|
50 | + if (file_exists($this->backupFilePath)) { |
|
51 | + throw new Exception("Backup file exists."); |
|
52 | + } |
|
52 | 53 | $this->dbProcessor->backup(); |
53 | 54 | } |
54 | 55 |
@@ -25,11 +25,13 @@ |
||
25 | 25 | */ |
26 | 26 | public function __construct(string $backupFilePath, string $targetFolder, $io = IOPriority::IDLE) |
27 | 27 | { |
28 | - if (!file_exists($backupFilePath)) |
|
29 | - throw new Exception("Backup file don`t exist.."); |
|
28 | + if (!file_exists($backupFilePath)) { |
|
29 | + throw new Exception("Backup file don`t exist.."); |
|
30 | + } |
|
30 | 31 | |
31 | - if (!file_exists($targetFolder)) |
|
32 | - throw new Exception("Target folder don`t exist."); |
|
32 | + if (!file_exists($targetFolder)) { |
|
33 | + throw new Exception("Target folder don`t exist."); |
|
34 | + } |
|
33 | 35 | |
34 | 36 | $this->backupFilePath = $backupFilePath; |
35 | 37 | $this->targetFolder = $targetFolder; |
@@ -99,7 +99,7 @@ |
||
99 | 99 | $targetPath = Yii::getAlias($this->currentConfig['path']); |
100 | 100 | Yii::createObject(FolderBackupMaker::class, [$this->model->getFullPath(), $targetPath, $this->currentConfig['io']])->execute(); |
101 | 101 | } |
102 | - } catch (MysqlDumpException|PostgresDumpException|FolderDumpException $exception) { |
|
102 | + } catch (MysqlDumpException | PostgresDumpException | FolderDumpException $exception) { |
|
103 | 103 | $this->setBackupFailed(); |
104 | 104 | throw new $exception; |
105 | 105 | } |
@@ -61,8 +61,9 @@ discard block |
||
61 | 61 | protected function loadConfigs() |
62 | 62 | { |
63 | 63 | $this->configs = Yii::$app->getModule('backup')->configs; |
64 | - if (!is_array($this->configs) || !sizeof($this->configs)) |
|
65 | - throw new ModuleNotConfiguredException('Backup configs is empty'); |
|
64 | + if (!is_array($this->configs) || !sizeof($this->configs)) { |
|
65 | + throw new ModuleNotConfiguredException('Backup configs is empty'); |
|
66 | + } |
|
66 | 67 | } |
67 | 68 | |
68 | 69 | /** |
@@ -71,8 +72,9 @@ discard block |
||
71 | 72 | */ |
72 | 73 | protected function setUpActiveConfig() |
73 | 74 | { |
74 | - if (!is_array($this->configs[$this->config_id])) |
|
75 | - throw new ConfigurationNotFoundException("Configuration `{$this->config_id}` not found."); |
|
75 | + if (!is_array($this->configs[$this->config_id])) { |
|
76 | + throw new ConfigurationNotFoundException("Configuration `{$this->config_id}` not found."); |
|
77 | + } |
|
76 | 78 | $this->currentConfig = $this->configs[$this->config_id]; |
77 | 79 | } |
78 | 80 | |
@@ -87,8 +89,9 @@ discard block |
||
87 | 89 | $this->deleteOldFiles(); |
88 | 90 | $this->createBackupItem(); |
89 | 91 | |
90 | - if (empty($this->currentConfig['io'])) |
|
91 | - $this->currentConfig['io'] = IOPriority::IDLE; |
|
92 | + if (empty($this->currentConfig['io'])) { |
|
93 | + $this->currentConfig['io'] = IOPriority::IDLE; |
|
94 | + } |
|
92 | 95 | try { |
93 | 96 | if ($this->currentConfig['type'] == BackupType::DB) { |
94 | 97 | $connection = Yii::$app->{$this->currentConfig['connection']}; |
@@ -114,17 +117,19 @@ discard block |
||
114 | 117 | */ |
115 | 118 | protected function deleteOldFiles() |
116 | 119 | { |
117 | - if (!isset($this->currentConfig['limit']) || empty($this->currentConfig['limit'])) |
|
118 | - return false; |
|
120 | + if (!isset($this->currentConfig['limit']) || empty($this->currentConfig['limit'])) { |
|
121 | + return false; |
|
122 | + } |
|
119 | 123 | $backups = Backup::find() |
120 | 124 | ->where(['config_id' => $this->config_id]) |
121 | 125 | ->orderBy('date DESC') |
122 | 126 | ->offset($this->currentConfig['limit'] - 1) |
123 | 127 | ->all(); |
124 | 128 | |
125 | - if ($backups) |
|
126 | - foreach ($backups as $backup) |
|
129 | + if ($backups) { |
|
130 | + foreach ($backups as $backup) |
|
127 | 131 | $backup->delete(); |
132 | + } |
|
128 | 133 | } |
129 | 134 | |
130 | 135 | /** |
@@ -152,8 +157,9 @@ discard block |
||
152 | 157 | $extension = Backup::EXT_TGZ; |
153 | 158 | /** @var Connection $connection */ |
154 | 159 | $connection = Yii::$app->{$this->currentConfig['connection']}; |
155 | - if ($connection->driverName == 'pgsql') |
|
156 | - $extension = Backup::EXT_DUMP; |
|
160 | + if ($connection->driverName == 'pgsql') { |
|
161 | + $extension = Backup::EXT_DUMP; |
|
162 | + } |
|
157 | 163 | } |
158 | 164 | $date = date("Y-m-d_H-i-s"); |
159 | 165 | $rand = substr(md5(rand(0, 9999)), 0, 3); |
@@ -32,8 +32,9 @@ |
||
32 | 32 | */ |
33 | 33 | public function __construct(string $backupFilePath, Connection $connection) |
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 | 39 | $currentProcessorClassname = $this->dbProcessors[$connection->driverName]; |
39 | 40 | $this->dbProcessor = new $currentProcessorClassname($backupFilePath, $connection); |