From: hickert Date: Wed, 12 May 2010 12:50:17 +0000 (+0000) Subject: Added dummy migrator for userRDN X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=06b78bde2f89cfec78c2095466da8ca61c888245;p=gosa.git Added dummy migrator for userRDN git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18377 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_configRegistry.inc b/gosa-core/include/class_configRegistry.inc index fb78771d4..6cf1d32e2 100644 --- a/gosa-core/include/class_configRegistry.inc +++ b/gosa-core/include/class_configRegistry.inc @@ -243,7 +243,7 @@ class gosaProperty trigger_error("Cannot start migration for gosaProperty::'{$this->getName()}' class not found ({$this->migrate})!"); }else{ $class = $this->migrate; - $tmp = new $class($this); + $tmp = new $class($this->parent->config,$this); if(! $tmp instanceof propertyMigration){ trigger_error("Cannot start migration for gosaProperty::'{$this->getName()}' doesn't implement propertyMigration!"); } @@ -391,7 +391,7 @@ class gosaProperty static function isRdn($message,$class,$name,$value, $type) { - $match = preg_match("/^([a-z]*=[^=,]*,)*[^=]*=[^=]*$/i", $value); + $match = preg_match("/^([a-z]*=[^=,]*,)*[^=]*=[^=]*,$/i", $value); // Display the reason for failing this check. if($message && ! $match){ @@ -546,7 +546,7 @@ class gosaProperty interface propertyMigration { - function __construct($property); + function __construct($config,$property); } diff --git a/gosa-core/include/class_migrate_userRDN.inc b/gosa-core/include/class_migrate_userRDN.inc index 63815cc21..8fc163aac 100644 --- a/gosa-core/include/class_migrate_userRDN.inc +++ b/gosa-core/include/class_migrate_userRDN.inc @@ -4,25 +4,124 @@ class migrate_userRDN implements propertyMigration { private $property = NULL; + private $config = NULL; - function __construct($property) + private $found = array(); + + function __construct($config,$property) { $this->property = &$property; + $this->config = &$config; } function checkForIssues() { - return(TRUE); + $this->found = array(); + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap2= $this->config->get_ldap_link(); + $ldap2->cd($this->config->current['BASE']); + + // If the userRDN wasn't empty, then only search for users inside of the old userRDN. + $initialValue = $this->property->getValue(); + $targetValue = $this->property->getValue(TRUE); + $dnMatch = ""; + if(!empty($initialValue)){ + list($namingAttrs, $container) = preg_split("/=/",$initialValue,2); + $container = trim($container,', '); + $dnMatch = "({$namingAttrs}:dn:={$container})"; + } + + // Search for users + $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=sambaSamAccount)){$dnMatch})",array('dn')); + $found = FALSE; + while($attrs = $ldap->fetch()){ + $dn = $attrs['dn']; + $dnTo = $dn; + + // If there intially was no userDN given then just add the new userRDN to the user dns + // and create the new container objects. + if(empty($initialValue)){ + list($namingAttrs, $container) = preg_split("/=/",$targetValue,2); + list($name, $container) = preg_split("/,/",$dn,2); + + // Ensure that we handle a valid gosaDepartment container. + while(!isset($this->config->idepartments[$container])){ + $container = preg_replace("/^[^,]*+,/","",$container); + } + + // Queue new containuer to be created. + if(!preg_match("/^".preg_quote($targetValue,'/i')."/", $container)){ + $dnTo = $name.",".$targetValue.$container; + if(!$ldap->dn_exists($targetValue.$container)){ + $this->found['add'][$targetValue.$container] = array(); + } + if($dn != $dnTo){ + $this->found['move'][$dn] = $dnTo; + $found = TRUE; + } + } + } + + // If there intially was a userDN given then replace it with the new one. + if(!empty($initialValue)){ + + list($name, $container) = preg_split("/,/",$dn,2); + if(preg_match("/^".preg_quote($initialValue,'/i')."/", $container)){ + $containerDN = preg_replace("/^".preg_quote($initialValue,'/')."/",$targetValue,$container); + $dnTo = $name.",".$containerDN; + if(!empty($targetValue) && !$ldap->dn_exists($targetValue.$container)){ + $this->found['add'][$containerDN] = array(); + } + if($dn != $dnTo){ + $this->found['move'][$dn] = $dnTo; + $found = TRUE; + } + } + } + } + return($found); } function execute() { - return(""); + $str = ""; + if(count($this->found['add'])) { + $str.= "

"._("Objects that will be added")."

"; + foreach($this->found['add'] as $dn => $attrs){ + $str.= $dn."
"; + } + } + if(count($this->found['move'])) { + $str.= "

"._("Objects that will be moved")."

"; + $str.="
";
+            foreach($this->found['move'] as $dn => $dnTo){
+                $str.= sprintf(_("Moving object '%s' to '%s'"), $dn, $dnTo)."
"; + } + $str.="
"; + } + $str.= ""; + return($str); } function save_object() { - + if(isset($_POST['migrateNow'])){ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + + // Try to add the new container objects + foreach($this->found['add'] as $dn => $data){ + $ldap->cd($this->config->current['BASE']); + $ldap->create_missing_trees(ldap::convert($dn)); + } + + // Now move the objects to the new traget + foreach($this->found['move'] as $from => $to){ + $ldap->rename_dn($from, $to); + } + $this->checkForIssues(); + } } function check() diff --git a/gosa-core/plugins/addons/configViewer/class_configViewer.inc b/gosa-core/plugins/addons/configViewer/class_configViewer.inc index 9e3c39e65..02d129049 100644 --- a/gosa-core/plugins/addons/configViewer/class_configViewer.inc +++ b/gosa-core/plugins/addons/configViewer/class_configViewer.inc @@ -83,11 +83,26 @@ class configViewer extends management if(count($this->toBeMigrated)){ $first = $this->toBeMigrated[0]->getMigrationClass(); $first->save_object(); - $content = $first->execute(); - $smarty = get_smarty(); - $smarty->assign('content', $content); - $smarty->assign('leftSteps', count($this->toBeMigrated)); - return($smarty->fetch(get_template_path('migrate.tpl',TRUE))); + + // We've no problems with this property anymore. + while($first instanceOf propertyMigration && !$first->checkForIssues()){ + $this->toBeMigrated[0]->save(); + unset($this->toBeMigrated[0]); + $this->toBeMigrated = array_values($this->toBeMigrated); + if(count($this->toBeMigrated)){ + $first = $this->toBeMigrated[0]->getMigrationClass(); + }else{ + $first = NULL; + } + } + + if($first){ + $content = $first->execute(); + $smarty = get_smarty(); + $smarty->assign('content', $content); + $smarty->assign('leftSteps', count($this->toBeMigrated)); + return($smarty->fetch(get_template_path('migrate.tpl',TRUE))); + } } return(management::execute());