From 5e5d1f670d3b20536f145335e5002a1e2197155f Mon Sep 17 00:00:00 2001 From: David Durieux Date: Tue, 17 May 2016 16:15:34 +0200 Subject: [PATCH] Fix sql query. references #1807 --- install/update.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/install/update.php b/install/update.php index f6ffeca677..b6b808a80c 100644 --- a/install/update.php +++ b/install/update.php @@ -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); } } @@ -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); } }