Completed
Push — master ( a7a898...344131 )
by Andrii
11:40
created

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