Code

Updated schemaCheck
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 25 May 2010 13:57:57 +0000 (13:57 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 25 May 2010 13:57:57 +0000 (13:57 +0000)
-Keep results in an array
-Seperated the code which generates the error message into an extra method.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18693 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/html/main.php
gosa-core/include/class_configRegistry.inc

index 83f0a7e3d90255bbdcc12dac55a6bb4e51588473..710b8c34e7cc78a65215ce08db1e493c25578fc1 100644 (file)
@@ -65,7 +65,9 @@ if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
 $config= session::global_get('config');
 $config->check_and_reload();
 $config->configRegistry->reload();
-$config->configRegistry->validateSchemata($force=FALSE,$disableIncompatiblePlugins=TRUE,$errorMessages= TRUE);
+if(!$config->configRegistry->validateSchemata($force=FALSE,$disableIncompatiblePlugins=TRUE)){
+    $config->configRegistry->displayErrors();
+}
 
 /* Enable compressed output */
 if ($config->get_cfg_value("core","sendCompressedOutput") == "true"){
index 7cdd58c406d3bc5261fb91bfb554d7d7ce9f214c..d64d82872403452da0e4ab53659d982d24d8abd9 100644 (file)
@@ -20,6 +20,8 @@ class configRegistry{
 
     public $objectClasses = array();
 
+    public $detectedSchemaIssues = array();
+    public $schemaCheckFailed = FALSE;
     public $schemaCheckFinished = FALSE;
 
     function __construct($config)
@@ -47,7 +49,7 @@ class configRegistry{
     }
 
 
-    function validateSchemata($force = FALSE, $disableIncompatiblePlugins = FALSE,$displayMessage = FALSE)
+    function validateSchemata($force = FALSE, $disableIncompatiblePlugins = FALSE)
     {
         // We can check the schemata only with a valid LDAP connection
         if(empty($this->config->current['CONFIG'])){
@@ -55,7 +57,12 @@ class configRegistry{
         }
 
         // Don't do things twice unless forced
-        if($this->schemaCheckFinished && !$force) return; 
+        if($this->schemaCheckFinished && !$force) return($this->schemaCheckFailed); 
+
+        // Prepare result array
+        $this->detectedSchemaIssues = array();
+        $this->detectedSchemaIssues['missing'] = array();
+        $this->detectedSchemaIssues['versionMismatch'] = array();
 
         // Read objectClasses from ldap
         if(!count($this->objectClasses)){
@@ -73,40 +80,51 @@ class configRegistry{
             }
         }
 
-        // Check schema requirements now
-        $missing = $invalid = array();
+        // Check schema requirements now        $missing = $invalid = array();
         foreach($this->pluginRequirements['ldapSchema'] as $cname => $requirements){
             foreach($requirements as $oc => $version){
-                if(!$this->ocAvailable($oc)){
-                    $missing[] = $oc;
+                if(1 || !$this->ocAvailable($oc)){
+                    $this->detectedSchemaIssues['missing'][] = $oc;
+                    $this->schemaCheckFailed = TRUE;
                 }elseif(!empty($version)){
                     $currentVersion = $this->getObjectClassVersion($oc);
                     if(!empty($currentVersion) && !$this->ocVersionMatch($version, $currentVersion)){
                         if($currentVersion == -1){
                             $currentVersion = _("unknown");
                         }
-                        $invalid[] = sprintf(_("%s has version %s but %s required!"), bold($oc),bold($currentVersion),bold($version));
+                        $this->detectedSchemaIssues['versionMismatch'] = 
+                            sprintf(_("%s has version %s but %s required!"), bold($oc),bold($currentVersion),bold($version));
+                        $this->schemaCheckFailed = TRUE;
                     }
                 }
             }
         }
+        $this->schemaCheckFinished =TRUE;
+        return(!$this->schemaCheckFailed);
+    }
 
-        if($displayMessage && count($missing)){
+        
+    function displayErrors()
+    {
+        if(count($this->detectedSchemaIssues['missing'])){
             msg_dialog::display(_("Schema validation error"), 
-                 _("The following objectClasses are missing:").
-                "<div class='scrollContainer' style='height:100px'>".msgPool::buildList($missing)."</div>",
+                    _("The following objectClasses are missing:").
+                    "<div class='scrollContainer' style='height:100px'>".
+                    msgPool::buildList($this->detectedSchemaIssues['missing']).
+                    "</div>",
                     ERROR_DIALOG);
         }    
-        if($displayMessage && count($invalid)){
+        if(count($this->detectedSchemaIssues['versionMismatch'])){
             msg_dialog::display(_("Schema validation error"), 
-                _("The following objectClasses do not match the version requirements:").
-                "<div class='scrollContainer' style='height:100px'>".msgPool::buildList($invalid)."</div>",
+                    _("The following objectClasses do not match the version requirements:").
+                    "<div class='scrollContainer' style='height:100px'>".
+                    msgPool::buildList($this->detectedSchemaIssues['versionMismatch']).
+                    "</div>",
                     ERROR_DIALOG);
         }    
-
-        $this->schemaCheckFinished =TRUE;
     }
 
+
     function ocVersionMatch($required, $installed)
     {
         $operator = preg_replace('/^([=<>]*).*$/',"\\1",$required);