|
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)); |
|
|
|
|
|
|
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)); |
|
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function doRunMigrationsAndSeeders(): bool |
|
86
|
|
|
{ |
|
87
|
|
|
dump($this->data); |
|
|
|
|
|
|
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
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.