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-2019, 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 hipanel\filters\EasyAccessControl; |
22
|
|
|
use Yii; |
23
|
|
|
use yii\base\Event; |
24
|
|
|
|
25
|
|
|
class DbController extends CrudController |
26
|
|
|
{ |
27
|
|
View Code Duplication |
public function behaviors() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
return array_merge(parent::behaviors(), [ |
30
|
|
|
[ |
31
|
|
|
'class' => EasyAccessControl::class, |
32
|
|
|
'actions' => [ |
33
|
|
|
'create' => 'account.create', |
34
|
|
|
'delete,truncate' => 'account.delete', |
35
|
|
|
'set-password,set-description' => 'account.update', |
36
|
|
|
'*' => 'account.read', |
37
|
|
|
], |
38
|
|
|
], |
39
|
|
|
]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function actions() |
43
|
|
|
{ |
44
|
|
|
return array_merge(parent::actions(), [ |
45
|
|
|
'index' => [ |
46
|
|
|
'class' => IndexAction::class, |
47
|
|
|
'data' => function ($action) { |
48
|
|
|
return [ |
49
|
|
|
'stateData' => $action->controller->getStateData(), |
50
|
|
|
]; |
51
|
|
|
}, |
52
|
|
|
'filterStorageMap' => [ |
53
|
|
|
'name_like' => 'hosting.db.name_like', |
54
|
|
|
'state' => 'hosting.db.state', |
55
|
|
|
'account' => 'hosting.account.login', |
56
|
|
|
'server' => 'server.server.name', |
57
|
|
|
'client_id' => 'client.client.id', |
58
|
|
|
'seller_id' => 'client.client.seller_id', |
59
|
|
|
], |
60
|
|
|
], |
61
|
|
|
'view' => [ |
62
|
|
|
'class' => ViewAction::class, |
63
|
|
|
], |
64
|
|
|
'create' => [ |
65
|
|
|
'class' => SmartCreateAction::class, |
66
|
|
|
'success' => Yii::t('hipanel:hosting', 'DB has been created successfully'), |
67
|
|
|
], |
68
|
|
|
'set-password' => [ |
69
|
|
|
'class' => SmartUpdateAction::class, |
70
|
|
|
'success' => Yii::t('hipanel', 'Password been changed successfully'), |
71
|
|
|
], |
72
|
|
|
'truncate' => [ |
73
|
|
|
'class' => SmartUpdateAction::class, |
74
|
|
|
'success' => Yii::t('hipanel:hosting', 'DB has been truncated successfully'), |
75
|
|
|
], |
76
|
|
|
'set-description' => [ |
77
|
|
|
'class' => SmartUpdateAction::class, |
78
|
|
|
'success' => Yii::t('hipanel:hosting', 'Description has been changed successfully'), |
79
|
|
|
], |
80
|
|
|
'validate-form' => [ |
81
|
|
|
'class' => ValidateFormAction::class, |
82
|
|
|
], |
83
|
|
|
'delete' => [ |
84
|
|
|
'class' => SmartDeleteAction::class, |
85
|
|
|
'success' => Yii::t('hipanel:hosting', 'DB has been deleted successfully'), |
86
|
|
|
], |
87
|
|
|
'enable-backuping' => [ |
88
|
|
|
'class' => SmartPerformAction::class, |
89
|
|
|
'success' => Yii::t('hipanel:hosting', 'Backups were enabled for the domain'), |
90
|
|
|
'on beforeSave' => function (Event $event) { |
91
|
|
|
/** @var \hipanel\actions\Action $action */ |
92
|
|
|
$action = $event->sender; |
93
|
|
|
foreach ($action->collection->models as $model) { |
94
|
|
|
$model->setAttribute('backuping_type', 'week'); |
95
|
|
|
} |
96
|
|
|
}, |
97
|
|
|
], |
98
|
|
|
]); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getStateData() |
102
|
|
|
{ |
103
|
|
|
return $this->getRefs('state,db', 'hipanel:hosting'); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.