|
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
|
|
|
/** |
|
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\OrientationAction; |
|
21
|
|
|
use hipanel\actions\SmartUpdateAction; |
|
22
|
|
|
use hipanel\actions\ValidateFormAction; |
|
23
|
|
|
use hipanel\actions\ViewAction; |
|
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 actions() |
|
32
|
|
|
{ |
|
33
|
|
|
return [ |
|
34
|
|
|
'index' => [ |
|
35
|
|
|
'class' => IndexAction::class, |
|
36
|
|
|
'filterStorageMap' => [ |
|
37
|
|
|
'server' => 'server.server.name', |
|
38
|
|
|
'account' => 'hosting.account.login', |
|
39
|
|
|
'client_id' => 'client.client.id', |
|
40
|
|
|
], |
|
41
|
|
|
], |
|
42
|
|
|
'view' => [ |
|
43
|
|
|
'class' => ViewAction::class, |
|
44
|
|
|
], |
|
45
|
|
|
'update' => [ |
|
46
|
|
|
'class' => SmartUpdateAction::class, |
|
47
|
|
|
], |
|
48
|
|
|
'validate-form' => [ |
|
49
|
|
|
'class' => ValidateFormAction::class, |
|
50
|
|
|
], |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
View Code Duplication |
public function actionRequestFetch() |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
\Yii::$app->response->format = Response::FORMAT_JSON; |
|
57
|
|
|
$response = []; |
|
58
|
|
|
$id = Yii::$app->request->post('id'); |
|
59
|
|
|
if ($id) { |
|
60
|
|
|
try { |
|
61
|
|
|
$response = Crontab::perform('request-fetch', ['id' => $id]); |
|
62
|
|
|
} catch (Exception $e) { |
|
63
|
|
|
$response['error'] = $e->errorInfo['response']; |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
return $response; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
View Code Duplication |
public function actionGetRequestState() |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON; |
|
72
|
|
|
$response = []; |
|
73
|
|
|
$id = Yii::$app->request->post('id'); |
|
74
|
|
|
if ($id) { |
|
75
|
|
|
try { |
|
76
|
|
|
$response = Crontab::perform('get-request-state', ['id' => $id]); |
|
77
|
|
|
} catch (Exception $e) { |
|
78
|
|
|
$response['error'] = $e->errorInfo['response']; |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
return $response; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function actionGetInfo($id) |
|
85
|
|
|
{ |
|
86
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON; |
|
87
|
|
|
$response = []; |
|
88
|
|
|
if ($id) { |
|
89
|
|
|
try { |
|
90
|
|
|
$response = Crontab::perform('get-info', ['id' => $id]); |
|
91
|
|
|
} catch (Exception $e) { |
|
92
|
|
|
$response = $e->errorInfo['response']; |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
return $response; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
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.