From 9b5d61e6ffe54b83fcff773c18dc27a2f40935d3 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 30 Apr 2007 13:25:36 +0000 Subject: [PATCH] Updated migration step. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6215 594d385d-05f5-0310-b6e9-bd551577e9d8 --- setup/class_setupStep_Migrate.inc | 60 ++++++++++++++++++++++++------- setup/setup_migrate.tpl | 5 +-- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/setup/class_setupStep_Migrate.inc b/setup/class_setupStep_Migrate.inc index e23869268..bffd1baa7 100644 --- a/setup/class_setupStep_Migrate.inc +++ b/setup/class_setupStep_Migrate.inc @@ -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."
".$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 .= "
".$ref_dn; + } + if(!empty($refs)){ + $this->outside_users[$b_dn]['ldif'] .= "

"._("Updating following references too").":".$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); + } } } diff --git a/setup/setup_migrate.tpl b/setup/setup_migrate.tpl index ac59f6dcc..ae25233d6 100644 --- a/setup/setup_migrate.tpl +++ b/setup/setup_migrate.tpl @@ -39,8 +39,6 @@
{t}Be careful with this tool, there may be references pointing to this user that can't be migrated.{/t}
- {t}Attention, groupOfNames will not be updated to destination dn right now.{/t} -

{foreach from=$outside_users item=val key=key} @@ -50,6 +48,7 @@ {/if} +  {$outside_users.$key.dn} {if $outside_users.$key.ldif != ""}
@@ -59,8 +58,6 @@
{/if} - -  {$outside_users.$key.dn}
{/foreach} -- 2.30.2