Skip to content

Commit

Permalink
Drop Raw SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmr committed Nov 25, 2024
1 parent 6deb300 commit 37326b1
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,19 @@ public static function migrateOneProfile($profiles_id)
return true;
}

foreach ($DB->request(
'glpi_plugin_timelineticket_profiles',
"`profiles_id`='$profiles_id'"
) as $profile_data) {
$it = $DB->request([
'FROM' => 'glpi_plugin_timelineticket_profiles',
'WHERE' => ['profiles_id' => $profiles_id]
]);
foreach ($it as $profile_data) {
$matching = ['timelineticket' => 'plugin_timelineticket_ticket'];
$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 @@ -273,13 +274,22 @@ 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_timelineticket_%'") as $prof) {

$it = $DB->request([
'FROM' => 'glpi_profilerights',
'WHERE' => [
'profiles_id' => $_SESSION['glpiactiveprofile']['id'],
'name' => ['LIKE', '%plugin_timelineticket%']
]
]);
foreach ($it as $prof) {
if (isset($_SESSION['glpiactiveprofile'])) {
$_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights'];
}
Expand Down

0 comments on commit 37326b1

Please sign in to comment.