Skip to content

Commit

Permalink
Fix raw SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmr committed Nov 25, 2024
1 parent 0603008 commit f0bd482
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ function plugin_resources_uninstall()
];

foreach ($tables as $table) {
$DB->query("DROP TABLE IF EXISTS `$table`;");
$DB->dropTable($table);
}

//old versions
Expand All @@ -726,7 +726,7 @@ function plugin_resources_uninstall()
];

foreach ($tables as $table) {
$DB->query("DROP TABLE IF EXISTS `$table`;");
$DB->dropTable($table);
}

$tables = [
Expand Down
35 changes: 22 additions & 13 deletions inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
]);
}
}
}
Expand All @@ -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'];
}
Expand Down

0 comments on commit f0bd482

Please sign in to comment.