From 7624d9907015083a0633ed4144342429f449ccb5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 18 Jul 2018 17:47:40 +0200 Subject: [PATCH] Use subquery filters for contacts if appropriate refs #2934 --- .../Backend/Ido/Query/HostcontactQuery.php | 26 +++++++++++++++++++ .../Backend/Ido/Query/ServicecontactQuery.php | 20 ++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcontactQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcontactQuery.php index 85f5d0457..fade4ed3f 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcontactQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcontactQuery.php @@ -17,6 +17,11 @@ class HostcontactQuery extends IdoQuery protected $groupOrigin = ['contactgroups', 'hosts', 'services']; + protected $subQueryTargets = [ + 'hostgroups' => 'hostgroup', + 'servicegroups' => 'servicegroup' + ]; + protected $columnMap = [ 'contactgroups' => [ 'contactgroup' => 'cgo.name1 COLLATE latin1_general_ci', @@ -189,6 +194,8 @@ class HostcontactQuery extends IdoQuery */ protected function joinServices() { + $this->joinHosts(); + $this->select->joinLeft( ['s' => $this->prefix . 'services'], 's.host_object_id = ho.object_id', @@ -216,4 +223,23 @@ class HostcontactQuery extends IdoQuery [] ); } + + protected function joinSubQuery(IdoQuery $query, $name, $filter, $and, $negate, &$additionalFilter) + { + if ($name === 'hostgroup') { + $this->requireVirtualTable('hosts'); + + $query->joinVirtualTable('members'); + + return ['hgm.host_object_id', 'ho.object_id']; + } elseif ($name === 'servicegroup') { + $this->requireVirtualTable('services'); + + $query->joinVirtualTable('members'); + + return ['sgm.service_object_id', 'so.object_id']; + } + + return parent::joinSubQuery($query, $name, $filter, $and, $negate, $additionalFilter); + } } diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecontactQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecontactQuery.php index d667e0d9e..5ab787ebe 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecontactQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecontactQuery.php @@ -17,6 +17,11 @@ class ServicecontactQuery extends IdoQuery protected $groupOrigin = ['contactgroups', 'hosts', 'services']; + protected $subQueryTargets = [ + 'hostgroups' => 'hostgroup', + 'servicegroups' => 'servicegroup' + ]; + protected $columnMap = [ 'contactgroups' => [ 'contactgroup' => 'cgo.name1 COLLATE latin1_general_ci', @@ -212,4 +217,19 @@ class ServicecontactQuery extends IdoQuery [] ); } + + protected function joinSubQuery(IdoQuery $query, $name, $filter, $and, $negate, &$additionalFilter) + { + if ($name === 'hostgroup') { + $query->joinVirtualTable('members'); + + return ['hgm.host_object_id', 's.host_object_id']; + } elseif ($name === 'servicegroup') { + $query->joinVirtualTable('members'); + + return ['sgm.service_object_id', 'so.object_id']; + } + + return parent::joinSubQuery($query, $name, $filter, $and, $negate, $additionalFilter); + } }