IcingaObjectResolver: support PostgreSQL

This commit is contained in:
Thomas Gelf 2020-02-12 10:59:38 +01:00
parent 421f47d08d
commit babae3e068
1 changed files with 7 additions and 5 deletions

View File

@ -178,18 +178,20 @@ class IcingaObjectResolver
*/
protected function fetchInheritancePaths($baseTable, $relColumn)
{
// select host_id, GROUP_CONCAT(parent_host_id ORDER BY weight) FROM icinga_host_inheritance group by host_id;
if ($this->db instanceof \Zend_Db_Adapter_Pdo_Pgsql) {
$groupColumn = "ARRAY_TO_STRING(ARRAY_AGG(parent_$relColumn ORDER BY weight), ',')";
} else {
$groupColumn = "GROUP_CONCAT(parent_$relColumn ORDER BY weight SEPARATOR ',')";
}
$query = $this->db->select()
->from([
'oi' => "${baseTable}_inheritance"
], [
$relColumn,
"GROUP_CONCAT(parent_$relColumn ORDER BY weight SEPARATOR ',')"
$groupColumn
])
->group($relColumn)
->order("LENGTH(GROUP_CONCAT(parent_$relColumn ORDER BY weight SEPARATOR ','))");
// pgsql: ARRAY_TO_STRING(ARRAY_AGG(---), ',') -> order?
->order("LENGTH($groupColumn)");
return $this->db->fetchPairs($query);
}