Code Duplication    Length = 109-111 lines in 2 locations

Apps/Controller/Admin/Application.php 1 location

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

Apps/Controller/Admin/Widget.php 1 location

@@ 20-130 (lines=111) @@
17
 * This class provide general admin implementation of control for user comments and its settings
18
 * @package Apps\Controller\Admin
19
 */
20
class Widget extends AdminController
21
{
22
    public $type = 'widget';
23
24
    /**
25
     * Widget constructor. Disable installation checking for this controller
26
     */
27
    public function __construct()
28
    {
29
        parent::__construct(false);
30
    }
31
32
    /**
33
     * Show all installed widgets
34
     * @return string
35
     * @throws \Ffcms\Core\Exception\SyntaxException
36
     */
37
    public function actionIndex()
38
    {
39
        return App::$View->render('index', [
40
            'widgets' => $this->widgets
41
        ]);
42
    }
43
44
    /**
45
     * Show installation for of applications
46
     * @return string
47
     * @throws \Ffcms\Core\Exception\SyntaxException
48
     */
49
    public function actionInstall()
50
    {
51
        $model = new FormInstall($this->applications, 'widget');
52
53
        // check if model is sended
54
        if ($model->send()) {
55
            // validate app name
56
            if ($model->validate()) {
57
                // try to run ::install method from remoute controller
58
                if ($model->make()) {
59
                    App::$Session->getFlashBag()->add('success', __('Widget "%widget%" is successful installed!', ['widget' => $model->sysname]));
60
                    App::$Response->redirect('widget/index');
61
                } else {
62
                    App::$Session->getFlashBag()->add('error', __('During the installation process an error has occurred! Please contact with widget developer.'));
63
                }
64
            } else {
65
                App::$Session->getFlashBag()->add('error', __('Probably, app or widget with the same name is always used! Try to solve this conflict.'));
66
            }
67
        }
68
69
        return App::$View->render('install', [
70
            'model' => $model->export()
71
        ]);
72
    }
73
74
    public function actionUpdate($sys_name)
75
    {
76
        // get controller name and try to find app in db
77
        $controller = ucfirst(Str::lowerCase($sys_name));
78
        $search = \Apps\ActiveRecord\App::getItem('widget', $controller);
79
80
        // check what we got
81
        if ($search === null || (int)$search->id < 1) {
82
            throw new NotFoundException('Widget is not founded');
83
        }
84
85
        // init model and make update with notification
86
        $model = new FormUpdate($search);
87
88
        if ($model->send() && $model->validate()) {
89
            $model->make();
90
            App::$Session->getFlashBag()->add('success', __('Widget %w% is successful updated to %v% version', ['w' => $sys_name, 'v' => $model->scriptVersion]));
91
            App::$Response->redirect('application/index');
92
        }
93
94
        // render response
95
        return App::$View->render('update', [
96
            'model' => $model
97
        ]);
98
    }
99
100
    /**
101
     * Allow turn on/off applications
102
     * @param $controllerName
103
     * @return string
104
     * @throws ForbiddenException
105
     * @throws \Ffcms\Core\Exception\SyntaxException
106
     */
107
    public function actionTurn($controllerName)
108
    {
109
        $controllerName = ucfirst(Str::lowerCase($controllerName));
110
111
        $search = \Apps\ActiveRecord\App::where('sys_name', '=', $controllerName)->where('type', '=', 'widget')->first();
112
113
        if ($search === null || (int)$search->id < 1) {
114
            throw new ForbiddenException('App is not founded');
115
        }
116
117
        $model = new FormTurn();
118
119
        if ($model->send()) {
120
            $model->update($search);
121
            App::$Session->getFlashBag()->add('success', __('Widget status was changed'));
122
        }
123
124
        return App::$View->render('turn', [
125
            'widget' => $search,
126
            'model' => $model
127
        ]);
128
    }
129
130
}