/** * Deploy services * Recursive method * * @param int $hostId * @param mixed $hostTemplateId * @return void */ protected function deployServices($hostId, $hostTemplateId = null) { static $tmplRel; static $svcObj; static $hostSvcRel; static $svcExtended; if (!isset($tmplRel) && !isset($svcObj) && !isset($hostSvcRel)) { $tmplRel = new Centreon_Object_Relation_Host_Template_Host(); $svcObj = new Centreon_Object_Service(); $hostSvcRel = new Centreon_Object_Relation_Host_Service(); $svcExtended = new Centreon_Object_Service_Extended(); } if (!isset($hostTemplateId)) { $id = $hostId; } else { $id = $hostTemplateId; } $templates = $tmplRel->gethost_tpl_idFromhost_host_id($id); foreach ($templates as $templateId) { $serviceTemplates = $hostSvcRel->getservice_service_idFromhost_host_id($templateId); foreach ($serviceTemplates as $serviceTemplateId) { $params = $svcObj->getParameters($serviceTemplateId, array('service_alias')); $sql = "SELECT service_id\n \t\tFROM service s, host_service_relation hsr\n \t\tWHERE s.service_id = hsr.service_service_id\n \t\tAND s.service_description = :servicedescription\n \t\tAND hsr.host_host_id = :hostid\n \t\tUNION\n \t\tSELECT service_id\n \t\tFROM service s, host_service_relation hsr\n \t\tWHERE s.service_id = hsr.service_service_id\n \t\tAND s.service_description = :servicedescription\n \t\tAND hsr.hostgroup_hg_id IN (SELECT hostgroup_hg_id FROM hostgroup_relation WHERE host_host_id = :hostid)"; $res = $this->db->query($sql, array(':servicedescription' => $params['service_alias'], ':hostid' => $hostId)); $result = $res->fetchAll(); if (!count($result)) { $svcId = $svcObj->insert(array('service_description' => $params['service_alias'], 'service_activate' => '1', 'service_register' => '1', 'service_template_model_stm_id' => $serviceTemplateId)); $hostSvcRel->insert($hostId, $svcId); $svcExtended->insert(array($svcExtended->getUniqueLabelField() => $svcId)); } unset($res); } $this->deployServices($hostId, $templateId); } }