Code

Updated configViewer and its migration handling
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 14 May 2010 06:32:31 +0000 (06:32 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 14 May 2010 06:32:31 +0000 (06:32 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18405 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/addons/configViewer/class_migrate_userRDN.inc [deleted file]
gosa-core/plugins/addons/configViewer/migration/class_migrateRDN.inc [new file with mode: 0644]
gosa-core/plugins/addons/configViewer/migration/class_migrate_groupRDN.inc [new file with mode: 0644]
gosa-core/plugins/addons/configViewer/migration/class_migrate_userRDN.inc [new file with mode: 0644]

diff --git a/gosa-core/plugins/addons/configViewer/class_migrate_userRDN.inc b/gosa-core/plugins/addons/configViewer/class_migrate_userRDN.inc
deleted file mode 100644 (file)
index bdfb02b..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-<?php
-
-
-class migrate_userRDN implements propertyMigration
-{
-    private $property = NULL;
-    private $config = NULL;
-
-    private $found = array();
-
-    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->property->getValue();
-        $targetValue = $this->property->getValue(TRUE);
-        $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
-        $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'][] = 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'])) ? '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'>"._("Migrate")."</button>";
-        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
-            $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-core/plugins/addons/configViewer/migration/class_migrateRDN.inc b/gosa-core/plugins/addons/configViewer/migration/class_migrateRDN.inc
new file mode 100644 (file)
index 0000000..ce3d1a8
--- /dev/null
@@ -0,0 +1,150 @@
+<?php
+
+
+
+class migrateRDN implements propertyMigration
+{
+    protected $property = NULL;
+    protected $config = NULL;
+    protected $found = array();
+    protected $filter ="";
+
+    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->property->getValue();
+        $targetValue = $this->property->getValue(TRUE);
+        $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'])) ? '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'>"._("Migrate")."</button>";
+        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
+            $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-core/plugins/addons/configViewer/migration/class_migrate_groupRDN.inc b/gosa-core/plugins/addons/configViewer/migration/class_migrate_groupRDN.inc
new file mode 100644 (file)
index 0000000..0a75c2b
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+class migrate_groupRDN extends migrateRDN implements propertyMigration 
+{
+    protected $filter = "(&(objectClass=posixGroup)%s)";
+}
+?>
diff --git a/gosa-core/plugins/addons/configViewer/migration/class_migrate_userRDN.inc b/gosa-core/plugins/addons/configViewer/migration/class_migrate_userRDN.inc
new file mode 100644 (file)
index 0000000..90782a7
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+class migrate_userRDN extends migrateRDN implements propertyMigration 
+{
+    protected $filter = "(&(objectClass=gosaAccount)(!(objectClass=sambaSamAccount))%s)";
+}
+?>