1 | <?php |
||||
2 | /** |
||||
3 | * Created by PhpStorm. |
||||
4 | * User: floor12 |
||||
5 | * Date: 17.09.2018 |
||||
6 | * Time: 23:10 |
||||
7 | */ |
||||
8 | |||||
9 | namespace floor12\backup\models; |
||||
10 | |||||
11 | |||||
12 | use Yii; |
||||
13 | use yii\db\ActiveRecord; |
||||
14 | |||||
15 | /** |
||||
16 | * Class Backup |
||||
17 | * @package floor12\backup\models |
||||
18 | * @property integer $id |
||||
19 | * @property integer $status |
||||
20 | * @property integer $type |
||||
21 | * @property integer $size |
||||
22 | * @property string $config_id |
||||
23 | * @property string $config_name |
||||
24 | * @property string $date |
||||
25 | * @property string $filename |
||||
26 | * @property string $fullPath |
||||
27 | */ |
||||
28 | class Backup extends ActiveRecord |
||||
29 | { |
||||
30 | |||||
31 | const EXT_DUMP = 'dump'; |
||||
32 | const EXT_TGZ = 'gz'; |
||||
33 | const EXT_ZIP = 'zip'; |
||||
34 | |||||
35 | public static function getDb() |
||||
36 | { |
||||
37 | return Yii::$app->getModule('backup')->connection; |
||||
38 | } |
||||
39 | |||||
40 | /** |
||||
41 | * @inheritdoc |
||||
42 | */ |
||||
43 | public static function tableName() |
||||
44 | { |
||||
45 | return 'backup'; |
||||
46 | } |
||||
47 | |||||
48 | /** |
||||
49 | * @inheritdoc |
||||
50 | */ |
||||
51 | public function attributeLabels() |
||||
52 | { |
||||
53 | return [ |
||||
54 | 'date' => Yii::t('app.f12.backup', 'Date'), |
||||
55 | 'config_id' => Yii::t('app.f12.backup', 'Config'), |
||||
56 | 'type' => Yii::t('app.f12.backup', 'Backup type'), |
||||
57 | 'filename' => Yii::t('app.f12.backup', 'File name'), |
||||
58 | 'config_name' => Yii::t('app.f12.backup', 'Config name'), |
||||
59 | 'size' => Yii::t('app.f12.backup', 'Size'), |
||||
60 | 'status' => Yii::t('app.f12.backup', 'Status'), |
||||
61 | ]; |
||||
62 | } |
||||
63 | |||||
64 | /** |
||||
65 | * Full path to backup file on disk |
||||
66 | * @return string|void |
||||
67 | */ |
||||
68 | public function getFullPath() |
||||
69 | { |
||||
70 | if (!$this->filename) |
||||
71 | return; |
||||
72 | return Yii::$app->getModule('backup')->backupRootPath . DIRECTORY_SEPARATOR . $this->filename; |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
73 | } |
||||
74 | |||||
75 | /** |
||||
76 | * Backup file size updating |
||||
77 | * @return void |
||||
78 | */ |
||||
79 | public function updateFileSize() |
||||
80 | { |
||||
81 | $this->size = 0; |
||||
82 | if (file_exists($this->getFullPath())) |
||||
83 | $this->size = filesize($this->getFullPath()); |
||||
84 | } |
||||
85 | |||||
86 | /** |
||||
87 | * Delete file from disk |
||||
88 | * @return void |
||||
89 | */ |
||||
90 | public function afterDelete() |
||||
91 | { |
||||
92 | @unlink($this->getFullPath()); |
||||
0 ignored issues
–
show
It seems like you do not handle an error condition for
unlink() . This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||||
93 | parent::afterDelete(); |
||||
94 | } |
||||
95 | } |
||||
96 |