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 b45d580 commit d40588b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function plugin_positions_uninstall() {
"glpi_plugin_positions_configs"];

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

$rep_files_positions = GLPI_PLUGIN_DOC_DIR."/positions";
Expand All @@ -199,7 +199,7 @@ function plugin_positions_uninstall() {
"glpi_logs"];

foreach ($tables_glpi as $table_glpi) {
$DB->query("DELETE FROM `$table_glpi` WHERE `itemtype` = 'PluginPositionsPosition' ;");
$DB->delete($table_glpi, ['itemtype' => ['LIKE' => 'PluginPositionsPosition%']]);
}

//Delete rights associated with the plugin
Expand Down
35 changes: 23 additions & 12 deletions inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,19 @@ static function migrateOneProfile($profiles_id) {
return true;
}

foreach ($DB->request('glpi_plugin_positions_profiles',
"`profiles_id`='$profiles_id'") as $profile_data) {

$it = $DB->request([
'FROM' => 'glpi_plugin_positions_profiles',
'WHERE' => ['profiles_id' => $profiles_id]
]);
foreach ($it as $profile_data) {
$matching = ['positions' => 'plugin_positions'];
$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 @@ -252,13 +254,22 @@ 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_positions%'") as $prof) {

$it = $DB->request([
'FROM' => 'glpi_profilerights',
'WHERE' => [
'profiles_id' => $_SESSION['glpiactiveprofile']['id'],
'name' => ['LIKE', '%plugin_positions%']
]
]);
foreach ($it as $prof) {
$_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights'];
}
}
Expand Down
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function plugin_version_positions() {
'name' => _n('Cartography', 'Cartographies', 1, 'positions'),
'version' => PLUGIN_POSITIONS_VERSION,
'license' => 'GPLv2+',
'author' => "<a href='http://infotel.com/services/expertise-technique/glpi/'>Infotel</a>",
'author' => "<a href='https://blogglpi.infotel.com'>Infotel</a>",
'homepage' => 'https://github.com/InfotelGLPI/positions',
'requirements' => [
'glpi' => [
Expand Down

0 comments on commit d40588b

Please sign in to comment.