From 49e95b9d03e10b3041ef7675755a8da8668c262a Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Mon, 26 Feb 2018 10:04:14 +0100 Subject: [PATCH] Virtual plugin: Fix sync params using key instead of id see BT#13996 At some point the other instance can have different ids, better to use the string identifiers (variable, subkey, category) to update. --- .../vchamilo/views/syncparams.controller.php | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/plugin/vchamilo/views/syncparams.controller.php b/plugin/vchamilo/views/syncparams.controller.php index 44bc842625..1ffd40299c 100644 --- a/plugin/vchamilo/views/syncparams.controller.php +++ b/plugin/vchamilo/views/syncparams.controller.php @@ -22,8 +22,7 @@ switch ($action) { } $value = $_REQUEST[$selkey]; - - $setting = api_get_settings_params_simple(['id' => $settingId]); + $setting = api_get_settings_params_simple(['id = ?' => $settingId]); $params = [ 'title' => $setting['title'], @@ -48,18 +47,17 @@ switch ($action) { WHERE id = $settingId"; Database::query($sql); } - //$DB->set_field('settings_current', 'selected_value', $value, $params, 'id', $chm->main_database); } } break; case 'syncthis': - $settingId = isset($_GET['settingid']) ? $_GET['settingid'] : ''; + $settingId = isset($_GET['settingid']) ? (int) $_GET['settingid'] : ''; - if (is_numeric($settingId)) { + if (!empty($settingId) && is_numeric($settingId)) { $deleteIfEmpty = isset($_REQUEST['del']) ? $_REQUEST['del'] : ''; $value = $_REQUEST['value']; // Getting the local setting record. - $setting = api_get_settings_params_simple(['id' => $settingId]); + $setting = api_get_settings_params_simple(['id = ?' => $settingId]); if (empty($setting)) { return 0; } @@ -88,25 +86,37 @@ switch ($action) { ]; $connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); try { + $variable = $setting['variable']; + $subKey = $setting['subkey']; + $category = $setting['category']; + $accessUrl = $setting['access_url']; + if ($deleteIfEmpty && empty($value)) { $sql = "DELETE FROM $table - WHERE - selected_value = '$value' AND - variable = '{{$setting['variable']}}' AND - access_url = '{$setting['access_url']}' + WHERE + selected_value = '$value' AND + variable = '$variable' AND + access_url = '$accessUrl' "; $connection->executeQuery($sql); $case = 'delete'; } else { $sql = "SELECT * FROM $table WHERE - variable = '".$setting['variable']."' AND - access_url = '{$setting['access_url']}' + variable = '$variable' AND + access_url = '$accessUrl' "; $result = $connection->fetchAll($sql); if (!empty($result)) { - $sql = "UPDATE $table SET selected_value = '$value' WHERE id = $settingId"; + //$sql = "UPDATE $table SET selected_value = '$value' WHERE id = $settingId"; + $sql = "UPDATE $table SET selected_value = '$value' WHERE variable = '$variable'"; + if (!empty($subKey)) { + $sql .= " AND subkey = '$subKey' "; + } + if (!empty($category)) { + $sql .= " AND category = '$category'"; + } $connection->executeQuery($sql); } else { $connection->insert($table, $params);