Code

Added dummy migrate method for userRDN
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 12 May 2010 09:13:47 +0000 (09:13 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 12 May 2010 09:13:47 +0000 (09:13 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18375 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/class_configRegistry.inc
gosa-core/include/class_core.inc
gosa-core/include/class_migrate_userRDN.inc [new file with mode: 0644]
gosa-core/plugins/addons/configViewer/class_configViewer.inc
gosa-core/plugins/addons/configViewer/migrate.tpl [new file with mode: 0644]

index ea80efa573e8ed4068391eca325deabcae59bd87..fb78771d4361503c9a73ffbdaa2c7b0f68f7f34c 100644 (file)
@@ -168,10 +168,21 @@ class configRegistry{
 
     function saveChanges()
     {
+        $migrate = array();
         foreach($this->properties as $prop){
-            $prop->save();
+
+            // Is this property modified
+            if(in_array($prop->getStatus(),array('modified','removed'))){
+
+                // Check if we've to migrate something before we can make the changes effective. 
+                if($prop->migrationRequired()){
+                    $migrate[] = $prop;
+                }else{
+                    $prop->save();
+                }
+            }
         }
-        $this->reload(TRUE);
+        return($migrate);
     }
 }
 
@@ -193,6 +204,8 @@ class gosaProperty
     protected $parent = NULL;
     protected $data = array();
 
+    protected $migrationClass = NULL;
+
     /*!  The current property status
      *     'ldap'       Property is stored in ldap 
      *     'file'       Property is stored in the config file
@@ -204,6 +217,9 @@ class gosaProperty
     protected $attributes = array('name','type','default','description','check',
             'migrate','mandatory','group','defaults');
 
+
+
+
     function __construct($parent,$classname,$data)
     {
         // Set some basic infos 
@@ -220,6 +236,33 @@ class gosaProperty
 
         // Initialize with the current value
         $this->_restoreCurrentValue(); 
+
+        // Instantiate migration class 
+        if(!empty($this->migrate)){
+            if(!class_available($this->migrate)){
+                trigger_error("Cannot start migration for gosaProperty::'{$this->getName()}' class not found ({$this->migrate})!");
+            }else{
+                $class = $this->migrate;
+                $tmp = new $class($this);
+                if(! $tmp instanceof propertyMigration){ 
+                    trigger_error("Cannot start migration for gosaProperty::'{$this->getName()}' doesn't implement propertyMigration!");
+                }
+                $this->migrationClass = $tmp;
+            }
+        }
+    }
+
+    function migrationRequired()
+    {
+        if(empty($this->migrate) || $this->migrationClass == NULL){
+            return(FALSE);
+        }
+        return($this->migrationClass->checkForIssues());
+    }
+
+    function getMigrationClass()
+    {
+        return($this->migrationClass);
     }
 
     function check()
@@ -458,8 +501,9 @@ class gosaProperty
                 if(!$ldap->success()){
                     echo $ldap->get_error();
                 }
-            } 
-            $this->_restoreCurrentValue();
+            }
+            $this->value = $this->tmp_value;
+            $this->setStatus('ldap'); 
         }elseif($this->getStatus() == 'removed'){
             $ldap = $this->parent->config->get_ldap_link();
             $ldap->cd($this->parent->config->current['BASE']);
@@ -498,4 +542,12 @@ class gosaProperty
     }
 }
 
+
+
+interface propertyMigration
+{
+    function __construct($property);
+}
+
+
 ?>
index 3df7083c4a4a07d6789de1f9bd09d74af9b6c271..e88f55ca95e652ce2b44a6f5d2f7ad97d87ca3a7 100644 (file)
@@ -446,7 +446,7 @@ DEBUG_SI      = 256"),
                                 "default"       => "ou=people",
                                 "description"   => "The 'userRDN' statement defines the location where new accounts will be created inside of defined departments. The default is 'ou=people'.",
                                 "check"         => "gosaProperty::isRdn",
-                                "migrate"       => "",
+                                "migrate"       => "migrate_userRDN",
                                 "group"         => "user",
                                 "mandatory"     => FALSE),
 
@@ -578,7 +578,7 @@ DEBUG_SI      = 256"),
                                 "default"       => "false",
                                 "description"   => "The 'honourUnitTags' statement enables checking of 'unitTag' attributes when using administrative units. If this is set to 'true' GOsa can only see objects inside the administrative unit a user is logged into.",
                                 "check"         => "",
-                                "migrate"       => "gosaProperty::isBool",
+                                "migrate"       => "",
                                 "group"         => "core",
                                 "mandatory"     => FALSE),
 
@@ -676,9 +676,9 @@ DEBUG_SI      = 256"),
                                 "name"          => "strictNamingRules",
                                 "type"          => "bool",
                                 "default"       => "true",
-                                "description"   => "",
+                                "description"   => "The 'strictNamingRules' statement enables strict checking of uids and group names. If you need   characters like . or - inside of your accounts, set this to 'false'.",
                                 "check"         => "gosaProperty::isBool",
-                                "migrate"       => "The 'strictNamingRules' statement enables strict checking of uids and group names. If you need characters like . or - inside of your accounts, set this to 'false'",
+                                "migrate"       => "",
                                 "group"         => "core",
                                 "mandatory"     => FALSE),
 
diff --git a/gosa-core/include/class_migrate_userRDN.inc b/gosa-core/include/class_migrate_userRDN.inc
new file mode 100644 (file)
index 0000000..63815cc
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+
+
+class migrate_userRDN implements propertyMigration
+{
+    private $property = NULL;
+
+    function __construct($property)
+    {
+        $this->property = &$property;
+    }   
+
+    function checkForIssues()
+    {
+        return(TRUE);
+    }
+
+    function execute()
+    {
+        return("<input type='submit'>");
+    }
+   
+    function save_object()
+    {
+    
+    } 
+
+    function check()
+    {
+        return(array());
+    }
+} 
+
+?>
index 02d3b73f8de8869e1ac3ad36815f39d5ba17ebef..9e3c39e654de63c58970e61f0025d9ec9e8f3175 100644 (file)
@@ -7,6 +7,8 @@ class configViewer extends management
     var $plDescription= "Configure global and special GOsa settings like hooks and plugin parameters";
     var $plIcon  = "plugins/configViewer/images/plugin.png";
 
+    var $toBeMigrated = array();
+
     function __construct($config,$ui)
     {
         $this->config = $config;
@@ -50,7 +52,6 @@ class configViewer extends management
                 $this->dialogObject = new commandVerifier($this->config,$prop);
             }
         }
-
         if(isset($_POST['commandVerifier_save'])){
             $this->dialogObject->save();
             $this->closeDialogs();
@@ -59,6 +60,36 @@ class configViewer extends management
             $this->closeDialogs();
         }
 
+
+        // Execute registered management event listeners.
+        $this->handleActions($this->detectPostActions());
+
+
+        // Handle properties that have to be migrated 
+        if(isset($_POST['propertyMigrate_cancel']) && count($this->toBeMigrated)){
+            unset($this->toBeMigrated[0]);
+            $this->toBeMigrated = array_values($this->toBeMigrated);
+        }
+        if(isset($_POST['propertyMigrate_save']) && count($this->toBeMigrated)){
+            $first = $this->toBeMigrated[0]->getMigrationClass();
+            $first->save_object();
+            $msgs = $first->check();
+            if(!count($msgs)){
+                $this->toBeMigrated[0]->save();
+                unset($this->toBeMigrated[0]);
+                $this->toBeMigrated = array_values($this->toBeMigrated);
+            }
+        }
+        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)));
+        }
+
         return(management::execute());
     }
 
@@ -84,14 +115,17 @@ class configViewer extends management
 
     function saveProperties()
     {
+        // Check if we've misconfigured properties and skip saving in this case.
         $all = $this->config->configRegistry->getAllProperties();
         $valid = TRUE;
         foreach($all as $prop){
             $valid &= $prop->check();
+            if(!$valid) break;
         }
 
-        if($valid){ 
-            $this->config->configRegistry->saveChanges();
+        // Now save the properties.
+        if($valid){
+            $this->toBeMigrated = $this->config->configRegistry->saveChanges();
         }
     }
 
diff --git a/gosa-core/plugins/addons/configViewer/migrate.tpl b/gosa-core/plugins/addons/configViewer/migrate.tpl
new file mode 100644 (file)
index 0000000..bd048b9
--- /dev/null
@@ -0,0 +1,13 @@
+<h3>{t}Property migration assistent{/t}</h3> 
+
+{t}Migration steps left{/t}: {$leftSteps}
+
+<hr>
+
+{$content}
+
+<hr>
+<div class="plugin-actions">
+    <button name='propertyMigrate_save'>{msgPool type='okButton'}</button>
+    <button name='propertyMigrate_cancel'>{msgPool type='cancelButton'}</button>
+</div>