@@ -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 |
@@ -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 |
@@ -93,8 +93,9 @@ discard block |
||
| 93 | 93 | { |
| 94 | 94 | $config_id = Yii::$app->request->post('config_id'); |
| 95 | 95 | |
| 96 | - if (!Yii::$app->getModule('backup')->checkConfig($config_id)) |
|
| 97 | - throw new NotFoundHttpException(Yii::t('app.f12.backup', 'Backup config is not found.')); |
|
| 96 | + if (!Yii::$app->getModule('backup')->checkConfig($config_id)) { |
|
| 97 | + throw new NotFoundHttpException(Yii::t('app.f12.backup', 'Backup config is not found.')); |
|
| 98 | + } |
|
| 98 | 99 | |
| 99 | 100 | Yii::createObject(BackupCreate::class, [$config_id])->run(); |
| 100 | 101 | } |
@@ -127,7 +128,8 @@ discard block |
||
| 127 | 128 | protected function getBackup(int $id) |
| 128 | 129 | { |
| 129 | 130 | $this->model = Backup::findOne($id); |
| 130 | - if (!$this->model) |
|
| 131 | - throw new NotFoundHttpException(Yii::t('app.f12.backup', 'Backup is not found.')); |
|
| 131 | + if (!$this->model) { |
|
| 132 | + throw new NotFoundHttpException(Yii::t('app.f12.backup', 'Backup is not found.')); |
|
| 133 | + } |
|
| 132 | 134 | } |
| 133 | 135 | } |
| 134 | 136 | \ No newline at end of file |
@@ -48,8 +48,9 @@ discard block |
||
| 48 | 48 | public function actionRestore(string $backup_id) |
| 49 | 49 | { |
| 50 | 50 | $model = Backup::findOne((int)$backup_id); |
| 51 | - if (!$model) |
|
| 52 | - throw new ErrorException('Backup not found.'); |
|
| 51 | + if (!$model) { |
|
| 52 | + throw new ErrorException('Backup not found.'); |
|
| 53 | + } |
|
| 53 | 54 | |
| 54 | 55 | Yii::createObject(BackupRestore::class, [$model])->run(); |
| 55 | 56 | $this->stdout('Backup restored.' . PHP_EOL, Console::FG_GREEN); |
@@ -65,13 +66,15 @@ discard block |
||
| 65 | 66 | { |
| 66 | 67 | $models = Backup::find()->orderBy('id DESC')->all(); |
| 67 | 68 | |
| 68 | - if (empty($models)) |
|
| 69 | - return $this->stderr('Backups not found.' . PHP_EOL, Console::FG_YELLOW); |
|
| 69 | + if (empty($models)) { |
|
| 70 | + return $this->stderr('Backups not found.' . PHP_EOL, Console::FG_YELLOW); |
|
| 71 | + } |
|
| 70 | 72 | |
| 71 | - foreach ($models as $model) |
|
| 72 | - $this->stdout("{$model->id}: " . Yii::$app->formatter->asDatetime($model->date) . "\t\t{$model->config_id}\t\t" . |
|
| 73 | + foreach ($models as $model) { |
|
| 74 | + $this->stdout("{$model->id}: " . Yii::$app->formatter->asDatetime($model->date) . "\t\t{$model->config_id}\t\t" . |
|
| 73 | 75 | BackupType::$list[$model->type] . |
| 74 | 76 | PHP_EOL, |
| 75 | 77 | $model->status ? Console::FG_GREEN : Console::FG_RED); |
| 78 | + } |
|
| 76 | 79 | } |
| 77 | 80 | } |
| 78 | 81 | \ No newline at end of file |