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-2017, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\hosting\controllers; |
12
|
|
|
|
13
|
|
|
use hipanel\actions\IndexAction; |
14
|
|
|
use hipanel\actions\SmartCreateAction; |
15
|
|
|
use hipanel\actions\SmartDeleteAction; |
16
|
|
|
use hipanel\actions\SmartPerformAction; |
17
|
|
|
use hipanel\actions\SmartUpdateAction; |
18
|
|
|
use hipanel\actions\ValidateFormAction; |
19
|
|
|
use hipanel\actions\ViewAction; |
20
|
|
|
use hipanel\base\CrudController; |
21
|
|
|
use Yii; |
22
|
|
|
use yii\base\Event; |
23
|
|
|
|
24
|
|
|
class DbController extends CrudController |
25
|
|
|
{ |
26
|
|
|
public function behaviors() |
27
|
|
|
{ |
28
|
|
|
return array_merge(parent::behaviors(), [ |
29
|
|
|
[ |
30
|
|
|
'class' => EasyAccessControl::class, |
31
|
|
|
'actions' => [ |
32
|
|
|
'create' => 'account.create', |
33
|
|
|
'delete,truncate' => 'account.delete', |
34
|
|
|
'set-password,set-description' => 'account.update', |
35
|
|
|
'*' => 'account.read', |
36
|
|
|
], |
37
|
|
|
], |
38
|
|
|
]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function actions() |
42
|
|
|
{ |
43
|
|
|
return array_merge(parent::actions(), [ |
44
|
|
|
'index' => [ |
45
|
|
|
'class' => IndexAction::class, |
46
|
|
|
'data' => function ($action) { |
47
|
|
|
return [ |
48
|
|
|
'stateData' => $action->controller->getStateData(), |
49
|
|
|
]; |
50
|
|
|
}, |
51
|
|
|
'filterStorageMap' => [ |
52
|
|
|
'name_like' => 'hosting.db.name_like', |
53
|
|
|
'state' => 'hosting.db.state', |
54
|
|
|
'account' => 'hosting.account.login', |
55
|
|
|
'server' => 'server.server.name', |
56
|
|
|
'client_id' => 'client.client.id', |
57
|
|
|
'seller_id' => 'client.client.seller_id', |
58
|
|
|
], |
59
|
|
|
], |
60
|
|
|
'view' => [ |
61
|
|
|
'class' => ViewAction::class, |
62
|
|
|
], |
63
|
|
|
'create' => [ |
64
|
|
|
'class' => SmartCreateAction::class, |
65
|
|
|
'success' => Yii::t('hipanel:hosting', 'DB has been created successfully'), |
66
|
|
|
], |
67
|
|
|
'set-password' => [ |
68
|
|
|
'class' => SmartUpdateAction::class, |
69
|
|
|
'success' => Yii::t('hipanel', 'Password been changed successfully'), |
70
|
|
|
], |
71
|
|
|
'truncate' => [ |
72
|
|
|
'class' => SmartUpdateAction::class, |
73
|
|
|
'success' => Yii::t('hipanel:hosting', 'DB has been truncated successfully'), |
74
|
|
|
], |
75
|
|
|
'set-description' => [ |
76
|
|
|
'class' => SmartUpdateAction::class, |
77
|
|
|
'success' => Yii::t('hipanel:hosting', 'Description has been changed successfully'), |
78
|
|
|
], |
79
|
|
|
'validate-form' => [ |
80
|
|
|
'class' => ValidateFormAction::class, |
81
|
|
|
], |
82
|
|
|
'delete' => [ |
83
|
|
|
'class' => SmartDeleteAction::class, |
84
|
|
|
'success' => Yii::t('hipanel:hosting', 'DB has been deleted successfully'), |
85
|
|
|
], |
86
|
|
|
'enable-backuping' => [ |
87
|
|
|
'class' => SmartPerformAction::class, |
88
|
|
|
'success' => Yii::t('hipanel:hosting', 'Backups were enabled for the domain'), |
89
|
|
|
'on beforeSave' => function (Event $event) { |
90
|
|
|
/** @var \hipanel\actions\Action $action */ |
91
|
|
|
$action = $event->sender; |
92
|
|
|
foreach ($action->collection->models as $model) { |
93
|
|
|
$model->setAttribute('backuping_type', 'week'); |
94
|
|
|
} |
95
|
|
|
}, |
96
|
|
|
], |
97
|
|
|
]); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getStateData() |
101
|
|
|
{ |
102
|
|
|
return $this->getRefs('state,db', 'hipanel:hosting'); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|