Code

Updated opsi handling
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 25 Aug 2008 08:45:35 +0000 (08:45 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 25 Aug 2008 08:45:35 +0000 (08:45 +0000)
-Used another parsing method for xml results.

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

gosa-plugins/opsi/admin/opsi/class_opsi.inc
gosa-plugins/opsi/admin/opsi/class_opsigeneric.inc

index 727314ee25faacd7cd0939a448568d1bd50d1bf1..9e5ea54a1fb25ce8d00dc770ae0c7d3b6655e6c6 100644 (file)
@@ -76,19 +76,21 @@ class opsi extends gosaSupportDaemon
         "description" => array(0 => $entry['DESCRIPTION'][0]['VALUE']),
         "macAddress"  => array(0 => $entry['MAC'][0]['VALUE']),
         "opsi_notes"  => array(0 => $entry['NOTES'][0]['VALUE']));
-        
     }
-  
     return($data);
   }
 
 
+  /*! \brief  Maps all xml to array conversion to an alternative method
+                then used in the parent class 'gosaSupportDaemon'.
+              The alternative method is able to handle more complex data.
+   */
   private function xml_to_array($xml,$alternative_method = FALSE)
   {
-    echo "asd";
     return(gosaSupportDaemon::xml_to_array($xml,TRUE));
   }
 
+
   /******************
     SI Communication functions
    ******************/
