MigrationController::getControllerName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/* Copyright (C) 2024       Rafael San José         <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace CoreModules\Admin\Controller;
20
21
use Alxarafe\Base\Config;
22
use Alxarafe\Base\Controller\ViewController;
23
use Alxarafe\Base\Database;
24
use Alxarafe\Lib\Messages;
25
use Alxarafe\Lib\Trans;
26
27
/**
28
 * Class ConfigController. App settings controller.
29
 */
30
class MigrationController extends ViewController
31
{
32
    const MENU = 'admin|migrations';
33
34
    /**
35
     * Returns the module name for use in url function
36
     *
37
     * @return string
38
     */
39
    public static function getModuleName(): string
40
    {
41
        return 'Admin';
42
    }
43
44
    /**
45
     * Returns the controller name for use in url function
46
     *
47
     * @return string
48
     */
49
    public static function getControllerName(): string
50
    {
51
        return 'Migration';
52
    }
53
54
    public function doGetProcesses(): void
55
    {
56
        $this->template = null;
57
        $migrations = array_merge(Config::getMigrations());
58
        $result = [];
59
        foreach ($migrations as $key => $migration) {
60
            $data = explode("@", $key);
61
            if (count($data) < 2) {
62
                continue;
63
            }
64
            $class = $data[0];
65
            $module = $data[1];
66
            $result[] = [
67
                'class' => $class,
68
                'module' => $module,
69
                'migration' => $migration,
70
                'message' => Trans::_('processing_migration', ['name' => $module . '::' . $class]),
71
            ];
72
        }
73
        die(json_encode($result));
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
74
    }
75
76
    public function doExecuteProcess(): void
77
    {
78
        $this->template = null;
79
        $result = [
80
            'status' => 'success',
81
            'message' => 'Processed successfully ' . $_POST['module'] . '::' . $_POST['class']
82
        ];
83
        die(json_encode($result));
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
84
    }
85
86
    public function doRunMigrationsAndSeeders(): bool
87
    {
88
        dd($this->data);
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist on CoreModules\Admin\Controller\MigrationController. Did you maybe forget to declare it?
Loading history...
89
        new Database($this->data->db);
90
91
92
        Config::runMigrations();
93
        Config::runSeeders();
94
95
        return true;
96
    }
97
98
    public function doExit()
99
    {
100
        /**
101
         * TODO: Loads public page
102
         */
103
        $this->template = 'page/public';
104
        return true;
105
    }
106
}
107