These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\ComboSearchAction; |
||
14 | use hipanel\actions\IndexAction; |
||
15 | use hipanel\actions\PrepareBulkAction; |
||
16 | use hipanel\actions\RedirectAction; |
||
17 | use hipanel\actions\RenderJsonAction; |
||
18 | use hipanel\actions\SmartCreateAction; |
||
19 | use hipanel\actions\SmartDeleteAction; |
||
20 | use hipanel\actions\SmartPerformAction; |
||
21 | use hipanel\actions\SmartUpdateAction; |
||
22 | use hipanel\actions\ValidateFormAction; |
||
23 | use hipanel\actions\ViewAction; |
||
24 | use Yii; |
||
25 | use yii\base\Event; |
||
26 | |||
27 | class HdomainController extends \hipanel\base\CrudController |
||
28 | { |
||
29 | public function actions() |
||
30 | { |
||
31 | return array_merge(parent::actions(), [ |
||
32 | 'search' => [ |
||
33 | 'class' => ComboSearchAction::class, |
||
34 | ], |
||
35 | 'index' => [ |
||
36 | 'class' => IndexAction::class, |
||
37 | 'findOptions' => [ |
||
38 | 'with_vhosts' => true, |
||
39 | 'with_aliases' => true, |
||
40 | 'with_request' => true, |
||
41 | ], |
||
42 | 'data' => function ($action) { |
||
43 | return [ |
||
44 | 'stateData' => $action->controller->getStateData(), |
||
45 | 'typeData' => $action->controller->getTypeData(), |
||
46 | ]; |
||
47 | }, |
||
48 | 'filterStorageMap' => [ |
||
49 | 'domain_like' => 'domain.hdomain.domain_like', |
||
50 | 'state' => 'hosting.hdomain.state', |
||
51 | 'server' => 'server.server.name', |
||
52 | 'account' => 'hosting.account.login', |
||
53 | 'client_id' => 'client.client.id', |
||
54 | 'seller_id' => 'client.client.seller_id', |
||
55 | ], |
||
56 | ], |
||
57 | 'view' => [ |
||
58 | 'class' => ViewAction::class, |
||
59 | 'findOptions' => [ |
||
60 | 'with_vhosts' => true, |
||
61 | 'with_aliases' => true, |
||
62 | 'with_request' => true, |
||
63 | 'show_deleted' => true, |
||
64 | 'show_aliases' => true, |
||
65 | 'with_blocking' => true, |
||
66 | ], |
||
67 | 'on beforePerform' => function (Event $event) { |
||
68 | /** @var \hipanel\actions\SearchAction $action */ |
||
69 | $action = $event->sender; |
||
70 | $dataProvider = $action->getDataProvider(); |
||
71 | $dataProvider->query->joinWith(['blocking']); |
||
72 | }, |
||
73 | 'data' => function ($action) { |
||
74 | return [ |
||
75 | 'blockReasons' => $this->getBlockReasons(), |
||
76 | ]; |
||
77 | }, |
||
78 | ], |
||
79 | 'create' => [ |
||
80 | 'class' => SmartCreateAction::class, |
||
81 | 'success' => Yii::t('hipanel:hosting', 'Domain has been created successfully'), |
||
82 | ], |
||
83 | 'create-alias' => [ |
||
84 | 'class' => SmartCreateAction::class, |
||
85 | 'view' => 'create-alias', |
||
86 | 'success' => Yii::t('hipanel:hosting', 'Domain has been created successfully'), |
||
87 | ], |
||
88 | 'enable-block' => [ |
||
89 | 'class' => SmartUpdateAction::class, |
||
90 | 'success' => Yii::t('hipanel:hosting', 'Domain has been blocked successfully'), |
||
91 | ], |
||
92 | 'disable-block' => [ |
||
93 | 'class' => SmartUpdateAction::class, |
||
94 | 'success' => Yii::t('hipanel:hosting', 'Domain has been unblocked successfully'), |
||
95 | ], |
||
96 | 'validate-form' => [ |
||
97 | 'class' => ValidateFormAction::class, |
||
98 | ], |
||
99 | 'enable-paid-feature-autorenewal' => [ |
||
100 | 'class' => SmartPerformAction::class, |
||
101 | 'success' => Yii::t('hipanel:hosting', 'Premium autorenewal has been enabled'), |
||
102 | ], |
||
103 | 'disable-paid-feature-autorenewal' => [ |
||
104 | 'class' => SmartPerformAction::class, |
||
105 | 'success' => Yii::t('hipanel:hosting', 'Premium autorenewal has been disabled'), |
||
106 | ], |
||
107 | 'delete' => [ |
||
108 | 'class' => SmartDeleteAction::class, |
||
109 | 'success' => Yii::t('hipanel:hosting', 'Domain has been deleted successfully'), |
||
110 | ], |
||
111 | 'delete-alias' => [ |
||
112 | 'class' => SmartDeleteAction::class, |
||
113 | 'scenario' => 'delete', |
||
114 | 'success' => Yii::t('hipanel:hosting', 'Domain has been deleted successfully'), |
||
115 | ], |
||
116 | 'bulk-enable-block' => [ |
||
117 | 'class' => SmartUpdateAction::class, |
||
118 | 'scenario' => 'enable-block', |
||
119 | 'success' => Yii::t('hipanel:hosting', 'Domains have been blocked successfully'), |
||
120 | 'POST html' => [ |
||
121 | 'save' => true, |
||
122 | 'success' => [ |
||
123 | 'class' => RedirectAction::class, |
||
124 | ], |
||
125 | ], |
||
126 | 'on beforeSave' => function (Event $event) { |
||
127 | /** @var \hipanel\actions\Action $action */ |
||
128 | $action = $event->sender; |
||
129 | $type = Yii::$app->request->post('type'); |
||
130 | $comment = Yii::$app->request->post('comment'); |
||
131 | View Code Duplication | if (!empty($type)) { |
|
132 | foreach ($action->collection->models as $model) { |
||
133 | $model->setAttributes([ |
||
134 | 'type' => $type, |
||
135 | 'comment' => $comment, |
||
136 | ]); |
||
137 | } |
||
138 | } |
||
139 | }, |
||
140 | ], |
||
141 | 'bulk-enable-block-modal' => [ |
||
142 | 'class' => PrepareBulkAction::class, |
||
143 | 'scenario' => 'enable-block', |
||
144 | 'view' => '_bulkEnableBlock', |
||
145 | 'data' => function ($action, $data) { |
||
146 | return array_merge($data, [ |
||
147 | 'blockReasons' => $this->getBlockReasons(), |
||
148 | ]); |
||
149 | }, |
||
150 | ], |
||
151 | 'bulk-disable-block' => [ |
||
152 | 'class' => SmartUpdateAction::class, |
||
153 | 'scenario' => 'disable-block', |
||
154 | 'success' => Yii::t('hipanel:hosting', 'Domains have been unblocked successfully'), |
||
155 | 'POST html' => [ |
||
156 | 'save' => true, |
||
157 | 'success' => [ |
||
158 | 'class' => RedirectAction::class, |
||
159 | ], |
||
160 | ], |
||
161 | View Code Duplication | 'on beforeSave' => function (Event $event) { |
|
162 | /** @var \hipanel\actions\Action $action */ |
||
163 | $action = $event->sender; |
||
164 | $comment = Yii::$app->request->post('comment'); |
||
165 | if (!empty($type)) { |
||
166 | foreach ($action->collection->models as $model) { |
||
167 | $model->setAttribute('comment', $comment); |
||
168 | } |
||
169 | } |
||
170 | }, |
||
171 | ], |
||
172 | 'bulk-disable-block-modal' => [ |
||
173 | 'class' => PrepareBulkAction::class, |
||
174 | 'scenario' => 'disable-block', |
||
175 | 'view' => '_bulkDisableBlock', |
||
176 | ], |
||
177 | 'set-dns-on' => [ |
||
178 | 'class' => SmartUpdateAction::class, |
||
179 | 'success' => Yii::t('hipanel:hosting', 'DNS settings were changed'), |
||
180 | 'POST html' => [ |
||
181 | 'save' => true, |
||
182 | 'success' => [ |
||
183 | 'class' => RedirectAction::class, |
||
184 | ], |
||
185 | ], |
||
186 | ], |
||
187 | 'enable-backuping' => [ |
||
188 | 'class' => SmartPerformAction::class, |
||
189 | 'success' => Yii::t('hipanel:hosting', 'Backups were enabled for the domain'), |
||
190 | 'on beforeSave' => function (Event $event) { |
||
191 | /** @var \hipanel\actions\Action $action */ |
||
192 | $action = $event->sender; |
||
193 | foreach ($action->collection->models as $model) { |
||
194 | $model->setAttribute('backuping_type', 'week'); |
||
195 | } |
||
196 | }, |
||
197 | ], |
||
198 | 'set-premium-autorenewal' => [ |
||
199 | 'class' => SmartPerformAction::class, |
||
200 | 'success' => Yii::t('hipanel:domain', 'Premium autorenewal has been changed'), |
||
201 | 'scenario' => 'set-paid-feature-autorenewal', |
||
202 | 'queryOptions' => [ |
||
203 | 'batch' => false, |
||
204 | ], |
||
205 | 'POST ajax' => [ |
||
206 | 'save' => true, |
||
207 | 'flash' => true, |
||
208 | 'success' => [ |
||
209 | 'class' => RenderJsonAction::class, |
||
210 | View Code Duplication | 'return' => function ($action) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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.
Loading history...
|
|||
211 | $message = Yii::$app->session->removeFlash('success'); |
||
212 | return [ |
||
213 | 'success' => true, |
||
214 | 'text' => Yii::t('hipanel:domain', reset($message)['text']), |
||
215 | ]; |
||
216 | }, |
||
217 | ], |
||
218 | 'error' => [ |
||
219 | 'class' => RenderJsonAction::class, |
||
220 | View Code Duplication | 'return' => function ($action) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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.
Loading history...
|
|||
221 | $message = Yii::$app->session->removeFlash('error'); |
||
222 | return [ |
||
223 | 'success' => false, |
||
224 | 'text' => reset($message)['text'], |
||
225 | ]; |
||
226 | }, |
||
227 | ], |
||
228 | ], |
||
229 | ], |
||
230 | 'enable-premium-autorenewal' => [ |
||
231 | 'class' => SmartPerformAction::class, |
||
232 | 'scenario' => 'enable-paid-feature-autorenewal', |
||
233 | 'success' => Yii::t('hipanel:domain', 'Autorenewal has been enabled'), |
||
234 | 'error' => Yii::t('hipanel:domain', 'Failed enabling Autorenewal'), |
||
235 | ], |
||
236 | 'disable-premium-autorenewal' => [ |
||
237 | 'class' => SmartPerformAction::class, |
||
238 | 'scenario' => 'disable-paid-feature-autorenewal', |
||
239 | 'success' => Yii::t('hipanel:domain', 'Autorenewal has been disabled'), |
||
240 | 'error' => Yii::t('hipanel:domain', 'Failed disabling Autorenewal'), |
||
241 | ], |
||
242 | ]); |
||
243 | } |
||
244 | |||
245 | public function getStateData() |
||
246 | { |
||
247 | return $this->getRefs('state,hdomain', 'hipanel:hosting'); |
||
248 | } |
||
249 | |||
250 | public function getTypeData() |
||
251 | { |
||
252 | return [ |
||
253 | 0 => Yii::t('hipanel', 'Domain'), |
||
254 | 1 => Yii::t('hipanel', 'Alias'), |
||
255 | ]; |
||
256 | } |
||
257 | } |
||
258 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.