1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2022-2023 Rafael San José Tovar <[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
|
|
|
* (at your option) 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 Alxarafe\Controllers; |
20
|
|
|
|
21
|
|
|
use Alxarafe\Core\Base\BasicController; |
22
|
|
|
use Alxarafe\Core\Base\View; |
23
|
|
|
use Alxarafe\Core\Singletons\Config; |
24
|
|
|
use Alxarafe\Views\ConfigView; |
25
|
|
|
use DebugBar\DebugBarException; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Controller for editing database and skin settings |
29
|
|
|
* |
30
|
|
|
* @package Alxarafe\Controllers |
31
|
|
|
*/ |
32
|
|
|
class EditConfig extends BasicController |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Save the form changes in the configuration file |
36
|
|
|
* |
37
|
|
|
* @return bool |
38
|
|
|
*/ |
39
|
|
|
public function doSave(): bool |
40
|
|
|
{ |
41
|
|
|
$config = Config::getInstance(); |
|
|
|
|
42
|
|
|
$config->setVar('constants', 'boolean', 'DEBUG', isset($_POST['debug'])); |
43
|
|
|
$config->setVar('translator', 'main', 'language', $_POST['language'] ?? 'en'); |
44
|
|
|
$config->setVar('templaterender', 'main', 'skin', $_POST['skin'] ?? 'default'); |
45
|
|
|
$config->setVar('database', 'main', 'dbEngineName', $_POST['dbEngineName'] ?? ''); |
46
|
|
|
$config->setVar('database', 'main', 'dbUser', $_POST['dbUser'] ?? ''); |
47
|
|
|
$config->setVar('database', 'main', 'dbPass', $_POST['dbPass'] ?? ''); |
48
|
|
|
$config->setVar('database', 'main', 'dbName', $_POST['dbName'] ?? ''); |
49
|
|
|
$config->setVar('database', 'main', 'dbHost', $_POST['dbHost'] ?? ''); |
50
|
|
|
$config->setVar('database', 'main', 'dbPort', $_POST['dbPort'] ?? ''); |
51
|
|
|
$config->setVar('database', 'main', 'dbPrefix', $_POST['dbPrefix'] ?? ''); |
52
|
|
|
|
53
|
|
|
$result = $config->connectToDatabase(); |
54
|
|
|
if (!$result) { |
55
|
|
|
$this->flashMessages->setError('database_not_found', 'next'); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$result = $config->saveConfigFile(); |
59
|
|
|
if ($result) { |
60
|
|
|
$this->flashMessages->setSuccess('saved', 'next'); |
61
|
|
|
header('location: ' . self::url('Main', 'EditConfig')); |
62
|
|
|
die(); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $result; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @throws DebugBarException |
70
|
|
|
*/ |
71
|
|
|
public function setView(): View |
72
|
|
|
{ |
73
|
|
|
return new ConfigView($this); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.