Code

Added dummy schema validator
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 21 May 2010 12:43:55 +0000 (12:43 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 21 May 2010 12:43:55 +0000 (12:43 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18613 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/class_configRegistry.inc

index 5051d21b6221dc7412529932a38da648d2aabb29..32b4b61e2e30526714d9a300989ed3e1a9033f0a 100644 (file)
@@ -15,6 +15,10 @@ class configRegistry{
 
     // Contains all classes with plInfo
     public $classesWithInfo = array();
+    public $categoryRequirements  = array();
+    public $categoryToClass  = array();
+
+    public $objectClasses = array();
 
     function __construct($config)
     {
@@ -40,6 +44,76 @@ class configRegistry{
         $this->reload();
     }
 
+
+    function validateSchemata($disableIncompatiblePlugins = FALSE,$displayMessage = FALSE)
+    {
+        // We can check the schemata only with a valid LDAP connection
+        if(empty($this->config->current['CONFIG'])){
+            return(TRUE); 
+        }
+
+        // Read objectClasses from ldap
+        if(!count($this->objectClasses)){
+            $ldap = $this->config->get_ldap_link();
+            $ldap->cd($this->config->current['BASE']);
+            $this->objectClasses = $ldap->get_objectclasses();
+        }
+
+        // Collect required schema infos
+        $this->categoryRequirements = array();
+        $this->categoryToClass = array();
+        foreach($this->classesWithInfo as $cname => $defs){
+            if(isset($defs['plCategory'])){
+                foreach($defs['plCategory'] as $name => $data){
+                    if(!is_numeric($name)){
+                        $this->categoryToClass[$name]['BASE'] = $cname;
+                        if(isset($data['objectClass'])){
+                            $this->categoryRequirements[$name] = $data['objectClass'];
+                        }
+                    }else{
+                        $this->categoryToClass[$data]['SUB'][] = $cname;
+                    }
+                }
+            }
+        }
+
+        // Check schema requirements now
+        foreach($this->categoryRequirements as $cat => $requirements){
+
+            if(!is_string($requirements)){
+            }else{
+                if(!$this->ocAvailable($requirements)){
+
+                    if($displayMessage){
+                        $classes = "<ul>";
+                        $name = $this->categoryToClass[$cat]['BASE'];
+                        $classes.= "<li>".$this->classToName[$name]."</li>";
+                        if(isset($this->categoryToClass[$cat]['SUB'])){
+                            foreach($this->categoryToClass[$cat]['SUB'] as $name){
+                                $classes.= "<li>".$this->classToName[$name]."</li>";
+                            }
+                        }
+                        $classes.= "</ul>";
+                        msg_dialog::display(_("Schema validation error"), 
+                                sprintf(_("The objectClass '%s' which is required for plugin '%s' is not availabe!"),
+                                    bold($requirements),bold($cat)), 
+                                ERROR_DIALOG);
+                    }
+                }else{
+                     #äprint_a($this->objectClasses[$requirements]);   
+                }
+            }
+        }
+    }
+
+
+    // check wheter an objectClass is installed or not.
+    function ocAvailable($name)
+    {
+        return(isset($this->objectClasses[$name]));
+    }
+
+
     function reload($force = FALSE)
     {
         // Do not reload the properties everytime, once we have