From 260df07bef8502e3cd82e4677938999087baaad0 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 17 May 2010 12:47:47 +0000 Subject: [PATCH] Updated FAI classes -RDN are must values git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18515 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-plugins/fai/admin/fai/class_faiHook.inc | 2 +- .../fai/admin/fai/class_faiPackage.inc | 2 +- .../fai/admin/fai/class_faiPartitionTable.inc | 2 +- .../fai/admin/fai/class_faiProfile.inc | 2 +- .../fai/admin/fai/class_faiScript.inc | 2 +- .../fai/admin/fai/class_faiTemplate.inc | 2 +- .../fai/admin/fai/class_faiVariable.inc | 2 +- .../fai/migration/class_migrateFaiRDN.inc | 118 ++++-------------- 8 files changed, 28 insertions(+), 104 deletions(-) diff --git a/gosa-plugins/fai/admin/fai/class_faiHook.inc b/gosa-plugins/fai/admin/fai/class_faiHook.inc index c3a43a42e..4fc6ee2a2 100644 --- a/gosa-plugins/fai/admin/fai/class_faiHook.inc +++ b/gosa-plugins/fai/admin/fai/class_faiHook.inc @@ -515,7 +515,7 @@ class faiHook extends plugin "check" => "gosaProperty::isRdn", "migrate" => "migrate_faiHookRDN", "group" => "plugin", - "mandatory" => FALSE)), + "mandatory" => TRUE)), "plProvidedAcls" => array( diff --git a/gosa-plugins/fai/admin/fai/class_faiPackage.inc b/gosa-plugins/fai/admin/fai/class_faiPackage.inc index 7211b599c..8a4744a98 100644 --- a/gosa-plugins/fai/admin/fai/class_faiPackage.inc +++ b/gosa-plugins/fai/admin/fai/class_faiPackage.inc @@ -681,7 +681,7 @@ class faiPackage extends plugin "check" => "gosaProperty::isRdn", "migrate" => "migrate_faiPackageRDN", "group" => "plugin", - "mandatory" => FALSE)), + "mandatory" => TRUE)), "plProvidedAcls" => array( "cn" => _("Name"), diff --git a/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc b/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc index 1e01e7aec..622cc4541 100644 --- a/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc +++ b/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc @@ -795,7 +795,7 @@ class faiPartitionTable extends plugin "check" => "gosaProperty::isRdn", "migrate" => "migrate_faiPartitionRDN", "group" => "plugin", - "mandatory" => FALSE)), + "mandatory" => TRUE)), "plProvidedAcls" => array( "cn" => _("Name")." ("._("Read only").")", diff --git a/gosa-plugins/fai/admin/fai/class_faiProfile.inc b/gosa-plugins/fai/admin/fai/class_faiProfile.inc index 5f97b2574..b7d46b1d0 100644 --- a/gosa-plugins/fai/admin/fai/class_faiProfile.inc +++ b/gosa-plugins/fai/admin/fai/class_faiProfile.inc @@ -370,7 +370,7 @@ class faiProfile extends plugin "check" => "gosaProperty::isRdn", "migrate" => "migrate_faiProfileRDN", "group" => "plugin", - "mandatory" => FALSE)), + "mandatory" => TRUE)), "plProvidedAcls" => array( diff --git a/gosa-plugins/fai/admin/fai/class_faiScript.inc b/gosa-plugins/fai/admin/fai/class_faiScript.inc index 489f55853..b944c310e 100644 --- a/gosa-plugins/fai/admin/fai/class_faiScript.inc +++ b/gosa-plugins/fai/admin/fai/class_faiScript.inc @@ -560,7 +560,7 @@ class faiScript extends plugin "check" => "gosaProperty::isRdn", "migrate" => "migrate_faiScriptRDN", "group" => "plugin", - "mandatory" => FALSE + "mandatory" => TRUE ) ), diff --git a/gosa-plugins/fai/admin/fai/class_faiTemplate.inc b/gosa-plugins/fai/admin/fai/class_faiTemplate.inc index c13bd96cb..2d76c0d00 100644 --- a/gosa-plugins/fai/admin/fai/class_faiTemplate.inc +++ b/gosa-plugins/fai/admin/fai/class_faiTemplate.inc @@ -539,7 +539,7 @@ class faiTemplate extends plugin "check" => "gosaProperty::isRdn", "migrate" => "migrate_faiTemplateRDN", "group" => "plugin", - "mandatory" => FALSE)), + "mandatory" => TRUE)), "plProvidedAcls" => array( "cn" => _("Name")." ("._("Readonly").")", diff --git a/gosa-plugins/fai/admin/fai/class_faiVariable.inc b/gosa-plugins/fai/admin/fai/class_faiVariable.inc index fcbf2785c..af42beaa8 100644 --- a/gosa-plugins/fai/admin/fai/class_faiVariable.inc +++ b/gosa-plugins/fai/admin/fai/class_faiVariable.inc @@ -404,7 +404,7 @@ class faiVariable extends plugin "check" => "gosaProperty::isRdn", "migrate" => "migrate_faiVariableRDN", "group" => "plugin", - "mandatory" => FALSE)), + "mandatory" => TRUE)), "plProvidedAcls" => array( "cn" => _("Name")." ("._("Read only").")", diff --git a/gosa-plugins/fai/admin/fai/migration/class_migrateFaiRDN.inc b/gosa-plugins/fai/admin/fai/migration/class_migrateFaiRDN.inc index a163bc587..f0e68befd 100644 --- a/gosa-plugins/fai/admin/fai/migration/class_migrateFaiRDN.inc +++ b/gosa-plugins/fai/admin/fai/migration/class_migrateFaiRDN.inc @@ -27,10 +27,7 @@ class migrateFaiRDN extends migrateRDN implements propertyMigration function checkForIssues() { - return(FALSE); - // This is very tricky ... have to think about it. Its deactivated currently. - $this->found = array(); $ldap= $this->config->get_ldap_link(); $ldap->cd($this->config->current['BASE']); @@ -41,13 +38,9 @@ class migrateFaiRDN extends migrateRDN implements propertyMigration $initialValue = $this->prefix.$this->property->getValue().$this->suffix; $targetValue = $this->prefix.$this->property->getValue(TRUE).$this->suffix; - $prefixProp = $this->config->configRegistry->getProperty('faiManagement','faiBaseRDN'); - $prefix = $prefixProp->getValue(); - $prefixNew = $prefixProp->getValue(TRUE); - $dnMatch = ""; - if(!empty($initialValue) || !empty($prefix)){ - foreach(preg_split("/,/", $initialValue.$prefix) as $rdnPart){ + if(!empty($initialValue)){ + foreach(preg_split("/,/", $initialValue) as $rdnPart){ if(empty($rdnPart)) continue; list($namingAttrs, $container) = preg_split("/=/",$rdnPart,2); $container = trim($container,', '); @@ -64,108 +57,39 @@ class migrateFaiRDN extends migrateRDN implements propertyMigration $releases[$attrs['dn']] = $attrs['dn']; } + // Add release bases + $faiBase = $this->config->get_cfg_value('faiManagement','faiBaseRDN').$this->config->current['BASE']; + $releases[$faiBase] = $faiBase; + // Search for users $filter = sprintf($this->filter,$dnMatch); $ldap->search($filter,array('dn')); $found = FALSE; while($attrs = $ldap->fetch()){ - $dn = $attrs['dn']; - $dnTo = $dn; - // Detect the releaes part of the dn. - $releasePart = $dn; - while(!isset($releases[$releasePart]) && preg_match("/,/", $releasePart)){ - $releasePart = preg_replace("/^[^,]*+,/","",$releasePart); + // Detect release dn + $releaseDn = $attrs['dn']; + while(!isset($releases[$releaseDn]) && !isset($this->config->idepartments[$releaseDn])){ + $releaseDn = preg_replace("/^[^,]+,/","",$releaseDn); } - if(!isset($releases[$releasePart])){ - // Release not found; - continue; + + // Build up the new dn + $name = preg_replace("/^([^,]*+,).*$/","\\1",$attrs['dn']); + $newDn = $name.$targetValue.$releaseDn; + + // Check if we've to create new sub departments + if(!$ldap2->dn_exists($targetValue.$releaseDn)){ + $this->found['add'][$targetValue.$releaseDn] = array(); } - // Detect the base part of the releasePart - $basePart = $releasePart; - while(!isset($this->config->idepartments[$basePart]) && preg_match("/,/", $basePart)){ - $basePart = preg_replace("/^[^,]*+,/","",$basePart); - } - if(!isset($this->config->idepartments[$basePart])){ - // Base not found; - continue; - } - - $releaseRDN = substr($releasePart,0,strlen($releasePart) - strlen($basePart)); - - // Now remove the faiBaseRDN from the release DN. - $releaseRDN = preg_replace("/".preg_quote($prefix,'/')."/","", $releaseRDN); - - // Remove all parts from the dn to geht the objects name. - $name = substr($dn,0, (strlen($dn) - strlen($initialValue.$releaseRDN.$prefix.$basePart))); - - // Build new container name and check if it exists. - $newContainer = $targetValue.$releaseRDN.$prefixNew.$basePart; - if(!$ldap->dn_exists($newContainer)){ - $this->found['add'][$newContainer] = array(); - } - - // Check if the target name has changed. - $dnTo = $name.$newContainer; - if($dn != $dnTo){ - $this->found['move'][] = array('from' => $dn, 'to' => $dnTo); + // Queue object to be moved. + if($newDn != $attrs['dn']){ + $this->found['move'][] = array('from' => $attrs['dn'], 'to' => $newDn); $found = TRUE; } } return($found); } - - function execute() - { - $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 $id => $data){
-                $checked = (!isset($_POST["migrateNow".get_class($this)])) ? 'checked':'';
-                $str.= "";
-                $str.= sprintf(_("Moving object '%s' to '%s'"), $data['from'], $data['to'])."
"; - } - $str.="
"; - } - $str.= ""; - return($str); - } - - function save_object() - { - if(isset($_POST["migrateNow".get_class($this)])){ - $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 - $tmp = new plugin($this->config,NULL); - foreach($this->found['move'] as $id => $data){ - if(isset($_POST["migrateEntry_{$id}"])){ - $tmp->move($data['from'], $data['to']); - } - } - $this->checkForIssues(); - } - } - - function check() - { - return(array()); - } } -- 2.30.2