[icinga-checkins] icinga.org: icinga-web/next: Fix moving groups to top level failing

git at icinga.org git at icinga.org
Fri Apr 12 13:47:44 CEST 2013


Module: icinga-web
Branch: next
Commit: 45409c1fd623c6980213375f7c2d8943c9497cb4
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=45409c1fd623c6980213375f7c2d8943c9497cb4

Author: Jannis Mosshammer <jannis.mosshammer at netways.de>
Date:   Fri Apr 12 13:39:23 2013 +0200

Fix moving groups to top level failing

When moving a group to the top level, the NsmRole doctrine model gets it's
parent field set to null (PHP atom). Doctrine is not able to insert this properly
and just skips the null value when trying to update, causing an 'invalid Ãparameter
number bound' error. The query is now implemented as DQL where null is explictily
written.

fixes #3959

---

 app/modules/AppKit/models/RoleAdminModel.class.php |   25 ++++++++++++++++---
 1 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/app/modules/AppKit/models/RoleAdminModel.class.php b/app/modules/AppKit/models/RoleAdminModel.class.php
index a1ad2ea..f9ad4b0 100644
--- a/app/modules/AppKit/models/RoleAdminModel.class.php
+++ b/app/modules/AppKit/models/RoleAdminModel.class.php
@@ -30,8 +30,8 @@
 class AppKit_RoleAdminModel extends AppKitBaseModel {
 
     private static $editableAttributes = array(
-            'role_name', 'role_description', 'role_disabled', 'role_parent'
-                                         );
+        'role_name', 'role_description', 'role_disabled', 'role_parent'
+    );
 
     /**
      * Human query to restrict groups
@@ -158,8 +158,25 @@ class AppKit_RoleAdminModel extends AppKitBaseModel {
         if (!$role->NsmPrincipal->principal_id) {
             $role->NsmPrincipal->principal_type = NsmPrincipal::TYPE_ROLE;
         }
-
-        $role->save();
+        $parts = array();
+        $params = array();
+        foreach($role as $property=>$value) {
+            if($property == "role_id" || !in_array($property,self::$editableAttributes))
+                continue;
+
+            if($value === null)
+                $parts[] = "$property = NULL";
+            else {
+                $parts[] = "$property = ? ";
+                $params[] = $value;
+            }
+        }
+        $params[] = $role->role_id;
+        $dql = "UPDATE NsmRole SET ".implode(",",$parts)." WHERE role_id = ?";
+        $query = new Doctrine_Query();
+        $query->setConnection(AppKitDoctrineUtil::getConnection());
+        $query->parseDqlQuery($dql);
+        $query->execute($params);
         return true;
     }
 





More information about the icinga-checkins mailing list