Code

Updated generateLdif method
[gosa.git] / gosa-core / include / class_configRegistry.inc
index e4703b7d1579a562881ffedc91d46daf7be7ce32..f895a3dac561ef9a0c1a8c04d3c426c7beb37f3c 100644 (file)
@@ -25,6 +25,9 @@ class configRegistry{
     public $schemaCheckFinished = FALSE;
     public $pluginsDeactivated = array();
 
+    // Name of enabled plugins found in gosa.conf.
+    private $activePlugins = array();
+
 
     /*! \brief      Constructs the config registry 
      *  @param      config  The configuration object
@@ -54,6 +57,15 @@ class configRegistry{
         $this->reload();
     }
 
+    
+    /*! \brief      Returns a list of plugins used by GOsa.
+        @return     Array       An array containing all plugins with theis plInfo data.
+     */
+    function getListOfPlugins()
+    {
+        return($this->classesWithInfo);
+    }
+
 
     /*! \brief      Checks whether the schema check was called in the current session or not.
      *  @return     Boolean     True if check was already called
@@ -130,9 +142,32 @@ class configRegistry{
         // Collect required schema infos
         $this->pluginRequirements = array('ldapSchema' => array());
         $this->categoryToClass = array();
+
+        // Walk through plugins with requirements, but only check for active plugins.
         foreach($this->classesWithInfo as $cname => $defs){
             if(isset($defs['plRequirements'])){
-                $this->pluginRequirements[$cname] = $defs['plRequirements'];
+
+                // Check only if required plugin is enabled in gosa.conf
+                // Normally this is the class name itself, but may be overridden
+                //  in plInfo using the plRequirements::activePlugin statement.
+                $requiresActivePlugin = $cname;
+                if(isset($defs['plRequirements']['activePlugin'])){
+                    $requiresActivePlugin = $defs['plRequirements']['activePlugin'];
+                }
+
+                // Only queue checks for active plugins. 
+                if(isset($this->activePlugins[strtolower($requiresActivePlugin)])){
+                    $this->pluginRequirements[$cname] = $defs['plRequirements'];
+                }else{
+                    if($cname == $requiresActivePlugin){
+                        new log("debug","","Skipped schema check for '{$cname}' plugin is inactive!",
+                                array(),'');
+                    }else{
+                        new log("debug","","Skipped schema check for class '{$cname}' skipped,".
+                                    " required plugin '{$requiresActivePlugin}' is inactive!",
+                                array(),'');
+                    }
+                }
             }
         }
 
@@ -145,8 +180,13 @@ class configRegistry{
                 foreach($requirements['ldapSchema'] as $oc => $version){
                     if(!$this->ocAvailable($oc)){
                         $this->detectedSchemaIssues['missing'][$oc] = $oc;
+                    
                         $this->schemaCheckFailed = TRUE;
                         $failure = TRUE;
+
+                        new log("debug","","LDAP objectClass missing '{$oc}'!",
+                                array(),'');
+
                     }elseif(!empty($version)){
                         $currentVersion = $this->getObjectClassVersion($oc);
                         if(!empty($currentVersion) && !$this->ocVersionMatch($version, $currentVersion)){
@@ -157,6 +197,10 @@ class configRegistry{
                                 sprintf(_("%s has version %s but %s is required!"), bold($oc),bold($currentVersion),bold($version));
                             $this->schemaCheckFailed = TRUE;
                             $failure = TRUE;
+
+                            new log("debug","","LDAP objectClass version mismatch '{$oc}' ".
+                                    "has '{$currentVersion}' but {$version} required!",
+                                    array(),'');
                         }
                     }
                 }
@@ -268,6 +312,7 @@ class configRegistry{
         $this->fileStoredProperties = array();
         $this->properties = array();
         $this->mapByName = array();
+        $this->activePlugins = array('core'=>'core');
 
         if(!$this->config) return;
 
@@ -275,8 +320,15 @@ class configRegistry{
         foreach($this->config->data['TABS'] as $tabname => $tabdefs){
             foreach($tabdefs as $info){
 
+                // Put plugin in list of active plugins
+                if(isset($info['CLASS'])){
+                    $class = strtolower($info['CLASS']);
+                    $this->activePlugins[$class] = $class;
+                }
+
                 // Check if the info is valid
                 if(isset($info['NAME']) && isset($info['CLASS'])){
+                    
 
                     // Check if there is nore than just the plugin definition
                     if(count($info) > 2){
@@ -295,11 +347,18 @@ class configRegistry{
         // Search for config flags defined in the config file (MENU section)
         foreach($this->config->data['MENU'] as $section => $entries){
             foreach($entries as $entry){
-                if(count($entry) > 2 && isset($entry['CLASS'])){
-                    $class = $entry['CLASS'];
-                    foreach($entry as $name => $value){
-                        if(!in_array($name, array('CLASS','ACL'))){
-                            $this->fileStoredProperties[strtolower($class)][strtolower($name)] = $value;
+
+                if(isset($entry['CLASS'])){
+
+                    // Put plugin to active plugins list.
+                    $class = strtolower($entry['CLASS']);
+                    $this->activePlugins[$class] = $class;
+                
+                    if(count($entry) > 2 ){
+                        foreach($entry as $name => $value){
+                            if(!in_array($name, array('CLASS','ACL'))){
+                                $this->fileStoredProperties[strtolower($class)][strtolower($name)] = $value;
+                            }
                         }
                     }
                 }
@@ -338,7 +397,6 @@ class configRegistry{
                     $this->ldapStoredProperties[$class][$name] = $value;
                 }
             }
-            $this->status = 'finished';
         }
 
         // Register plugin properties.
@@ -357,6 +415,12 @@ class configRegistry{
             $this->register($cname, $data);    
             $data = array('name' => 'postmodify','type' => 'command');
             $this->register($cname, $data);    
+            $data = array('name' => 'precreate','type' => 'command');
+            $this->register($cname, $data);    
+            $data = array('name' => 'preremove','type' => 'command');
+            $this->register($cname, $data);    
+            $data = array('name' => 'premodify','type' => 'command');
+            $this->register($cname, $data);    
             $data = array('name' => 'check', 'type' => 'command');
             $this->register($cname, $data);    
 
@@ -367,6 +431,19 @@ class configRegistry{
                 }
             }
         }
+
+        // We are only finsihed once we are logged in.
+        if(!empty($this->config->current['CONFIG'])){
+            $this->status = 'finished';
+        }
+    }
+
+   
+    /*! \brief      Returns TRUE if the property registration has finished without any error.
+     */ 
+    function propertyInitializationComplete()
+    {
+        return($this->status == 'finished');
     }
 
 
@@ -666,6 +743,31 @@ class gosaProperty
         return($match);
     }
 
+    static function isWriteableFile($message,$class,$name,$value, $type)
+    {
+        $match = (file_exists($value) && is_writeable($value)) || 
+                 (!file_exists($value) && is_writeable(dirname($value)));
+                
+   
+        // Display the reason for failing this check.         
+        if($message && ! $match){
+
+            if(!file_exists($value) && !is_writeable(dirname($value))){
+                msg_dialog::display(_("Warning"), 
+                        sprintf(_("The file '%s' specified for '%s:%s' cannot be created neither be used for writing!"), 
+                            bold($value),bold($class),bold($name)), 
+                        WARNING_DIALOG);
+            }elseif(file_exists($value) && !is_writeable($value)){
+                msg_dialog::display(_("Warning"), 
+                        sprintf(_("The file '%s' specified for '%s:%s' cannot be used for writing!"), 
+                            bold($value),bold($class),bold($name)), 
+                        WARNING_DIALOG);
+            }
+        }
+
+        return($match);
+    }
+
     static function isWriteablePath($message,$class,$name,$value, $type)
     {
         $match = !empty($value)&&is_dir($value)&&is_writeable($value);