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