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 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\Helper\Type\Str; |
12
|
|
|
|
13
|
|
|
class Application extends AdminController |
14
|
|
|
{ |
15
|
|
|
public $type = 'app'; |
16
|
|
|
|
17
|
|
|
public function __construct() |
18
|
|
|
{ |
19
|
|
|
// prevent version checks |
20
|
|
|
parent::__construct(false); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* List of all installed applications |
26
|
|
|
* @return string|null |
27
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
28
|
|
|
*/ |
29
|
|
|
public function actionIndex() |
30
|
|
|
{ |
31
|
|
|
return App::$View->render('index', [ |
32
|
|
|
'apps' => $this->applications |
33
|
|
|
]); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Show installation for of applications |
39
|
|
|
* @return string |
40
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
41
|
|
|
*/ |
42
|
|
|
public function actionInstall() |
43
|
|
|
{ |
44
|
|
|
$model = new FormInstall($this->applications, 'app'); |
45
|
|
|
|
46
|
|
|
// check if model is sended |
47
|
|
|
if ($model->send()) { |
48
|
|
|
// validate app name |
49
|
|
|
if ($model->validate()) { |
50
|
|
|
// try to run ::install method from remoute controller |
51
|
|
|
if ($model->make()) { |
52
|
|
|
App::$Session->getFlashBag()->add('success', __('Application "%app%" is successful installed!', ['app' => $model->sysname])); |
53
|
|
|
App::$Response->redirect('application/index'); |
54
|
|
|
} else { |
55
|
|
|
App::$Session->getFlashBag()->add('error', __('During the installation process an error has occurred! Please contact with application developer.')); |
56
|
|
|
} |
57
|
|
|
} else { |
58
|
|
|
App::$Session->getFlashBag()->add('error', __('Probably, app or widget with the same name is always used! Try to solve this conflict.')); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return App::$View->render('install', [ |
63
|
|
|
'model' => $model->export() |
64
|
|
|
]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function actionUpdate($sys_name) |
68
|
|
|
{ |
69
|
|
|
// get controller name and try to find app in db |
70
|
|
|
$controller = ucfirst(Str::lowerCase($sys_name)); |
71
|
|
|
$search = \Apps\ActiveRecord\App::getItem('app', $controller); |
72
|
|
|
|
73
|
|
|
// check what we got |
74
|
|
|
if ($search === null || (int)$search->id < 1) { |
75
|
|
|
throw new ForbiddenException('App is not founded'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$model = new FormUpdate($controller); |
|
|
|
|
79
|
|
|
|
80
|
|
|
|
81
|
|
|
|
82
|
|
|
|
83
|
|
|
return 'test'; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Allow turn on/off applications |
88
|
|
|
* @param $controllerName |
89
|
|
|
* @return string |
90
|
|
|
* @throws ForbiddenException |
91
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
92
|
|
|
*/ |
93
|
|
|
public function actionTurn($controllerName) |
94
|
|
|
{ |
95
|
|
|
$controllerName = ucfirst(Str::lowerCase($controllerName)); |
96
|
|
|
|
97
|
|
|
$search = \Apps\ActiveRecord\App::where('sys_name', '=', $controllerName)->where('type', '=', 'app')->first(); |
98
|
|
|
|
99
|
|
|
if ($search === null || (int)$search->id < 1) { |
100
|
|
|
throw new ForbiddenException('App is not founded'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$model = new FormAppTurn(); |
104
|
|
|
|
105
|
|
|
if ($model->send()) { |
106
|
|
|
$model->updateApp($search); |
107
|
|
|
App::$Session->getFlashBag()->add('success', __('Application status was changed')); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return App::$View->render('turn', [ |
111
|
|
|
'app' => $search, |
112
|
|
|
'model' => $model |
113
|
|
|
]); |
114
|
|
|
} |
115
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.