Code

Updated device handling
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 29 Sep 2010 09:03:37 +0000 (09:03 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 29 Sep 2010 09:03:37 +0000 (09:03 +0000)
-

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19843 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto/admin/systems/goto/Device/DeviceTab.inc
gosa-plugins/goto/admin/systems/goto/Device/class_Device.inc

index 4775ed0d697543587312f9b0a6b21bf56b0df076..86f09f7922ce0d37825bfdca733feff46f2e72da 100644 (file)
@@ -6,32 +6,49 @@ class DeviceTab extends tabs
     {
         // Prepare object DN
         $baseobject= $this->by_object['Device'];
-        $uuid    = preg_replace('/,/', '\,', $baseobject->deviceUUID);
+        $uuid = $baseobject->deviceUUID;
+        $orig_uuid = $baseobject->orig_deviceUUID;
+
 
         $rdn = get_ou('Device','DeviceRDN');
-        if(empty($uuid)){
-            $cn      = preg_replace('/,/', '\,', $baseobject->cn);
-            $cn      = preg_replace('/"/', '\"', $cn);
-            $this->dn= "cn=".$cn.",".$rdn.$baseobject->base;
-        }else{
-            $this->dn= "deviceUUID=".$uuid.",".$rdn.$baseobject->base;
-        }
-        $baseobject->dn= $this->dn;
+        $cn      = preg_replace('/,/', '\,', $baseobject->cn);
+        $cn      = preg_replace('/"/', '\"', $cn);
 
-        // Object moved?
-        if($this->dn != $baseobject->orig_dn && $baseobject->orig_dn != "new"){
-            $baseobject->update_acls($baseobject->orig_dn,$this->dn);
-            $baseobject->move($baseobject->orig_dn,$this->dn);
+        $dnCn = "cn=".$cn.",".$rdn.$baseobject->base;
+        $dnUuid= "deviceUUID=".$uuid.",".$rdn.$baseobject->base;
+
+        // Save object using the 'cn' in the dn and then move it to 'uuid';
+        $moveToUUID = FALSE;
+        if(!empty($uuid) && empty($orig_uuid) && $baseobject->orig_dn != "new"){
+            $moveToUUID = TRUE;
         }
 
+        // Detect target dn
+        $this->dn = (empty($uuid)) ? $dnCn : $dnUuid;
+
+        if($moveToUUID) $this->dn = $dnCn;
+
         // Populate values 
         foreach ($this->by_object as $key => $obj){
             $this->by_object[$key]->dn= $this->dn;
             $this->by_object[$key]->cn= $baseobject->cn;
         }
 
+        // Object moved?
+        if($this->dn != $baseobject->orig_dn && $baseobject->orig_dn != "new"){
+            $baseobject->update_acls($baseobject->orig_dn,$this->dn);
+            $baseobject->move($baseobject->orig_dn,$this->dn);
+        }
+
         // Save now
         tabs::save(TRUE);
+
+        if($moveToUUID){
+            $this->dn = (empty($uuid)) ? $dnCn : $dnUuid;
+            $baseobject->update_acls($baseobject->orig_dn,$this->dn);
+            $baseobject->move($baseobject->orig_dn,$this->dn);
+        }
+
     }
 }
 
index 7995b8b7c509fbfc73cf0fbf76adbf20e738c4b2..8f54646bcc727b33e2c95c9ae05d8553040800de 100644 (file)
@@ -55,6 +55,8 @@ class Device extends plugin
         $this->baseSelector->setSubmitButton(false);
         $this->baseSelector->setHeight(300);
         $this->baseSelector->update(true);
+
+        $this->orig_deviceUUID = $this->deviceUUID;
     }
 
     
@@ -94,7 +96,7 @@ class Device extends plugin
 
         // Assign attribute values 
         foreach($this->attributes as $attr){
-            $smarty->assign($attr, $this->$attr);
+            $smarty->assign($attr, set_post($this->$attr));
         }
         return($smarty->fetch(get_template_path('goto/Device/Device.tpl', TRUE)));
     }
@@ -129,7 +131,7 @@ class Device extends plugin
         }
 
         // Check mac-address
-        if (!empty($this->ipHostNumber) && !tests::is_ip($this->macAddress)){
+        if (!empty($this->macAddress) && !tests::is_mac($this->macAddress)){
             $message[]= msgPool::invalid(_("MAC address"), "", "", "00:0C:7F:31:33:F1");
         }
  
@@ -243,6 +245,7 @@ class Device extends plugin
         $this->cleanup();
         $ldap=$this->config->get_ldap_link();
         $ldap->cd($this->config->current['BASE']);
+        $ldap->create_missing_trees(preg_replace("/^[^,]*+,/","",$this->dn));
         $ldap->cd($this->dn);
 
         // Perform action modify/create