Code

Added initial department migration step.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 25 Apr 2007 08:15:11 +0000 (08:15 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 25 Apr 2007 08:15:11 +0000 (08:15 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6189 594d385d-05f5-0310-b6e9-bd551577e9d8

setup/class_setupStep_Migrate.inc
setup/setup_migrate.tpl

index 8828f8d8bc93d62a0971c3c69a93fea7e67b8f94..4e40268e6dceca3803baeba2c46f59f3252169c1 100644 (file)
@@ -27,6 +27,12 @@ class Step_Migrate extends setup_step
   var $header_image   = "images/monitoring.png";
   var $checks         = array();
 
+  /* Department migration attributes */
+  var $migration_dialog   = FALSE;
+  var $deps_to_migrate    = array();
+
+  
+
   function Step_Migrate()
   {
     $this->update_strings(); 
@@ -46,8 +52,14 @@ class Step_Migrate extends setup_step
     $this->checks['permissions']['TITLE']     = _("Checking permissions on ldap database");
     $this->checks['permissions']['STATUS']    = FALSE;
     $this->checks['permissions']['STATUS_MSG']= "";
-    $this->checks['permissions']['CHK_FUNC']  = "check_ldap_permissions";
-    $this->checks['permissions']['ERROR_MSG'] = _("The specified user '%s' does not have full access to your ldap database.");
+    $this->checks['permissions']['ERROR_MSG'] = "";
+    $this->check_ldap_permissions();
+
+    $this->checks['deps_visible']['TITLE']     = _("Checking for invisible deparmtments");
+    $this->checks['deps_visible']['STATUS']    = FALSE;
+    $this->checks['deps_visible']['STATUS_MSG']= "";
+    $this->checks['deps_visible']['ERROR_MSG'] = "";
+    $this->check_visible_organizationalUnits();
   }
 
 
@@ -79,6 +91,8 @@ class Step_Migrate extends setup_step
       $this->checks['permissions']['STATUS_MSG']= _("Failed");
       $this->checks['permissions']['ERROR_MSG'] = 
         sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
+      $this->checks['permissions']['ERROR_MSG'].=
+        "<input type='submit' name='retry_permissions' value='"._("Retry")."'>";
       return(false);
     }
 
@@ -88,43 +102,179 @@ class Step_Migrate extends setup_step
       $this->checks['permissions']['STATUS_MSG']= _("Failed");
       $this->checks['permissions']['ERROR_MSG'] = 
         sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
+      $this->checks['permissions']['ERROR_MSG'].=
+        "<input type='submit' name='retry_permissions' value='"._("Retry")."'>";
       return(false);
     }
 
     $this->checks['permissions']['STATUS']    = TRUE;
     $this->checks['permissions']['STATUS_MSG']= _("Ok");
