Code

Updated migration step.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 30 Apr 2007 13:25:36 +0000 (13:25 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 30 Apr 2007 13:25:36 +0000 (13:25 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6215 594d385d-05f5-0310-b6e9-bd551577e9d8

setup/class_setupStep_Migrate.inc
setup/setup_migrate.tpl

index e238692681b07d10b98eacf6ad93cc7efb34c57c..bffd1baa7356ed2f9ce796e95a6740076b938bf0 100644 (file)
@@ -858,6 +858,16 @@ class Step_Migrate extends setup_step
 
   function migrate_outside_users($perform = FALSE)
   {
+    /* Establish ldap connection */
+    $cv = $this->parent->captured_values;
+    $ldap = new LDAP($cv['admin'],
+        $cv['password'],
+        $cv['connection'],
+        FALSE,
+        $cv['tls']);
+
+    $ldap->cd($cv['base']);
+
     /* Check if there was a destination department posted */
     if(isset($_POST['move_user_to'])){
       $destination_dep = $_POST['move_user_to'];
@@ -873,6 +883,18 @@ class Step_Migrate extends setup_step
         $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
         if(!$perform){
           $this->outside_users[$b_dn]['ldif'] = $dn."<br>".$d_dn;
+
+          /* Check if there are references to this object */
+          $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
+          $refs = "";
+          while($attrs = $ldap->fetch()){
+            $ref_dn = $attrs['dn'];
+            $refs .= "<br />".$ref_dn;
+          } 
+          if(!empty($refs)){ 
+            $this->outside_users[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
+          }
+
         }else{
           $this->move($dn,$d_dn);
         }
@@ -1331,27 +1353,41 @@ class Step_Migrate extends setup_step
         FALSE,
         $cv['tls']);
 
-     /* Rename dn in possible object groups */
-#    $ldap->cd($cv['base']);
-#    $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::fix($source).'))',
-#        array('cn'));
- #   while ($attrs= $ldap->fetch()){
- #     $og= new ogroup($this->config, $ldap->getDN());
- #     unset($og->member[$src_dn]);
- #     $og->member[$dst_dn]= $dst_dn;
- #     $og->save ();
- #   }
+     /* Update object references in gosaGroupOfNames */
+    $ogs_to_fix = array();
+    $ldap->cd($cv['base']);
+    $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::fix($source).'))', array('cn','member'));
+    while ($attrs= $ldap->fetch()){
+      $dn = $attrs['dn'];
+      $attrs = $this->cleanup_array($attrs);
+      $member_new = array($destination);
+      foreach($attrs['member'] as $member){
+        if($member != $source){
+          $member_new[] = $member;
+        }
+      }
+      $attrs['member'] = $member_new;
+      $ogs_to_fix[$dn] = $attrs;
+    }
 
+    /* Copy source to destination dn */
     $ldap->cat($source);
     $new_data = $this->cleanup_array($ldap->fetch());
     $ldap->cd($destination);
     $res = $ldap->add($new_data);
-    
+
+    /* Display warning if copy failed */
     if(!$res){
       print_red(_("Failed to copy '%s' to '%s'. Ldap says '%s'."),$source,$destination,$ldap->get_error());
     }else{
-      $ldap->rmDir($source);
+      $res = $ldap->rmDir($source);
       show_ldap_error($ldap->get_error(),_("Something went wrong while copying dns."));
+
+      /* Object is copied, so update its references */
+      foreach($ogs_to_fix as $dn => $data){
+        $ldap->cd($dn);
+        $ldap->modify($data);
+      }
     }
   }
 
index ac59f6dccd77dfd5979f7516ad8bfdb36f0fe30c..ae25233d624d7266faadb7438cb08f3a94d19a35 100644 (file)
@@ -39,8 +39,6 @@
                        <br>
                        {t}Be careful with this tool, there may be references pointing to this user that can't be migrated.{/t}
                        <br>
-                       <font color='red'>{t}Attention, groupOfNames will not be updated to destination dn right now.{/t}</font>
-                       <br>    
                        <br>    
 
                        {foreach from=$outside_users item=val key=key}
@@ -50,6 +48,7 @@
                                        <input type='checkbox' name='select_user_{$key}'>
                                {/if}
 
+                               &nbsp;{$outside_users.$key.dn}
                                {if $outside_users.$key.ldif != ""}
                       <div class="step2_entry_container_info" id="sol_8">
 <div style='padding-left:20px;'>
@@ -59,8 +58,6 @@
 </div>
 </div>
                                {/if}
-
-                               &nbsp;{$outside_users.$key.dn}
                                <br>
                        {/foreach}