mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix device_groups in alert/group builder (#10643)
This commit is contained in:
@@ -430,7 +430,8 @@ class QueryBuilderParser implements \JsonSerializable
|
||||
}
|
||||
|
||||
if (!$this->schema->columnExists($child, $child_key)) {
|
||||
echo"FIXME: Could not make glue from $child to $parent\n";
|
||||
$child_key = $this->schema->getPrimaryKey($child);
|
||||
\Log::warning("QueryBuilderParser: Warning, guessing glue from $child.$child_key to $parent.$parent_key");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -89,19 +89,14 @@ class Schema
|
||||
* Get the primary key column(s) for a table
|
||||
*
|
||||
* @param string $table
|
||||
* @return string|array if a single column just the name is returned, otherwise an array of column names
|
||||
* @return string if a single column just the name is returned, otherwise the first column listed will be returned
|
||||
*/
|
||||
public function getPrimaryKey($table)
|
||||
{
|
||||
$schema = $this->getSchema();
|
||||
|
||||
$columns = $schema[$table]['Indexes']['PRIMARY']['Columns'];
|
||||
|
||||
if (count($columns) == 1) {
|
||||
return reset($columns);
|
||||
}
|
||||
|
||||
return $columns;
|
||||
return reset($columns);
|
||||
}
|
||||
|
||||
public function getSchema()
|
||||
|
||||
@@ -180,4 +180,12 @@
|
||||
"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"]]
|
||||
]
|
||||
,
|
||||
[
|
||||
"%device_groups.id = 1",
|
||||
{"condition":"AND","rules":[{"id":"device_groups.id","field":"device_groups.id","type":"string","input":"text","operator":"equal","value":"1"}],"valid":true},
|
||||
"device_groups.id = 1",
|
||||
"SELECT * FROM devices,device_group_device,device_groups WHERE (devices.device_id = ? AND devices.device_id = device_group_device.device_id AND device_group_device.device_group_id = device_groups.id) AND device_groups.id = 1",
|
||||
["select * from `devices` left join `device_group_device` on `devices`.`device_id` = `device_group_device`.`device_id` left join `device_groups` on `device_group_device`.`device_group_id` = `device_groups`.`id` where (`device_groups`.`id` = ?)", ["1"]]
|
||||
]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user