[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaServiceForm: allow empty name for apply rule

git at icinga.org git at icinga.org
Tue Oct 25 04:39:55 CEST 2016


Module: icingaweb2-module-director
Branch: master
Commit: 1f660b514ab52802c695e314f625efdd49d687f1
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=1f660b514ab52802c695e314f625efdd49d687f1

Author: Thomas Gelf <thomas at gelf.net>
Date:   Sat Oct 22 00:05:08 2016 +0000

IcingaServiceForm: allow empty name for apply rule

---

 application/forms/IcingaServiceForm.php          |    2 +-
 library/Director/Objects/DirectorActivityLog.php |   14 +++++++++++++
 library/Director/Objects/IcingaHost.php          |    2 +-
 library/Director/Objects/IcingaService.php       |   23 ++++++++++++++++++++--
 4 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/application/forms/IcingaServiceForm.php b/application/forms/IcingaServiceForm.php
index 8e87f23..34acbf1 100644
--- a/application/forms/IcingaServiceForm.php
+++ b/application/forms/IcingaServiceForm.php
@@ -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'
             )
diff --git a/library/Director/Objects/DirectorActivityLog.php b/library/Director/Objects/DirectorActivityLog.php
index b877d08..bad6718 100644
--- a/library/Director/Objects/DirectorActivityLog.php
+++ b/library/Director/Objects/DirectorActivityLog.php
@@ -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()) {
diff --git a/library/Director/Objects/IcingaHost.php b/library/Director/Objects/IcingaHost.php
index 54f086d..81633e2 100644
--- a/library/Director/Objects/IcingaHost.php
+++ b/library/Director/Objects/IcingaHost.php
@@ -105,7 +105,7 @@ class IcingaHost extends IcingaObject
             if (substr($prop, -3) === '_id') {
                 $prop = substr($prop, 0, -3);
             }
-            
+
             $hostProperties[$prefix . $prop] = $prop;
         }
 
diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php
index 6a237e0..ca3bcd4 100644
--- a/library/Director/Objects/IcingaService.php
+++ b/library/Director/Objects/IcingaService.php
@@ -134,6 +134,20 @@ class IcingaService extends IcingaObject
     }
 
     /**
+     * @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
      *
      * Avoid complaints for method names with underscore:
@@ -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')
             );
         }



More information about the icinga-checkins mailing list