@@ -100,26 +102,21 @@ class opsi extends gosaSupportDaemon
    */
   public function get_netboot_products($host = "")
   {
-    $data = array();
-
     /* Append host attribute to query data 
      */
+    $data = array();
     if(!empty($host)){
       $data['hostId'] = trim($host);
     }
 
     $res    = $this->send_data("gosa_opsi_get_netboot_products",$this->target,$data,TRUE);
-    $items  = array();
-    if(isset($res['XML'][0]['ITEM']['PRODUCTID'])){
-      if(!is_array($res['XML'][0]['ITEM']['PRODUCTID'])){
-        $items[$res['XML'][0]['ITEM']['PRODUCTID']]['NAME'] = $res['XML'][0]['ITEM']['PRODUCTID'];
-        $items[$res['XML'][0]['ITEM']['PRODUCTID']]['DESC'] = $res['XML'][0]['ITEM']['DESCRIPTION'];
-      }else{
-        foreach($res['XML'][0]['ITEM']['PRODUCTID'] as $id => $name){
-          $items[$name]['NAME'] = $name;
-          $items[$name]['DESC'] = $res['XML'][0]['ITEM']['DESCRIPTION'][$id];
-        }
-      } 
+    $items = array();
+    if(isset($res['XML'][0]['ITEM'])){
+      foreach($res['XML'][0]['ITEM'] as $entry){
+        $e = array("DESC" => $entry['DESCRIPTION'][0]['VALUE'],
+                   "NAME" => $entry['PRODUCTID'][0]['VALUE']);
+        $items[$entry['PRODUCTID'][0]['VALUE']] = $e;
+      }
     }
     return($items);
   }
@@ -131,26 +128,21 @@ class opsi extends gosaSupportDaemon
    */
   public function get_local_products($host = "")
   {
-    $data = array();
-
     /* Append host attribute to query data 
      */
+    $data = array();
     if(!empty($host)){
       $data['hostId'] = trim($host);
     }
 
     $res    = $this->send_data("gosa_opsi_get_local_products",$this->target,$data,TRUE);
-    $items  = array();
-    if(isset($res['XML'][0]['ITEM']['PRODUCTID'])){
-      if(!is_array($res['XML'][0]['ITEM']['PRODUCTID'])){
-        $items[$res['XML'][0]['ITEM']['PRODUCTID']]['NAME'] = $res['XML'][0]['ITEM']['PRODUCTID'];
-        $items[$res['XML'][0]['ITEM']['PRODUCTID']]['DESC'] = $res['XML'][0]['ITEM']['DESCRIPTION'];
-      }else{
-        foreach($res['XML'][0]['ITEM']['PRODUCTID'] as $id => $name){
-          $items[$name]['NAME'] = $name;
-          $items[$name]['DESC'] = $res['XML'][0]['ITEM']['DESCRIPTION'][$id];
-        }
-      } 
+    $items = array();
+    if(isset($res['XML'][0]['ITEM'])){
+      foreach($res['XML'][0]['ITEM'] as $entry){
+        $e = array("DESC" => $entry['DESCRIPTION'][0]['VALUE'],
+                   "NAME" => $entry['PRODUCTID'][0]['VALUE']);
+        $items[$entry['PRODUCTID'][0]['VALUE']] = $e; 
+      }
     }
     return($items);
   }
@@ -180,10 +172,15 @@ class opsi extends gosaSupportDaemon
 
     /* Query SI server */
     $res    = $this->send_data("gosa_opsi_get_product_properties",$this->target,$data,TRUE);
+    $items  = array();
     if(isset($res['XML'][0]['ITEM'])){   
-      return($res['XML'][0]['ITEM']);
+      foreach($res['XML'][0]['ITEM'] as $entry){
+        foreach($entry as $name => $val){
+          $items[$name] = $val['0']['VALUE'];
+        }
+      }
     }
-    return(array());
+    return($items);
   }
 
 
index 5acbc597cb5c46579b481087ffaacac437ea5dff..fe3349c641b6777485eb56f118454c9dffa1db33 100644 (file)
@@ -54,11 +54,13 @@ class opsigeneric extends plugin
     /* Get selected products */
     if(!$err && !empty($this->hostId)) {
       $tmp = array_keys($this->opsi->get_netboot_products($this->hostId));
-      $this->s_selectedNetbootProduct = $tmp[0];
+      if(count($tmp)){
+        $this->s_selectedNetbootProduct = $tmp[0];
+      }
       $err |= $this->opsi->is_error();
     }
     if(!$err && !empty($this->hostId)) {
-      $tmp = $this->opsi->get_local_products($this->hostId);  
+      $tmp = $this->opsi->get_local_products($this->hostId); 
       $err |= $this->opsi->is_error();
       $this->a_selectedLocalProducts = $tmp;
     }
@@ -184,10 +186,22 @@ class opsigeneric extends plugin
 
     foreach($del as $name => $data){
       $this->opsi->del_product_from_client($name,$this->hostId);
+      if($this->opsi->is_error()){
+        msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
+        return;
+      }
     }
     foreach($add as $name => $data){
       $this->opsi->add_product_to_client($name,$this->hostId);
+      if($this->opsi->is_error()){
+        msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
+        return;
+      }
       $this->opsi->set_product_properties($name,$data['CFG'],$this->hostId);
+      if($this->opsi->is_error()){
+        msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
+        return;
+      }
     }
 
     foreach($this->a_selectedLocalProducts as $name => $data){
@@ -195,13 +209,25 @@ class opsigeneric extends plugin
       $diff = array_diff($data['CFG'],$this->a_initial_selectedLocalProducts[$name]['CFG']);
       if(count($diff)){
         $this->opsi->set_product_properties($name,$diff,$this->hostId);
+        if($this->opsi->is_error()){
+          msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
+          return;
+        }
       }
     }
-  
+
     if($this->s_selectedNetbootProduct != $this->s_initial_selectedNetbootProduct){
       if(!empty($this->s_initial_selectedNetbootProduct)){
         $this->opsi->del_product_from_client($this->s_initial_selectedNetbootProduct,$this->hostId);
-        $this->opsi->add_product_to_client($this->s_selectedNetbootProduct,$this->hostId);
+        if($this->opsi->is_error()){
+          msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
+          return;
+        }
+      }
+      $this->opsi->add_product_to_client($this->s_selectedNetbootProduct,$this->hostId);
+      if($this->opsi->is_error()){
+        msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
+        return;
       }
     }
   }