Test Failed
Branch main (345e92)
by Rafael
08:42
created

MigrationController::doExecuteProcess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
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\Trans;
25
26
/**
27
 * Class ConfigController. App settings controller.
28
 */
29
class MigrationController extends ViewController
30
{
31
    const MENU = 'admin|migrations';
32
33
    /**
34
     * Returns the module name for use in url function
35
     *
36
     * @return string
37
     */
38
    public static function getModuleName(): string
39
    {
40
        return 'Admin';
41
    }
42
43
    /**
44
     * Returns the controller name for use in url function
45
     *
46
     * @return string
47
     */
48
    public static function getControllerName(): string
49
    {
50
        return 'Migration';
51
    }
52
53
    public function doGetProcesses(): void
54
    {
55
        $this->template = null;
56
        $migrations = array_merge(Config::getMigrations());
57
        $result = [];
58
        foreach ($migrations as $key => $migration) {
59
            $data = explode("@", $key);
60
            if (count($data) < 2) {
61
                continue;
62
            }
63
            $class = $data[0];
64
            $module = $data[1];
65
            $result[] = [
66
                'class' => $class,
67
                'module' => $module,
68
                'migration' => $migration,
69
                'message' => Trans::_('processing_migration', ['name' => $module . '::' . $class]),
70
            ];
71
        }
72
        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...
73
    }
74
75
    public function doExecuteProcess(): void
76
    {
77
        $this->template = null;
78
        $result = [
79
            'status' => 'success',
80
            'message' => 'Processed successfully ' . $_POST['module'] . '::' . $_POST['class']
81
        ];
82
        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...
83
    }
84
85
    public function doRunMigrationsAndSeeders(): bool
86
    {
87
        dump($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...
88
        new Database($this->data->db);
89
90
        Config::runMigrations();
91
        Config::runSeeders();
92
93
        return true;
94
    }
95
96
    public function doExit()
97
    {
98
        /**
99
         * TODO: Loads public page
100
         */
101
        $this->template = 'page/public';
102
        return true;
103
    }
104
}
105