IcingaServiceForm: allow empty name for apply rule

This commit is contained in:
Thomas Gelf 2016-10-22 00:05:08 +00:00
parent 7c31b37f27
commit 1f660b514a
4 changed files with 37 additions and 4 deletions

View File

@ -212,7 +212,7 @@ class IcingaServiceForm extends DirectorObjectForm
{
$this->addElement('text', 'object_name', array(
'label' => $this->translate('Name'),
'required' => true,
'required' => !$this->object()->isApplyRule(),
'description' => $this->translate(
'Name for the Icinga service you are going to create'
)

View File

@ -29,6 +29,20 @@ class DirectorActivityLog extends DbObject
'parent_checksum' => null,
);
/**
* @codingStandardsIgnoreStart
*/
protected function setObject_Name($name)
{
// @codingStandardsIgnoreEnd
if ($name === null) {
$name = '';
}
return $this->reallySet('object_name', $name);
}
protected static function username()
{
if (Icinga::app()->isCli()) {

View File

@ -105,7 +105,7 @@ class IcingaHost extends IcingaObject
if (substr($prop, -3) === '_id') {
$prop = substr($prop, 0, -3);
}
$hostProperties[$prefix . $prop] = $prop;
}

View File

@ -133,6 +133,20 @@ class IcingaService extends IcingaObject
return $this;
}
/**
* @codingStandardsIgnoreStart
*/
protected function setObject_Name($name)
{
// @codingStandardsIgnoreEnd
if ($name === null && $this->isApplyRule()) {
$name = '';
}
return $this->reallySet('object_name', $name);
}
/**
* Render host_id as host_name
*
@ -158,11 +172,16 @@ class IcingaService extends IcingaObject
&& !$this->hasBeenAssignedToHostTemplate()
&& $this->get('apply_for') !== null) {
$name = $this->getObjectName();
if ($name !== '') {
$name = ' ' . c::renderString($name);
}
return sprintf(
"%s %s %s for (config in %s) {\n",
"%s %s%s for (config in %s) {\n",
$this->getObjectTypeName(),
$this->getType(),
c::renderString($this->getObjectName()),
$name,
$this->get('apply_for')
);
}