|
1 | 1 | <?php
|
2 | 2 | /* For licensing terms, see /license.txt */
|
3 | 3 |
|
| 4 | +use Doctrine\DBAL\Configuration; |
| 5 | +use Doctrine\DBAL\DriverManager; |
| 6 | + |
4 | 7 | api_protect_admin_script();
|
5 | 8 |
|
6 | 9 | $sql = "SELECT * FROM vchamilo";
|
|
34 | 37 |
|
35 | 38 | foreach ($vchamilos as $chm) {
|
36 | 39 | $table = $chm['main_database'].".settings_current ";
|
37 |
| - $sql = " SELECT * FROM $table |
38 |
| - WHERE |
39 |
| - variable = '{{$setting['variable']}}' AND |
| 40 | + $sql = " SELECT * FROM $table |
| 41 | + WHERE |
| 42 | + variable = '{{$setting['variable']}}' AND |
40 | 43 | access_url = '{$setting['access_url']}'
|
41 | 44 | ";
|
42 | 45 | $result = Database::query($sql);
|
43 | 46 |
|
44 | 47 | if (Database::num_rows($result)) {
|
45 |
| - $sql = "UPDATE $table SET |
46 |
| - selected_value = '$value' |
47 |
| - WHERE id = $settingId"; |
48 |
| - Database::query($sql); |
| 48 | + Database::update($table, ['selected_Value' => $value, ['id' => $settingId]]); |
49 | 49 | }
|
50 | 50 | }
|
51 | 51 | }
|
52 | 52 | break;
|
53 | 53 | case 'syncthis':
|
54 |
| - $settingId = isset($_GET['settingid']) ? (int) $_GET['settingid'] : ''; |
| 54 | + $settingId = isset($_GET['settingid']) ? (int) $_GET['settingid'] : 0; |
55 | 55 |
|
56 |
| - if (!empty($settingId) && is_numeric($settingId)) { |
57 |
| - $deleteIfEmpty = isset($_REQUEST['del']) ? $_REQUEST['del'] : ''; |
| 56 | + if ($settingId) { |
| 57 | + $deleteIfEmpty = $_REQUEST['del'] ?? ''; |
58 | 58 | $value = $_REQUEST['value'];
|
59 | 59 | // Getting the local setting record.
|
60 | 60 | $setting = api_get_settings_params_simple(['id = ?' => $settingId]);
|
|
76 | 76 | $errors = '';
|
77 | 77 | foreach ($vchamilos as $instance) {
|
78 | 78 | $table = 'settings_current';
|
79 |
| - $config = new \Doctrine\DBAL\Configuration(); |
| 79 | + $config = new Configuration(); |
80 | 80 | $connectionParams = [
|
81 | 81 | 'dbname' => $instance['main_database'],
|
82 | 82 | 'user' => $instance['db_user'],
|
83 | 83 | 'password' => $instance['db_password'],
|
84 | 84 | 'host' => $instance['db_host'],
|
85 | 85 | 'driver' => 'pdo_mysql',
|
86 | 86 | ];
|
87 |
| - $connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); |
88 | 87 | try {
|
| 88 | + $connection = DriverManager::getConnection($connectionParams, $config); |
| 89 | + |
89 | 90 | $variable = $setting['variable'];
|
90 | 91 | $subKey = $setting['subkey'];
|
91 | 92 | $category = $setting['category'];
|
92 | 93 | $accessUrl = $setting['access_url'];
|
93 | 94 |
|
94 | 95 | if ($deleteIfEmpty && empty($value)) {
|
95 |
| - $sql = "DELETE FROM $table |
96 |
| - WHERE |
97 |
| - selected_value = '$value' AND |
98 |
| - variable = '$variable' AND |
99 |
| - access_url = '$accessUrl' |
100 |
| - "; |
101 |
| - $connection->executeQuery($sql); |
| 96 | + $connection->delete($table, ['selected_value' => $value, 'variable' => $variable, 'access_url' => $accessUrl]); |
102 | 97 | $case = 'delete';
|
103 | 98 | } else {
|
104 |
| - $sql = "SELECT * FROM $table |
105 |
| - WHERE |
106 |
| - variable = '$variable' AND |
| 99 | + $sql = "SELECT * FROM $table |
| 100 | + WHERE |
| 101 | + variable = '$variable' AND |
107 | 102 | access_url = '$accessUrl'
|
108 | 103 | ";
|
109 |
| - $result = $connection->fetchAll($sql); |
| 104 | + $result = $connection->fetchAllAssociative($sql); |
110 | 105 |
|
111 | 106 | if (!empty($result)) {
|
112 | 107 | //$sql = "UPDATE $table SET selected_value = '$value' WHERE id = $settingId";
|
113 |
| - $sql = "UPDATE $table SET selected_value = '$value' WHERE variable = '$variable'"; |
| 108 | + $criteria = ['variable' => $variable]; |
114 | 109 | if (!empty($subKey)) {
|
115 |
| - $sql .= " AND subkey = '$subKey' "; |
| 110 | + $criteria['subkey'] = $subKey; |
116 | 111 | }
|
117 | 112 | if (!empty($category)) {
|
118 |
| - $sql .= " AND category = '$category'"; |
| 113 | + $criteria['category'] = $category; |
119 | 114 | }
|
120 |
| - $connection->executeQuery($sql); |
| 115 | + $connection->update($table, ['selected_value' => $value], $criteria); |
121 | 116 | } else {
|
122 | 117 | $connection->insert($table, $params);
|
123 | 118 | }
|
|
0 commit comments