-    $this->checks['permissions']['ERROR_MSG'] = "";
+    $this->checks['permissions']['ERROR_MSG'] = "<input type='submit' name='retry_permissions' value='"._("Retry")."'>";
     return(true);
   } 
 
 
   function check_visible_organizationalUnits()
   {
+    $this->deps_to_migrate = array();
+    $cnt_ok = 0;
+
+    /* Get collected configuration settings */
+    $cv = $this->parent->captured_values;
+
+    /* Establish ldap connection */
+    $ldap = new LDAP($cv['admin'],
+                     $cv['password'],
+                     $cv['connection'],
+                     FALSE,
+                     $cv['tls']);
+
+    /* Skip GOsa internal departments */
+    $skip_dns = array("/^ou=people,/","/^ou=groups,/","/(,|)ou=configs,/","/(,|)ou=systems,/",
+                      "/^ou=apps,/","/^ou=mime,/","/^ou=aclroles,/","/^ou=incoming,/",
+                      "/ou=snapshots,/","/(,|)dc=addressbook,/","/^(,|)ou=machineaccounts,/",
+                      "/(,|)ou=winstations,/");
+
+
+    /* Get all invisible departments */
+    $ldap->cd($cv['base']); 
+    $ldap->search("(&(objectClass=organizationalUnit)(!(objectClass=gosaDepartment)))",array("ou","description","dn"));
+    while($attrs = $ldap->fetch()){
+      $attrs['checked'] = FALSE;
+      $this->deps_to_migrate[] = $attrs;
+    }
+  
+    /* Filter returned list of departments */
+    foreach($this->deps_to_migrate as $key => $attrs){
+      $dn = $attrs['dn'];
+      $skip = false;
+      foreach($skip_dns as $skip_dn){
+        if(preg_match($skip_dn,$dn)){
+          $skip = true;
+        }
+      }
+      if($skip){
+        unset($this->deps_to_migrate[$key]);
+      }
+    }
+  
+    /* No invisible */
+    if(count($this->deps_to_migrate) == 0){
+      $this->checks['deps_visible']['STATUS']    = TRUE;
+      $this->checks['deps_visible']['STATUS_MSG']= _("Ok");
+      $this->checks['deps_visible']['ERROR_MSG'] = "";
+      $this->checks['deps_visible']['ERROR_MSG'] .= "<input type='submit' name='deps_visible_migrate_refresh' value='"._("Retry")."'>";
+    }else{
+      $this->checks['deps_visible']['STATUS']    = FALSE;
+      $this->checks['deps_visible']['STATUS_MSG']= sprintf(_("%s entries found"),count($this->deps_to_migrate));
+      $this->checks['deps_visible']['ERROR_MSG'] = sprintf(_("Found %s departments that will not be visible in GOsa."),count($this->deps_to_migrate));
+      $this->checks['deps_visible']['ERROR_MSG'] .= "<input type='submit' name='deps_visible_migrate' value='"._("Migrate")."'>";
+      $this->checks['deps_visible']['ERROR_MSG'] .= "<input type='submit' name='deps_visible_migrate_refresh' value='"._("Reload list")."'>";
+    }
 
   }
 
 
