summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3c880f8)
raw | patch | inline | side by side (parent: 3c880f8)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 14 May 2010 08:32:21 +0000 (08:32 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 14 May 2010 08:32:21 +0000 (08:32 +0000) |
-It is a bit tricky to keep the release container
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18471 594d385d-05f5-0310-b6e9-bd551577e9d8
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18471 594d385d-05f5-0310-b6e9-bd551577e9d8
diff --git a/gosa-plugins/fai/admin/fai/migration/class_migrateFaiRDN.inc b/gosa-plugins/fai/admin/fai/migration/class_migrateFaiRDN.inc
--- /dev/null
@@ -0,0 +1,160 @@
+<?php
+
+
+
+class migrateFaiRDN extends migrateRDN implements propertyMigration
+{
+ protected $property = NULL;
+ protected $config = NULL;
+ protected $found = array();
+ protected $filter ="";
+
+ // Additional suffixes or prefixes
+ // e.g. for 'faiScriptRDN' (ou=scripts,) moving to new destination lets say
+ // to 'ou=FAIscripts,' would break stuff with having 'ou=fai,ou=systems,ou=config'
+ // prepended.
+ //
+ protected $suffix = "";
+ protected $prefix = "";
+
+ function __construct($config,$property)
+ {
+ $this->property = &$property;
+ $this->config = &$config;
+ }
+
+ function checkForIssues()
+ {
+ $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->prefix.$this->property->getValue().$this->suffix;
+ $targetValue = $this->prefix.$this->property->getValue(TRUE).$this->suffix;
+
+ $dnMatch = "";
+ if(!empty($initialValue)){
+ foreach(preg_split("/,/", $initialValue) as $rdnPart){
+ if(empty($rdnPart)) continue;
+ list($namingAttrs, $container) = preg_split("/=/",$rdnPart,2);
+ $container = trim($container,', ');
+ $dnMatch.= "({$namingAttrs}:dn:={$container})";
+ }
+ }
+
+ // Search for users
+ $filter = sprintf($this->filter,$dnMatch);
+ $ldap->search($filter,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'][] = array('from' => $dn, 'to' => $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)){
+ $container = preg_replace("/^".preg_quote($initialValue,'/')."/",$targetValue,$container);
+
+ // Ensure that we handle a valid gosaDepartment container.
+ while(!isset($this->config->idepartments[$container])){
+ $container = preg_replace("/^[^,]*+,/","",$container);
+ }
+
+
+ $dnTo = $name.",".$targetValue.$container;
+ if(!empty($targetValue) && !$ldap->dn_exists($targetValue.$container)){
+ $this->found['add'][$targetValue.$container] = array();
+ }
+ if($dn != $dnTo){
+ $this->found['move'][] = array('from' => $dn, 'to' => $dnTo);
+ $found = TRUE;
+ }
+ }
+ }
+ }
+ return($found);
+ }
+
+ function execute()
+ {
+ $str = "";
+ if(count($this->found['add'])) {
+ $str.= "<br><h3>"._("Objects that will be added")."</h3>";
+ foreach($this->found['add'] as $dn => $attrs){
+ $str.= $dn."<br>";
+ }
+ }
+ if(count($this->found['move'])) {
+ $str.= "<br><h3>"._("Objects that will be moved")."</h3>";
+ $str.="<pre>";
+ foreach($this->found['move'] as $id => $data){
+ $checked = (!isset($_POST["migrateNow".get_class($this)])) ? 'checked':'';
+ $str.= "<input $checked type='checkbox' value='1' name='migrateEntry_{$id}'>";
+ $str.= sprintf(_("Moving object '%s' to '%s'"), $data['from'], $data['to'])."<br>";
+ }
+ $str.="</pre>";
+ }
+ $str.= "<button name='migrateNow".get_class($this)."'>"._("Migrate")."</button>";
+ 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());
+ }
+}
+
+
+?>
diff --git a/gosa-plugins/fai/admin/fai/migration/class_migrate_faiBaseRDN.inc b/gosa-plugins/fai/admin/fai/migration/class_migrate_faiBaseRDN.inc
index 5295af1acb402365e0e79b83cca4ce325a63ea44..d1e748cff6e8711a90fe48b7bf43cf3ea4e74c29 100644 (file)
<?php
-class migrate_faiBaseRDN extends migrateRDN implements propertyMigration
+class migrate_faiBaseRDN extends migrateFaiRDN implements propertyMigration
{
protected $filter = "(&(objectClass=nothing)%s)";
}
diff --git a/gosa-plugins/fai/admin/fai/migration/class_migrate_faiHookRDN.inc b/gosa-plugins/fai/admin/fai/migration/class_migrate_faiHookRDN.inc
index 52139d2998f2762e6387b0f52e352731ef30f25e..eeb4c2c6c1ad5353aaf72db9f8975bd607692d91 100644 (file)
<?php
-class migrate_faiHookRDN extends migrateRDN implements propertyMigration
+class migrate_faiHookRDN extends migrateFaiRDN implements propertyMigration
{
protected $filter = "(&(objectClass=FAIhook)%s)";
}
diff --git a/gosa-plugins/fai/admin/fai/migration/class_migrate_faiPackageRDN.inc b/gosa-plugins/fai/admin/fai/migration/class_migrate_faiPackageRDN.inc
index 7b669c2644246dafcb49c42f5d46589065faf9e4..ce18e932fd7a78335c19844f47f2ec98de57482f 100644 (file)
<?php
-class migrate_faiPackageRDN extends migrateRDN implements propertyMigration
+class migrate_faiPackageRDN extends migrateFaiRDN implements propertyMigration
{
protected $filter = "(&(objectClass=FAIpackageList)%s)";
}
diff --git a/gosa-plugins/fai/admin/fai/migration/class_migrate_faiPartitionRDN.inc b/gosa-plugins/fai/admin/fai/migration/class_migrate_faiPartitionRDN.inc
index 1192f22b72c832f4f08a3e4973b0cf127f3d09ff..fa1dc0c5a656c2899c6f219528ad08e2c1657369 100644 (file)
<?php
-class migrate_faiPartitionRDN extends migrateRDN implements propertyMigration
+class migrate_faiPartitionRDN extends migrateFaiRDN implements propertyMigration
{
protected $filter = "(&(objectClass=FAIpartitionTable)%s)";
}
diff --git a/gosa-plugins/fai/admin/fai/migration/class_migrate_faiProfileRDN.inc b/gosa-plugins/fai/admin/fai/migration/class_migrate_faiProfileRDN.inc
index c1df15f935b229c837f7412236d6eeec26bc4127..3b704a06ad06269325264a85ac7253aed88f1798 100644 (file)
<?php
-class migrate_faiProfileRDN extends migrateRDN implements propertyMigration
+class migrate_faiProfileRDN extends migrateFaiRDN implements propertyMigration
{
protected $filter = "(&(objectClass=FAIprofile)%s)";
}
diff --git a/gosa-plugins/fai/admin/fai/migration/class_migrate_faiScriptRDN.inc b/gosa-plugins/fai/admin/fai/migration/class_migrate_faiScriptRDN.inc
index 2ed7437adbad28f4172df3f186b8da18ca2b2046..c2b76042af6bcdf226ef797f660a5889c7769cf4 100644 (file)
<?php
-class migrate_faiScriptRDN extends migrateRDN implements propertyMigration
+class migrate_faiScriptRDN extends migrateFaiRDN implements propertyMigration
{
protected $filter = "(&(objectClass=FAIscript)%s)";
}
diff --git a/gosa-plugins/fai/admin/fai/migration/class_migrate_faiTemplateRDN.inc b/gosa-plugins/fai/admin/fai/migration/class_migrate_faiTemplateRDN.inc
index 06849633af83f82510ea36270b8fa0f55b173f5a..cf9342d2185d9f4857d79b67c1b163d3a652e8f9 100644 (file)
<?php
-class migrate_faiTemplateRDN extends migrateRDN implements propertyMigration
+class migrate_faiTemplateRDN extends migrateFaiRDN implements propertyMigration
{
protected $filter = "(&(objectClass=FAItemplate)%s)";
}
diff --git a/gosa-plugins/fai/admin/fai/migration/class_migrate_faiVariableRDN.inc b/gosa-plugins/fai/admin/fai/migration/class_migrate_faiVariableRDN.inc
index ae84d0a2778ba78eb2600cb083c5e8aa4433857c..13a0f43c473f068e1c61246e12863d338b5ffa95 100644 (file)
<?php
-class migrate_faiVariableRDN extends migrateRDN implements propertyMigration
+class migrate_faiVariableRDN extends migrateFaiRDN implements propertyMigration
{
protected $filter = "(&(objectClass=FAIvariable)%s)";
}