mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix device group queries that don't start with devices table (#10360)
This commit is contained in:
@ -176,8 +176,11 @@ class QueryBuilderFluentParser extends QueryBuilderParser
|
||||
foreach ($this->generateGlue() as $glue) {
|
||||
list($left, $right) = explode(' = ', $glue, 2);
|
||||
if (str_contains($right, '.')) { // last line is devices.device_id = ? for alerting... ignore it
|
||||
list($leftTable, $leftKey) = explode('.', $left);
|
||||
list($rightTable, $rightKey) = explode('.', $right);
|
||||
$joins[] = [$rightTable, $left, $right];
|
||||
$target_table = ($rightTable != 'devices' ? $rightTable : $leftTable); // don't try to join devices
|
||||
|
||||
$joins[] = [$target_table, $left, $right];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,5 +172,12 @@
|
||||
"devices.hostname LIKE '%one%' AND (devices.hostname LIKE '%two%' OR devices.hostname LIKE '%three%' OR (devices.hostname LIKE 'six%' AND devices.hostname = \"seven\")) AND (devices.hostname NOT LIKE '%four%' OR devices.hostname NOT LIKE '%five%')",
|
||||
"SELECT * FROM devices WHERE (devices.device_id = ?) AND devices.hostname LIKE '%one%' AND (devices.hostname LIKE '%two%' OR devices.hostname LIKE '%three%' OR (devices.hostname LIKE 'six%' AND devices.hostname = \"seven\")) AND (devices.hostname NOT LIKE '%four%' OR devices.hostname NOT LIKE '%five%')",
|
||||
["select * from `devices` where (`devices`.`hostname` LIKE ? AND (`devices`.`hostname` LIKE ? OR `devices`.`hostname` LIKE ? OR (`devices`.`hostname` LIKE ? AND `devices`.`hostname` = ?)) AND (`devices`.`hostname` NOT LIKE ? OR `devices`.`hostname` NOT LIKE ?))", ["%one%","%two%","%three%","six%","seven","%four%","%five%"]]
|
||||
],
|
||||
[
|
||||
"%locations.location ~ somewhere",
|
||||
{"condition":"AND","rules":[{"id":"locations.location","field":"locations.location","type":"string","input":"text","operator":"regex","value":"somewhere"}],"valid":true},
|
||||
"locations.location REGEXP \"somewhere\"",
|
||||
"SELECT * FROM locations,devices WHERE (devices.device_id = ? AND locations.id = devices.location_id) AND locations.location REGEXP \"somewhere\"",
|
||||
["select * from `devices` left join `locations` on `locations`.`id` = `devices`.`location_id` where (`locations`.`location` REGEXP ?)", ["somewhere"]]
|
||||
]
|
||||
]
|
||||
|
Reference in New Issue
Block a user