|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Apps\Controller\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Apps\Model\Admin\Application\FormAppTurn; |
|
6
|
|
|
use Apps\Model\Admin\Application\FormInstall; |
|
7
|
|
|
use Extend\Core\Arch\AdminAppController; |
|
8
|
|
|
use Ffcms\Core\App; |
|
9
|
|
|
use Ffcms\Core\Exception\ForbiddenException; |
|
10
|
|
|
use Ffcms\Core\Helper\Type\Str; |
|
11
|
|
|
|
|
12
|
|
|
class Application extends AdminAppController |
|
13
|
|
|
{ |
|
14
|
|
|
public function __construct() |
|
15
|
|
|
{ |
|
16
|
|
|
// prevent version checks |
|
17
|
|
|
parent::__construct(false); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* List of all installed applications |
|
23
|
|
|
* @return string|null |
|
24
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
|
25
|
|
|
*/ |
|
26
|
|
|
public function actionIndex() |
|
27
|
|
|
{ |
|
28
|
|
|
return App::$View->render('index', [ |
|
29
|
|
|
'apps' => $this->applications |
|
30
|
|
|
]); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Show installation for of applications |
|
36
|
|
|
* @return string |
|
37
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
|
38
|
|
|
*/ |
|
39
|
|
|
public function actionInstall() |
|
40
|
|
|
{ |
|
41
|
|
|
$model = new FormInstall($this->table, 'app'); |
|
42
|
|
|
|
|
43
|
|
|
// check if model is sended |
|
44
|
|
|
if ($model->send()) { |
|
45
|
|
|
// validate app name |
|
46
|
|
|
if ($model->validate()) { |
|
47
|
|
|
// try to run ::install method from remoute controller |
|
48
|
|
|
if ($model->make()) { |
|
49
|
|
|
App::$Session->getFlashBag()->add('success', __('Application "%app%" is successful installed!', ['app' => $model->sysname])); |
|
50
|
|
|
App::$Response->redirect('application/index'); |
|
51
|
|
|
} else { |
|
52
|
|
|
App::$Session->getFlashBag()->add('error', __('During the installation process an error has occurred! Please contact with application developer.')); |
|
53
|
|
|
} |
|
54
|
|
|
} else { |
|
55
|
|
|
App::$Session->getFlashBag()->add('error', __('Probably, app or widget with the same name is always used! Try to solve this conflict.')); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return App::$View->render('install', [ |
|
60
|
|
|
'model' => $model->export() |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Allow turn on/off applications |
|
66
|
|
|
* @param $controllerName |
|
67
|
|
|
* @return string |
|
68
|
|
|
* @throws ForbiddenException |
|
69
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
|
70
|
|
|
*/ |
|
71
|
|
|
public function actionTurn($controllerName) |
|
72
|
|
|
{ |
|
73
|
|
|
$controllerName = ucfirst(Str::lowerCase($controllerName)); |
|
74
|
|
|
|
|
75
|
|
|
$search = \Apps\ActiveRecord\App::where('sys_name', '=', $controllerName)->first(); |
|
76
|
|
|
|
|
77
|
|
|
if ($search === null || (int)$search->id < 1) { |
|
78
|
|
|
throw new ForbiddenException(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$model = new FormAppTurn(); |
|
82
|
|
|
|
|
83
|
|
|
if ($model->send()) { |
|
84
|
|
|
$model->updateApp($search); |
|
85
|
|
|
App::$Session->getFlashBag()->add('success', __('Application status was changed')); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return App::$View->render('turn', [ |
|
89
|
|
|
'app' => $search, |
|
90
|
|
|
'model' => $model |
|
91
|
|
|
]); |
|
92
|
|
|
} |
|
93
|
|
|
} |