Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
fix(mqttlog): logs may show the latest date but an old value for a topic
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Oct 20, 2018
1 parent aeea7f0 commit ad9bdf8
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions inc/mqttlog.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,20 +218,23 @@ public static function showMqttLogs(PluginFlyvemdmNotifiableInterface $item) {
public static function findLogs(PluginFlyvemdmNotifiableInterface $item) {
global $DB;

if (version_compare(GLPI_VERSION, '9.3.1') >= 0) {
$condition = [
'FIELDS' => ['id', 'MAX' => ['date as date'], 'topic', 'message'],
'WHERE' => ['itemtype' => $item::getType(), 'items_id' => $item->getID()],
'GROUPBY' => 'topic',
];
$result = $DB->request(static::getTable(), $condition);
} else {
$result = $DB->query("SELECT id, MAX(date) as date, topic, message
FROM " . static::getTable() . "
WHERE itemtype='" . $item::getType() . "' AND items_id = '" . $item->getID() . "'
GROUP BY topic
");
}
// Need this PR to avoid raw SQL
// https://github.com/glpi-project/glpi/pull/4812

$table = self::getTable();
$itemtype = $item->getType();
$itemId = $item->getID();
$result = $DB->request("SELECT `l1`.*
FROM `$table` AS `l1` INNER JOIN
(SELECT MAX(`date`) AS `maxdate`, `topic`
FROM `$table`
WHERE `itemtype` = '$itemtype' AND `items_id` = '$itemId'
GROUP BY `topic`
) AS `l2`
ON `l1`.`topic` = `l2`.`topic` AND `l1`.`date` = `l2`.`maxdate`
WHERE `itemtype`='$itemtype' AND `items_id` = '$itemId'
GROUP BY `topic`");

return $result;
}
}

0 comments on commit ad9bdf8

Please sign in to comment.