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\SmartDeleteAction; |
15
|
|
|
use hipanel\actions\SmartPerformAction; |
16
|
|
|
use hipanel\actions\SmartUpdateAction; |
17
|
|
|
use hipanel\actions\ValidateFormAction; |
18
|
|
|
use hipanel\actions\ViewAction; |
19
|
|
|
use hipanel\helpers\ArrayHelper; |
20
|
|
|
use hipanel\models\Ref; |
21
|
|
|
use hipanel\modules\hosting\models\Backuping; |
22
|
|
|
use hipanel\modules\hosting\models\BackupSearch; |
23
|
|
|
use hipanel\filters\EasyAccessControl; |
24
|
|
|
use Yii; |
25
|
|
|
use yii\filters\AccessControl; |
26
|
|
|
|
27
|
|
|
class BackupingController extends \hipanel\base\CrudController |
28
|
|
|
{ |
29
|
|
|
public function behaviors() |
30
|
|
|
{ |
31
|
|
|
return array_merge(parent::behaviors(), [ |
32
|
|
|
[ |
33
|
|
|
'class' => EasyAccessControl::class, |
34
|
|
|
'actions' => [ |
35
|
|
|
'update' => 'account.update', |
36
|
|
|
'delete' => 'account.delete', |
37
|
|
|
'*' => 'account.read', |
38
|
|
|
], |
39
|
|
|
], |
40
|
|
|
]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function actions() |
44
|
|
|
{ |
45
|
|
|
return array_merge(parent::actions(), [ |
46
|
|
|
'index' => [ |
47
|
|
|
'class' => IndexAction::class, |
48
|
|
|
'data' => function ($action) { |
49
|
|
|
return [ |
50
|
|
|
'stateOptions' => $action->controller->getStateOptions(), |
51
|
|
|
]; |
52
|
|
|
}, |
53
|
|
|
'filterStorageMap' => [ |
54
|
|
|
'state' => 'hosting.backuping.state', |
55
|
|
|
'server' => 'server.server.name', |
56
|
|
|
'account' => 'hosting.account.login', |
57
|
|
|
'client_id' => 'client.client.id', |
58
|
|
|
], |
59
|
|
|
], |
60
|
|
|
'update' => [ |
61
|
|
|
'class' => SmartUpdateAction::class, |
62
|
|
|
'success' => Yii::t('hipanel:hosting', 'Backup settings have been changed'), |
63
|
|
|
'data' => function ($action) { |
64
|
|
|
return [ |
65
|
|
|
'methodOptions' => $action->controller->getMethodOptions(), |
66
|
|
|
'dayOptions' => $action->controller->getDayOptions(), |
67
|
|
|
'hourOptions' => $action->controller->getHourOptions(), |
68
|
|
|
]; |
69
|
|
|
}, |
70
|
|
|
], |
71
|
|
|
'disable' => [ |
72
|
|
|
'class' => SmartPerformAction::class, |
73
|
|
|
], |
74
|
|
|
'enable' => [ |
75
|
|
|
'class' => SmartPerformAction::class, |
76
|
|
|
], |
77
|
|
|
'delete' => [ |
78
|
|
|
'class' => SmartDeleteAction::class, |
79
|
|
|
'success' => Yii::t('hipanel', 'Deleted'), |
80
|
|
|
'error' => Yii::t('hipanel', 'An error occurred. Try again please.'), |
81
|
|
|
], |
82
|
|
|
'view' => [ |
83
|
|
|
'class' => ViewAction::class, |
84
|
|
|
'findOptions' => ['show_deleted' => true], |
85
|
|
|
'data' => function ($action) { |
86
|
|
|
$backupSearch = new BackupSearch(); |
87
|
|
|
$backupsDataProvider = $backupSearch->search([$backupSearch->formName() => ['object_id' => $action->getId()]]); |
88
|
|
|
$backupsDataProvider->setSort(['defaultOrder' => ['time' => SORT_DESC]]); |
89
|
|
|
|
90
|
|
|
return [ |
91
|
|
|
'stateOptions' => $action->controller->getStateOptions(), |
92
|
|
|
'backupsDataProvider' => $backupsDataProvider, |
93
|
|
|
'hasBackup' => Backuping::find()->where(['id' => $action->getId()])->exists(), |
94
|
|
|
]; |
95
|
|
|
}, |
96
|
|
|
], |
97
|
|
|
'validate-form' => [ |
98
|
|
|
'class' => ValidateFormAction::class, |
99
|
|
|
], |
100
|
|
|
]); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getDayOptions() |
104
|
|
|
{ |
105
|
|
|
return ArrayHelper::map(Ref::find()->where(['gtype' => 'type,day', 'select' => 'full'])->all(), 'id', function ($model) { |
106
|
|
|
return Yii::t('hipanel:hosting', $model->label); |
107
|
|
|
}); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function getHourOptions() |
111
|
|
|
{ |
112
|
|
|
return ArrayHelper::map(Ref::find()->where(['gtype' => 'type,hour', 'select' => 'full'])->all(), 'id', function ($model) { |
113
|
|
|
return Yii::t('hipanel:hosting', $model->label); |
114
|
|
|
}); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function getMethodOptions() |
118
|
|
|
{ |
119
|
|
|
return $this->getRefs('type,backup_method', 'hipanel:hosting'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getStateOptions() |
123
|
|
|
{ |
124
|
|
|
return [ |
125
|
|
|
'ok' => Yii::t('hipanel', 'Ok'), |
126
|
|
|
'disabled' => Yii::t('hipanel', 'Disabled'), |
127
|
|
|
'deleted' => Yii::t('hipanel', 'Deleted'), |
128
|
|
|
]; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|