Tables: fix host/service blacklist queries

This commit is contained in:
Thomas Gelf 2018-05-25 18:27:05 +02:00
parent 8073128d0e
commit 35f1f09b84
2 changed files with 19 additions and 3 deletions

View File

@ -74,6 +74,10 @@ class IcingaHostAppliedServicesTable extends SimpleQueryBasedTable
], $attributes); ], $attributes);
} }
/**
* @return \Icinga\Data\SimpleQuery
* @throws \Icinga\Exception\IcingaException
*/
public function prepareQuery() public function prepareQuery()
{ {
$services = []; $services = [];
@ -94,6 +98,10 @@ class IcingaHostAppliedServicesTable extends SimpleQueryBasedTable
]); ]);
} }
/***
* @return array
* @throws \Icinga\Exception\IcingaException
*/
protected function getAllApplyRules() protected function getAllApplyRules()
{ {
if ($this->allApplyRules === null) { if ($this->allApplyRules === null) {
@ -106,6 +114,10 @@ class IcingaHostAppliedServicesTable extends SimpleQueryBasedTable
return $this->allApplyRules; return $this->allApplyRules;
} }
/**
* @return array
* @throws \Icinga\Exception\IcingaException
*/
protected function fetchAllApplyRules() protected function fetchAllApplyRules()
{ {
$db = $this->db; $db = $this->db;
@ -119,7 +131,7 @@ class IcingaHostAppliedServicesTable extends SimpleQueryBasedTable
] ]
)->joinLeft( )->joinLeft(
['hsb' => 'icinga_host_service_blacklist'], ['hsb' => 'icinga_host_service_blacklist'],
's.id = hsb.service_id', $db->quoteInto('s.id = hsb.service_id AND hsb.host_id = ?', $this->host->get('id')),
[] []
)->group('s.id')->where('object_type = ? AND assign_filter IS NOT NULL', 'apply'); )->group('s.id')->where('object_type = ? AND assign_filter IS NOT NULL', 'apply');

View File

@ -185,7 +185,8 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable
*/ */
public function prepareQuery() public function prepareQuery()
{ {
$query = $this->db()->select()->from( $db = $this->db();
$query = $db->select()->from(
['s' => 'icinga_service'], ['s' => 'icinga_service'],
[ [
'id' => 's.id', 'id' => 's.id',
@ -208,7 +209,10 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable
if ($this->affectedHost) { if ($this->affectedHost) {
$query->joinLeft( $query->joinLeft(
['hsb' => 'icinga_host_service_blacklist'], ['hsb' => 'icinga_host_service_blacklist'],
's.id = hsb.service_id', $db->quoteInto(
's.id = hsb.service_id AND hsb.host_id = ?',
$this->affectedHost->get('id')
),
[] []
)->group('s.id')->columns([ )->group('s.id')->columns([
'blacklisted' => "CASE WHEN hsb.service_id IS NULL THEN 'n' ELSE 'y' END", 'blacklisted' => "CASE WHEN hsb.service_id IS NULL THEN 'n' ELSE 'y' END",