Completed
Push — master ( 4b54e5...2a2b67 )
by Klochok
04:04
created

Db::scenarioCommands()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 2
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