Use subquery filters for contacts if appropriate

refs #2934
This commit is contained in:
Eric Lippmann 2018-07-18 17:47:40 +02:00
parent c168ebfe3a
commit 7624d99070
2 changed files with 46 additions and 0 deletions

View File

@ -17,6 +17,11 @@ class HostcontactQuery extends IdoQuery
protected $groupOrigin = ['contactgroups', 'hosts', 'services']; protected $groupOrigin = ['contactgroups', 'hosts', 'services'];
protected $subQueryTargets = [
'hostgroups' => 'hostgroup',
'servicegroups' => 'servicegroup'
];
protected $columnMap = [ protected $columnMap = [
'contactgroups' => [ 'contactgroups' => [
'contactgroup' => 'cgo.name1 COLLATE latin1_general_ci', 'contactgroup' => 'cgo.name1 COLLATE latin1_general_ci',
@ -189,6 +194,8 @@ class HostcontactQuery extends IdoQuery
*/ */
protected function joinServices() protected function joinServices()
{ {
$this->joinHosts();
$this->select->joinLeft( $this->select->joinLeft(
['s' => $this->prefix . 'services'], ['s' => $this->prefix . 'services'],
's.host_object_id = ho.object_id', '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);
}
} }

View File

@ -17,6 +17,11 @@ class ServicecontactQuery extends IdoQuery
protected $groupOrigin = ['contactgroups', 'hosts', 'services']; protected $groupOrigin = ['contactgroups', 'hosts', 'services'];
protected $subQueryTargets = [
'hostgroups' => 'hostgroup',
'servicegroups' => 'servicegroup'
];
protected $columnMap = [ protected $columnMap = [
'contactgroups' => [ 'contactgroups' => [
'contactgroup' => 'cgo.name1 COLLATE latin1_general_ci', '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);
}
} }