1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Controller\Admin; |
4
|
|
|
|
5
|
|
|
use Apps\Model\Admin\Application\FormInstall; |
6
|
|
|
use Apps\Model\Admin\Application\FormTurn; |
7
|
|
|
use Apps\Model\Admin\Application\FormUpdate; |
8
|
|
|
use Extend\Core\Arch\AdminController; |
9
|
|
|
use Ffcms\Core\App; |
10
|
|
|
use Ffcms\Core\Exception\ForbiddenException; |
11
|
|
|
use Ffcms\Core\Exception\NotFoundException; |
12
|
|
|
use Ffcms\Core\Helper\Type\Str; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class Application. View and manage system applications. |
16
|
|
|
* @package Apps\Controller\Admin |
17
|
|
|
*/ |
18
|
|
|
class Application extends AdminController |
19
|
|
|
{ |
20
|
|
|
public $type = 'app'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Application constructor. |
24
|
|
|
* @throws ForbiddenException |
25
|
|
|
*/ |
26
|
|
|
public function __construct() |
27
|
|
|
{ |
28
|
|
|
// prevent version checks |
29
|
|
|
parent::__construct(false); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* List of all installed applications |
34
|
|
|
* @return string|null |
35
|
|
|
*/ |
36
|
|
|
public function actionIndex(): ?string |
37
|
|
|
{ |
38
|
|
|
return $this->view->render('application/index', [ |
39
|
|
|
'apps' => $this->applications |
40
|
|
|
]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Show installation for of applications |
45
|
|
|
* @return string|null |
46
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
47
|
|
|
*/ |
48
|
|
|
public function actionInstall(): ?string |
49
|
|
|
{ |
50
|
|
|
$model = new FormInstall($this->applications, 'app'); |
51
|
|
|
|
52
|
|
|
// check if model is sended |
53
|
|
|
if ($model->send()) { |
54
|
|
|
// validate app name |
55
|
|
|
if ($model->validate()) { |
56
|
|
|
// try to run ::install method from remoute controller |
57
|
|
|
if ($model->make()) { |
58
|
|
|
App::$Session->getFlashBag()->add('success', __('Application "%app%" is successful installed!', ['app' => $model->sysname])); |
59
|
|
|
$this->response->redirect('application/index'); |
60
|
|
|
} else { |
61
|
|
|
App::$Session->getFlashBag()->add('error', __('During the installation process an error has occurred! Please contact with application developer.')); |
62
|
|
|
} |
63
|
|
|
} else { |
64
|
|
|
App::$Session->getFlashBag()->add('error', __('Probably, app or widget with the same name is always used! Try to solve this conflict.')); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $this->view->render('application/install', [ |
69
|
|
|
'model' => $model |
70
|
|
|
]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Show and process update form for apps |
75
|
|
|
* @param string $sys |
76
|
|
|
* @return string|null |
77
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
78
|
|
|
* @throws NotFoundException |
79
|
|
|
*/ |
80
|
|
|
public function actionUpdate($sys): ?string |
81
|
|
|
{ |
82
|
|
|
// get controller name and try to find app in db |
83
|
|
|
$controller = ucfirst(Str::lowerCase($sys)); |
84
|
|
|
$search = \Apps\ActiveRecord\App::getItem('app', $controller); |
|
|
|
|
85
|
|
|
|
86
|
|
|
// check what we got |
87
|
|
|
if (!$search || (int)$search->id < 1) { |
|
|
|
|
88
|
|
|
throw new NotFoundException('App is not founded'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// init model and make update with notification |
92
|
|
|
$model = new FormUpdate($search); |
93
|
|
|
if ($model->send() && $model->validate()) { |
94
|
|
|
$model->make(); |
95
|
|
|
App::$Session->getFlashBag()->add('success', __('Application %s% is successful updated to %v% version', ['s' => $sys, 'v' => $model->scriptVersion])); |
96
|
|
|
$this->response->redirect('application/index'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
// render response |
100
|
|
|
return $this->view->render('application/update', [ |
101
|
|
|
'model' => $model |
102
|
|
|
]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Allow turn on/off applications |
107
|
|
|
* @param $controllerName |
108
|
|
|
* @return string|null |
109
|
|
|
* @throws ForbiddenException |
110
|
|
|
*/ |
111
|
|
|
public function actionTurn($controllerName): ?string |
112
|
|
|
{ |
113
|
|
|
$controllerName = ucfirst(Str::lowerCase($controllerName)); |
114
|
|
|
|
115
|
|
|
/** @var \Apps\ActiveRecord\App $search */ |
116
|
|
|
$search = \Apps\ActiveRecord\App::where('sys_name', $controllerName) |
117
|
|
|
->where('type', 'app') |
118
|
|
|
->first(); |
119
|
|
|
if (!$search || (int)$search->id < 1) { |
|
|
|
|
120
|
|
|
throw new ForbiddenException('App is not founded'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
$model = new FormTurn($search); |
124
|
|
|
if ($model->send()) { |
125
|
|
|
$model->update(); |
126
|
|
|
App::$Session->getFlashBag()->add('success', __('Application status was changed')); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return $this->view->render('application/turn', [ |
130
|
|
|
'app' => $search, |
131
|
|
|
'model' => $model |
132
|
|
|
]); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.