Passed
Push — master ( c1fc2f...23f085 )
by Mihail
04:43
created

Main::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Apps\Controller\Admin;
4
5
use Apps\Model\Admin\Main\EntityDeleteRoute;
6
use Apps\Model\Admin\Main\FormAddRoute;
7
use Apps\Model\Admin\Main\FormSettings;
8
use Extend\Core\Arch\AdminAppController;
9
use Ffcms\Core\App;
10
use Ffcms\Core\Exception\SyntaxException;
11
use Ffcms\Core\Helper\FileSystem\File;
12
use Ffcms\Core\Helper\Type\Arr;
13
use Ffcms\Core\Helper\Type\Integer;
14
use Ffcms\Core\Helper\Type\Str;
15
16
class Main extends AdminAppController
17
{
18
    public function __construct()
19
    {
20
        parent::__construct(false);
21
    }
22
23
    /**
24
     * Index page of admin dashboard
25
     */
26
    public function actionIndex()
27
    {
28
        $this->response = App::$View->render('index', [
29
30
        ]);
31
    }
32
33
    /**
34
     * Manage settings in web
35
     */
36 View Code Duplication
    public function actionSettings()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        $model = new FormSettings();
39
40
        if ($model->send()) {
41
            if ($model->validate()) {
42
                if ($model->makeSave()) {
43
                    // show message about successful save and take system some time ;)
44
                    $this->response = App::$View->render('settings_save');
45
                    return;
46
                } else {
47
                    App::$Session->getFlashBag()->add('error', __('Configuration file is not writable! Check /Private/Config/ dir and files'));
48
                }
49
            } else {
50
                App::$Session->getFlashBag()->add('error', __('Validation of form data is failed!'));
51
            }
52
        }
53
54
        $this->response = App::$View->render('settings', [
55
            'model' => $model // no $model->export() there
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
56
        ]);
57
    }
58
59
    /**
60
     * Manage files via elFinder
61
     */
62
    public function actionFiles()
63
    {
64
        $this->response = App::$View->render('files', [
65
            'connector' => App::$Alias->scriptUrl . '/api/main/files?lang=' . App::$Request->getLanguage()
66
        ]);
67
    }
68
69
    /**
70
     * Show antivirus
71
     */
72
    public function actionAntivirus()
73
    {
74
        $this->response = App::$View->render('antivirus');
75
    }
76
77
    public function actionDebugcookie()
78
    {
79
        $cookieProperty = App::$Properties->get('debug');
80
        //App::$Request->cookies->add([$cookieProperty['cookie']['key'] => $cookieProperty['cookie']['value']]); todo: fix me
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
81
        setcookie($cookieProperty['cookie']['key'], $cookieProperty['cookie']['value'], Integer::MAX, '/', null, null, true);
82
        App::$Response->redirect('/');
83
    }
84
85
    /**
86
     * List available routes
87
     * @throws \Ffcms\Core\Exception\SyntaxException
88
     */
89
    public function actionRouting()
90
    {
91
        $routingMap = App::$Properties->getAll('Routing');
92
93
        $this->response = App::$View->render('routing', [
94
            'routes' => $routingMap
95
        ]);
96
    }
97
98
    /**
99
     * Show add form for routing
100
     * @throws \Ffcms\Core\Exception\SyntaxException
101
     */
102
    public function actionAddroute()
103
    {
104
        $model = new FormAddRoute();
105
106
        if (!File::exist('/Private/Config/Routing.php') || !File::writable('/Private/Config/Routing.php')) {
107
            App::$Session->getFlashBag()->add('error', __('Routing configuration file is not allowed to write: /Private/Config/Routing.php'));
108
        } elseif ($model->send() && $model->validate()) {
109
            $model->save();
110
            App::$Response->redirect('main/routing');
111
        }
112
113
        $this->response = App::$View->render('add_route', [
114
            'model' => $model
115
        ]);
116
    }
117
118
    /**
119
     * Delete scheme route
120
     * @throws SyntaxException
121
     */
122
    public function actionDeleteroute()
123
    {
124
        $type = (string)App::$Request->query->get('type');
125
        $loader = (string)App::$Request->query->get('loader');
126
        $source = Str::lowerCase((string)App::$Request->query->get('path'));
127
128
        $model = new EntityDeleteRoute($type, $loader, $source);
129
        if ($model->send()) {
130
            $model->make();
131
            App::$Response->redirect('main/routing');
132
        }
133
134
        $this->response = App::$View->render('delete_route', [
135
            'model' => $model
136
        ]);
137
    }
138
}