From f0bd482f6dedd542c40f67ecd52c37d1578b36dd Mon Sep 17 00:00:00 2001 From: Thetsmr Date: Mon, 25 Nov 2024 13:49:58 +0100 Subject: [PATCH] Fix raw SQL --- hook.php | 4 ++-- inc/profile.class.php | 35 ++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/hook.php b/hook.php index 909d48c..9790345 100644 --- a/hook.php +++ b/hook.php @@ -707,7 +707,7 @@ function plugin_resources_uninstall() ]; foreach ($tables as $table) { - $DB->query("DROP TABLE IF EXISTS `$table`;"); + $DB->dropTable($table); } //old versions @@ -726,7 +726,7 @@ function plugin_resources_uninstall() ]; foreach ($tables as $table) { - $DB->query("DROP TABLE IF EXISTS `$table`;"); + $DB->dropTable($table); } $tables = [ diff --git a/inc/profile.class.php b/inc/profile.class.php index cfd2354..621c580 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -379,10 +379,11 @@ public static function migrateOneProfile($profiles_id) return true; } - foreach ($DB->request( - 'glpi_plugin_resources_profiles', - "`profiles_id`='$profiles_id'" - ) as $profile_data) { + $it = $DB->request([ + 'FROM' => 'glpi_plugin_resources_profiles', + 'WHERE' => ['profiles_id' => $profiles_id] + ]); + foreach ($it as $profile_data) { $matching = [ 'resources' => 'plugin_resources', 'task' => 'plugin_resources_task', @@ -402,10 +403,10 @@ public static function migrateOneProfile($profiles_id) $current_rights = ProfileRight::getProfileRights($profiles_id, array_values($matching)); foreach ($matching as $old => $new) { if (!isset($current_rights[$old])) { - $query = "UPDATE `glpi_profilerights` - SET `rights`='".self::translateARight($profile_data[$old])."' - WHERE `name`='$new' AND `profiles_id`='$profiles_id'"; - $DB->query($query); + $DB->update('glpi_profilerights', ['rights' => self::translateARight($profile_data[$old])], [ + 'name' => $new, + 'profiles_id' => $profiles_id + ]); } } } @@ -430,13 +431,21 @@ public static function initProfile() } //Migration old rights in new ones - foreach ($DB->request("SELECT `id` FROM `glpi_profiles`") as $prof) { + $it = $DB->request([ + 'SELECT' => ['id'], + 'FROM' => 'glpi_profiles' + ]); + foreach ($it as $prof) { self::migrateOneProfile($prof['id']); } - foreach ($DB->request("SELECT * - FROM `glpi_profilerights` - WHERE `profiles_id`='".$_SESSION['glpiactiveprofile']['id']."' - AND `name` LIKE '%plugin_resources%'") as $prof) { + $it = $DB->request([ + 'FROM' => 'glpi_profilerights', + 'WHERE' => [ + 'profiles_id' => $_SESSION['glpiactiveprofile']['id'], + 'name' => ['LIKE', '%plugin_resources%'] + ] + ]); + foreach ($it as $prof) { if (isset($_SESSION['glpiactiveprofile'])) { $_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights']; }