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 6e835c4 commit 03ff657
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 @@ -272,7 +272,7 @@ function plugin_mydashboard_install()
$DB->runFile(PLUGIN_MYDASHBOARD_DIR . "/install/sql/update-2.0.9.sql");
$mig->executeMigration();

if ($DB->fieldExists("glpi_plugin_mydashboard_configs", "display_plugin_widget")) {
if (!$DB->fieldExists("glpi_plugin_mydashboard_preferences", "prefered_category")) {
$mig = new Migration("2.1.2");
$DB->runFile(PLUGIN_MYDASHBOARD_DIR . "/install/sql/update-2.1.2.sql");
$mig->executeMigration();
Expand Down Expand Up @@ -470,7 +470,7 @@ function plugin_mydashboard_uninstall()
"glpi_plugin_mydashboard_stockticketindicators"];

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

include_once(PLUGIN_MYDASHBOARD_DIR . "/inc/profile.class.php");
Expand Down
35 changes: 22 additions & 13 deletions inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,14 @@ public static function initProfile()
}
}

foreach ($DB->request("SELECT *
FROM `glpi_profilerights`
WHERE `profiles_id`='" . $_SESSION['glpiactiveprofile']['id'] . "'
AND `name` LIKE '%plugin_mydashboard%'") as $prof) {
$it = $DB->request([
'FROM' => 'glpi_profilerights',
'WHERE' => [
'profiles_id' => $_SESSION['glpiactiveprofile']['id'],
'name' => ['LIKE', '%plugin_mydashboard%']
]
]);
foreach ($it as $prof) {
if (isset($_SESSION['glpiactiveprofile'])) {
$_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights'];
}
Expand Down Expand Up @@ -335,19 +339,20 @@ private static function migrateOneProfile($profiles_id)
return true;
}

foreach ($DB->request(
'glpi_plugin_mydashboard_profiles',
"`profiles_id`='$profiles_id'"
) as $profile_data) {
$it = $DB->request([
'FROM' => 'glpi_plugin_mydashboard_profiles',
'WHERE' => ['profiles_id' => $profiles_id]
]);
foreach ($it as $profile_data) {
$matching = ['mydashboard' => 'plugin_mydashboard',
'config' => 'plugin_mydashboard_config'];
$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 @@ -361,7 +366,11 @@ public static function migrateRightsFrom84To85()
{
global $DB;
//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']);
}
}
Expand Down

0 comments on commit 03ff657

Please sign in to comment.