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
|
|
|
/** |
12
|
|
|
* @see http://hiqdev.com/hipanel-module-hosting |
13
|
|
|
* @license http://hiqdev.com/hipanel-module-hosting/license |
14
|
|
|
* @copyright Copyright (c) 2015 HiQDev |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace hipanel\modules\hosting\controllers; |
18
|
|
|
|
19
|
|
|
use hipanel\actions\IndexAction; |
20
|
|
|
use hipanel\actions\SmartUpdateAction; |
21
|
|
|
use hipanel\actions\ValidateFormAction; |
22
|
|
|
use hipanel\actions\ViewAction; |
23
|
|
|
use hipanel\filters\EasyAccessControl; |
24
|
|
|
use hipanel\modules\hosting\models\Crontab; |
25
|
|
|
use Yii; |
26
|
|
|
use yii\base\Exception; |
27
|
|
|
use yii\web\Response; |
28
|
|
|
|
29
|
|
|
class CrontabController extends \hipanel\base\CrudController |
30
|
|
|
{ |
31
|
|
|
public function behaviors() |
32
|
|
|
{ |
33
|
|
|
return array_merge(parent::behaviors(), [ |
34
|
|
|
[ |
35
|
|
|
'class' => EasyAccessControl::class, |
36
|
|
|
'actions' => [ |
37
|
|
|
'update' => 'account.update', |
38
|
|
|
'*' => 'account.read', |
39
|
|
|
], |
40
|
|
|
], |
41
|
|
|
]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function actions() |
45
|
|
|
{ |
46
|
|
|
return array_merge(parent::actions(), [ |
47
|
|
|
'index' => [ |
48
|
|
|
'class' => IndexAction::class, |
49
|
|
|
'filterStorageMap' => [ |
50
|
|
|
'server' => 'server.server.name', |
51
|
|
|
'account' => 'hosting.account.login', |
52
|
|
|
'client_id' => 'client.client.id', |
53
|
|
|
], |
54
|
|
|
], |
55
|
|
|
'view' => [ |
56
|
|
|
'class' => ViewAction::class, |
57
|
|
|
], |
58
|
|
|
'update' => [ |
59
|
|
|
'class' => SmartUpdateAction::class, |
60
|
|
|
], |
61
|
|
|
'validate-form' => [ |
62
|
|
|
'class' => ValidateFormAction::class, |
63
|
|
|
], |
64
|
|
|
]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
public function actionRequestFetch() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
\Yii::$app->response->format = Response::FORMAT_JSON; |
70
|
|
|
$response = []; |
71
|
|
|
$id = Yii::$app->request->post('id'); |
72
|
|
|
if ($id) { |
73
|
|
|
try { |
74
|
|
|
$response = Crontab::perform('request-fetch', ['id' => $id]); |
75
|
|
|
} catch (Exception $e) { |
76
|
|
|
$response['error'] = $e->errorInfo['response']; |
|
|
|
|
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $response; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
View Code Duplication |
public function actionGetRequestState() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON; |
86
|
|
|
$response = []; |
87
|
|
|
$id = Yii::$app->request->post('id'); |
88
|
|
|
if ($id) { |
89
|
|
|
try { |
90
|
|
|
$response = Crontab::perform('get-request-state', ['id' => $id]); |
91
|
|
|
} catch (Exception $e) { |
92
|
|
|
$response['error'] = $e->errorInfo['response']; |
|
|
|
|
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $response; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function actionGetInfo($id) |
100
|
|
|
{ |
101
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON; |
102
|
|
|
$response = []; |
103
|
|
|
if ($id) { |
104
|
|
|
try { |
105
|
|
|
$response = Crontab::perform('get-info', ['id' => $id]); |
106
|
|
|
} catch (Exception $e) { |
107
|
|
|
$response = $e->errorInfo['response']; |
|
|
|
|
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return $response; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
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.