From 8702b455de8e241398251aef01b1225b627f7708 Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Thu, 19 Mar 2020 13:30:02 +0200 Subject: [PATCH] fix(api): extend ResourceRepositoryRDB::hasServiceSearch to check if host filters are used too Resolve MON-5026 --- .../Monitoring/ResourceRepositoryRDB.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php index 4ec182b56c6..98f03d6e15c 100644 --- a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php @@ -247,15 +247,27 @@ public function findResources(ResourceFilter $filter): array * * @return bool */ - private function hasServiceSearch() + private function hasServiceSearch(): bool + { + return $this->extractSpecificSearchCriteria('/^service\./') + && !$this->extractSpecificSearchCriteria('/^host\./'); + } + + /** + * Extract request parameters + * + * @param string $key + * @return bool + */ + private function extractSpecificSearchCriteria(string $key) { $requestParameters = $this->sqlRequestTranslator->getRequestParameters(); $search = $requestParameters->getSearch(); $serviceConcordances = array_reduce( array_keys($this->serviceConcordances), - function ($acc, $concordanceKey) { - if (preg_match('/^service\./', $concordanceKey)) { + function ($acc, $concordanceKey) use ($key) { + if (preg_match($key, $concordanceKey)) { $acc[] = $concordanceKey; } return $acc;