+    
+  /* Start deparmtment migration */  
+  function migrate_organizationalUnits()
+  {
+    /* Get collected configuration settings */
+    $cv = $this->parent->captured_values;
+
+    /* Establish ldap connection */
+    $ldap = new LDAP($cv['admin'],
+                     $cv['password'],
+                     $cv['connection'],
+                     FALSE,
+                     $cv['tls']);
+
+    foreach($this->deps_to_migrate as $dep){
+      if($dep['checked']){
+
+        $ldap->cat($dep['dn'],array("objectClass","description"));
+        $attrs      = $ldap->fetch();
+        $new_attrs  = array();
+
+        for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
+          $new_attrs['objectClass'][]   = $attrs['objectClass'][$i];
+        }
+        $new_attrs['objectClass'][] = "gosaDepartment";
+    
+        if(!isset($attrs['description'])){
+          $new_attrs['description'][] = "GOsa department";
+        }
+        
+        $ldap->cd($attrs['dn']);
+        if(!$ldap->modify($new_attrs)){
+          print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
+          return(false);
+        }
+      }
+    }
+    return(TRUE);
+  }
+
+
+
   function execute()
   {
+    /* Permission check */
+    $this->check_ldap_permissions();
+
+    /* Migration options 
+     */
+    /* Refresh list of deparments */
+    if(isset($_POST['deps_visible_migrate_refresh'])){
+      $this->check_visible_organizationalUnits();
+    }
+
+    /* Open migration dialog */
+    if(isset($_POST['deps_visible_migrate'])){
+      $this->migration_dialog = TRUE;
+      $this->dialog =TRUE;
+    }
+
+    /* Close migration dialog */
+    if(isset($_POST['deps_visible_migrate_close'])){
+      $this->migration_dialog = FALSE;
+      $this->dialog =FALSE;
+    }
+
+    /* Start migration */
+    if(isset($_POST['deps_visible_migrate_migrate'])){
+      if($this->migrate_organizationalUnits()){
+        $this->check_visible_organizationalUnits();
+      }
+    }
+
+    /* Display migration dialog */
+    if($this->migration_dialog){
+      $smarty = get_smarty();
+      $smarty->assign("deps_to_migrate",$this->deps_to_migrate);
+      $smarty->assign("method","migrate");
+      return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
+    }
+
     $smarty = get_smarty();
     $smarty->assign("checks",$this->checks);
+    $smarty->assign("method","default");
     return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
   }
 
   function save_object()
   {
-    $this->is_completed = TRUE;
+    if($this->migration_dialog){
+      foreach($this->deps_to_migrate as $id => $data){
 
-    $once = TRUE;
-    foreach($_POST as $name => $value){
-        
-      if(preg_match("/^retry_/",$name) && $once){
-        $once   = FALSE;
-        $check  = preg_replace("/^retry_/","",$name);
-        $func = $this->checks[$check]['CHK_FUNC'];
-        $this->checks[$check]['STATUS']=$this->$func();
+        if(isset($_POST['migrate_'.$id])){
+          $this->deps_to_migrate[$id]['checked'] = TRUE;
+        }else{
+          $this->deps_to_migrate[$id]['checked'] = FALSE;
+        }
       }
     }
+
   }
 }
 
index 0c926e4aa23642fdef6ed6ed3be5861752f4c4d1..bcae3c6084bdff21ac43db7d2448f33802c638db 100644 (file)
@@ -1,36 +1,54 @@
 <div>
     <div class='default'>
 
-               {foreach from=$checks item=val key=key}
+               {if $method == "default"}
+                       {foreach from=$checks item=val key=key}
+                               <div class='step2_entry_name'><b>{$checks.$key.TITLE}</b></div>
+                               {if $checks.$key.STATUS}
+                                       <div class='step2_successful'>{$checks.$key.STATUS_MSG}
+                                       {if $checks.$key.ERROR_MSG}
+                                               {$checks.$key.ERROR_MSG}
+                                       {/if}
+                                       </div>
+                               {else}
+                                       <div class='step2_failed'>{$checks.$key.STATUS_MSG}
+                                       {if $checks.$key.ERROR_MSG}
+                                               {$checks.$key.ERROR_MSG}
+                                       {/if}
+                                       </div>
+                               {/if}
+                               <div style='height:10px;'>&nbsp;</div>
+                       {/foreach}
+               {elseif $method == "migrate"}
        
-               <div class='step2_entry_name'><b>{$checks.$key.TITLE}</b></div>
-
+                       <h2>Department migration</h2>
 
-                               
-                       {if $checks.$key.STATUS}
-                               <div class='step2_successful'>{$checks.$key.STATUS_MSG}</div>
-                       {else}
-                               <div class='step2_failed'>{$checks.$key.STATUS_MSG}</div>
-                               {if $checks.$key.ERROR_MSG}
-                                       {$checks.$key.ERROR_MSG}
-                               {/if}
-                       {/if}
-                               <input type='submit' name='retry_{$key}' value='{t}Retry{/t}'>
-                       <p>&nbsp;</p>
-               {/foreach}
+                       {t}The listed deparmtents below are currenlty invisble in the GOsa user interface. If you want to migrate a set of departments, just select them and use the migrate button below.{/t}<br>
+                       {t}If you want to know what will be done when migrating the selected entries, just use the 'What will be done here' button and you will see a list of changes.{/t}
+                                       
 
+                       <br><br>
+                       {foreach from=$deps_to_migrate item=val key=key}
 
-       <p>&nbsp; </p>
-       <p>&nbsp; </p>
-       <p>&nbsp; </p>
-       <p> </p>
-       <p></p>
-       <p class='seperator'></p>
-       <p></p>
-       <p class='seperator'></p>
+                               {if $deps_to_migrate.$key.checked}
+                                       <input type='checkbox' name='migrate_{$key}' checked>
+                               {else}
+                                       <input type='checkbox' name='migrate_{$key}'>
+                               {/if}
+                               {$deps_to_migrate.$key.dn}
+                               <br>
+                       {/foreach}
 
+                       <input type='submit' name='deps_visible_migrate_refresh' value='{t}Reload list{/t}'>
+                       <input type='submit' name='deps_visible_migrate_migrate' value='{t}Migrate{/t}'>
+                       <input type='submit' name='deps_visible_migrate_whatsdone' value='{t}What will be done here{/t}'>
 
+                       <p class='seperator'>&nbsp;</p> 
 
+                       <div style='width:100%; text-align:right; padding:5px;'>
+                               <input type='submit' name='deps_visible_migrate_close' value='{t}Close{/t}'>
+                       </div>
+               {else}
 
        * Create a test department with some objects to check for correct permissions
        <br>
@@ -49,5 +67,8 @@
        * Check for double uidNumbers/gidNumbers
        <br>
        * Check for mail accounts and add gosaMailAccount - optionally create these accounts on the IMAP server
+
+       
+       {/if}
     </div>
 </div>