1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Hosting Plugin for HiPanel |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/hipanel-module-hosting |
7
|
|
|
* @package hipanel-module-hosting |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hipanel\modules\hosting\models; |
13
|
|
|
|
14
|
|
|
use hipanel\base\Model; |
15
|
|
|
use hipanel\base\ModelTrait; |
16
|
|
|
use hipanel\modules\hosting\validators\DbNameValidator; |
17
|
|
|
use Yii; |
18
|
|
|
|
19
|
|
|
class Db extends Model |
20
|
|
|
{ |
21
|
|
|
use ModelTrait; |
22
|
|
|
|
23
|
|
|
/** @inheritdoc */ |
24
|
|
|
public function rules() |
25
|
|
|
{ |
26
|
|
|
return [ |
27
|
|
|
[['id', 'account_id', 'client_id', 'seller_id', 'service_id', 'device_id', 'server_id'], 'integer'], |
28
|
|
|
[['name', 'account', 'client', 'seller', 'service', 'device', 'server'], 'safe'], |
29
|
|
|
[['service_ip', 'description'], 'safe'], |
30
|
|
|
[['type', 'state', 'backuping_type', 'type_label', 'state_label', 'backuping_type_label'], 'safe'], |
31
|
|
|
/// Create |
32
|
|
|
[['server', 'account', 'service_id', 'name', 'password'], 'required', 'on' => ['create']], |
33
|
|
|
[['name'], DbNameValidator::class, 'on' => ['create']], |
34
|
|
|
[ |
35
|
|
|
['password'], |
36
|
|
|
'match', |
37
|
|
|
'pattern' => '/^[\x20-\x7f]*$/', |
38
|
|
|
'message' => Yii::t('hipanel:hosting', '{attribute} should not contain non-latin characters'), |
39
|
|
|
'on' => ['create', 'set-password'] |
40
|
|
|
], |
41
|
|
|
[['password'], 'required', 'on' => ['set-password']], |
42
|
|
|
[['id'], 'required', 'on' => ['delete', 'set-password', 'set-description', 'truncate']], |
43
|
|
|
[['backuping_exists'], 'boolean'], |
44
|
|
|
[['backuping_type'], 'required', 'on' => ['enable-backuping', 'disable-backuping']], |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** @inheritdoc */ |
49
|
|
|
public function attributeLabels() |
50
|
|
|
{ |
51
|
|
|
return $this->mergeAttributeLabels([ |
52
|
|
|
'name' => Yii::t('hipanel:hosting', 'DB name'), |
53
|
|
|
'service_ip' => Yii::t('hipanel:hosting', 'Service IP'), |
54
|
|
|
'backuping_type' => Yii::t('hipanel:hosting', 'Backup type'), |
55
|
|
|
]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function scenarioCommands() |
59
|
|
|
{ |
60
|
|
|
$result = []; |
61
|
|
|
$result['enable-backuping'] = 'update-backuping'; |
62
|
|
|
$result['disable-backuping'] = 'update-backuping'; |
63
|
|
|
|
64
|
|
|
return $result; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|