Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Fix sql query. references #1807
Browse files Browse the repository at this point in the history
  • Loading branch information
David Durieux committed May 17, 2016
1 parent 3fc8d1f commit 5e5d1f6
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions install/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -5837,19 +5837,18 @@ function plugin_fusioninventory_displayMigrationMessage ($id, $msg="") {
function changeDisplayPreference($olditemtype, $newitemtype) {
global $DB;

$query = "SELECT `users_id`, `num`, count(*) as `cnt` FROM `glpi_displaypreferences`
$query = "SELECT `users_id`, `num`, count(*) as `cnt`, GROUP_CONCAT( id SEPARATOR ' ') as id
FROM `glpi_displaypreferences`
WHERE (`itemtype` = '".$newitemtype."'
OR `itemtype` = '".$olditemtype."')
group by `users_id`, `num`";
$result=$DB->query($query);
while ($data=$DB->fetch_array($result)) {
if ($data['cnt'] > 1) {
$ids = explode(' ', $data['id']);
array_shift($ids);
$queryd = "DELETE FROM `glpi_displaypreferences`
WHERE (`itemtype` = '".$newitemtype."'
OR `itemtype` = '".$olditemtype."') "
. " AND `users_id`='".$data['users_id']."'"
. " AND `num`='".$data['num']."'"
. " LIMIT 1, 100";
WHERE `id` IN ('".implode("', '", $ids)."')";
$DB->query($queryd);
}
}
Expand Down Expand Up @@ -7670,19 +7669,18 @@ function update213to220_ConvertField($migration) {
function pluginFusioninventorychangeDisplayPreference($olditemtype, $newitemtype) {
global $DB;

$query = "SELECT `users_id`, `num`, count(*) as `cnt` FROM `glpi_displaypreferences`
$query = "SELECT `users_id`, `num`, count(*) as `cnt`, GROUP_CONCAT( id SEPARATOR ' ') as id
FROM `glpi_displaypreferences`
WHERE (`itemtype` = '".$newitemtype."'
OR `itemtype` = '".$olditemtype."')
group by `users_id`, `num`";
$result=$DB->query($query);
while ($data=$DB->fetch_array($result)) {
if ($data['cnt'] > 1) {
$ids = explode(' ', $data['id']);
array_shift($ids);
$queryd = "DELETE FROM `glpi_displaypreferences`
WHERE (`itemtype` = '".$newitemtype."'
OR `itemtype` = '".$olditemtype."') "
. " AND `users_id`='".$data['users_id']."'"
. " AND `num`='".$data['num']."'"
. " LIMIT 1, 100";
WHERE `id` IN ('".implode("', '", $ids)."')";
$DB->query($queryd);
}
}
Expand Down

0 comments on commit 5e5d1f6

Please sign in to comment.