[Svn] r1977 - trunk/roundcubemail/installer

trac at roundcube.net trac at roundcube.net
Tue Oct 14 14:40:11 CEST 2008


Author: thomasb
Date: 2008-10-14 07:40:11 -0500 (Tue, 14 Oct 2008)
New Revision: 1977

Modified:
   trunk/roundcubemail/installer/config.php
   trunk/roundcubemail/installer/rcube_install.php
   trunk/roundcubemail/installer/test.php
Log:
Add dependency checks for config options + update database schema with MDB2_Schema (doesn't work correctly yet)

Modified: trunk/roundcubemail/installer/config.php
===================================================================
--- trunk/roundcubemail/installer/config.php	2008-10-13 13:11:55 UTC (rev 1976)
+++ trunk/roundcubemail/installer/config.php	2008-10-14 12:40:11 UTC (rev 1977)
@@ -6,7 +6,7 @@
 $RCI->load_defaults();
 
 // register these boolean fields
-$RCI->config_props = array(
+$RCI->bool_config_props = array(
   'ip_check' => 1,
   'enable_caching' => 1,
   'enable_spellcheck' => 1,

Modified: trunk/roundcubemail/installer/rcube_install.php
===================================================================
--- trunk/roundcubemail/installer/rcube_install.php	2008-10-13 13:11:55 UTC (rev 1976)
+++ trunk/roundcubemail/installer/rcube_install.php	2008-10-14 12:40:11 UTC (rev 1977)
@@ -30,7 +30,7 @@
   var $configured = false;
   var $last_error = null;
   var $email_pattern = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9])';
-  var $config_props = array();
+  var $bool_config_props = array();
 
   var $obsolete_config = array('db_backend');
   var $replaced_config = array('skin_path' => 'skin', 'locale_string' => 'language');
@@ -136,7 +136,7 @@
       return '[Warning: could not read the template file]';
 
     foreach ($this->config as $prop => $default) {
-      $value = (isset($_POST["_$prop"]) || $this->config_props[$prop]) ? $_POST["_$prop"] : $default;
+      $value = (isset($_POST["_$prop"]) || $this->bool_config_props[$prop]) ? $_POST["_$prop"] : $default;
       
       // convert some form data
       if ($prop == 'debug_level') {
@@ -232,6 +232,30 @@
         $out['missing'][] = array('prop' => $prop);
     }
     
+    // check config dependencies and contradictions
+    if ($this->config['enable_spellcheck'] && $this->config['spellcheck_engine'] == 'pspell') {
+      if (!extension_loaded('pspell')) {
+        $out['dependencies'][] = array('prop' => 'spellcheck_engine',
+          'explain' => 'This requires the <tt>pspell</tt> extension which could not be loaded.');
+      }
+      if (empty($this->config['spellcheck_languages'])) {
+        $out['dependencies'][] = array('prop' => 'spellcheck_languages',
+          'explain' => 'You should specify the list of languages supported by your local pspell installation.');
+      }
+    }
+    
+    if ($this->config['log_driver'] == 'syslog') {
+      if (!function_exists('openlog')) {
+        $out['dependencies'][] = array('prop' => 'log_driver',
+          'explain' => 'This requires the <tt>sylog</tt> extension which could not be loaded.');
+      }
+      if (empty($this->config['syslog_id'])) {
+        $out['dependencies'][] = array('prop' => 'syslog_id',
+          'explain' => 'Using <tt>syslog</tt> for logging requires a syslog ID to be configured');
+      }
+      
+    }
+    
     return $out;
   }
   
@@ -265,6 +289,83 @@
   
   
   /**
+   * Compare the local database schema with the reference schema
+   * required for this version of RoundCube
+   *
+   * @param boolean True if the schema schould be updated
+   * @return boolean True if the schema is up-to-date, false if not or an error occured
+   */
+  function db_schema_check($update = false)
+  {
+    if (!$this->configured)
+      return false;
+    
+    $options = array(
+      'use_transactions' => false,
+      'log_line_break' => "\n",
+      'idxname_format' => '%s',
+      'debug' => false,
+      'quote_identifier' => true,
+      'force_defaults' => false,
+      'portability' => true
+    );
+    
+    $schema =& MDB2_Schema::factory($this->config['db_dsnw'], $options);
+    $schema->db->supported['transactions'] = false;
+    
+    if (PEAR::isError($schema)) {
+      $this->raise_error(array('code' => $schema->getCode(), 'message' => $schema->getMessage() . ' ' . $schema->getUserInfo()));
+      return false;
+    }
+    else {
+      $definition = $schema->getDefinitionFromDatabase();
+      $definition['charset'] = 'utf8';
+      
+      if (PEAR::isError($definition)) {
+        $this->raise_error(array('code' => $definition->getCode(), 'message' => $definition->getMessage() . ' ' . $definition->getUserInfo()));
+        return false;
+      }
+      
+      // load reference schema
+      $dsn = MDB2::parseDSN($this->config['db_dsnw']);
+      $ref_schema = INSTALL_PATH . 'SQL/' . $dsn['phptype'] . '.schema.xml';
+      
+      if (is_file($ref_schema)) {
+        $reference = $schema->parseDatabaseDefinition($ref_schema, false, array(), $schema->options['fail_on_invalid_names']);
+        
+        if (PEAR::isError($reference)) {
+          $this->raise_error(array('code' => $reference->getCode(), 'message' => $reference->getMessage() . ' ' . $reference->getUserInfo()));
+        }
+        else {
+          $diff = $schema->compareDefinitions($reference, $definition);
+          
+          if (empty($diff)) {
+            return true;
+          }
+          else if ($update) {
+            // update database schema with the diff from the above check
+            $success = $schema->alterDatabase($reference, $definition, $diff);
+            
+            if (PEAR::isError($success)) {
+              $this->raise_error(array('code' => $success->getCode(), 'message' => $success->getMessage() . ' ' . $success->getUserInfo()));
+            }
+            else
+              return true;
+          }
+          echo '<pre>'; var_dump($diff); echo '</pre>';
+          return false;
+        }
+      }
+      else
+        $this->raise_error(array('message' => "Could not find reference schema file ($ref_schema)"));
+        return false;
+    }
+    
+    return false;
+  }
+  
+  
+  /**
    * Getter for the last error message
    *
    * @return string Error message or null if none exists

Modified: trunk/roundcubemail/installer/test.php
===================================================================
--- trunk/roundcubemail/installer/test.php	2008-10-13 13:11:55 UTC (rev 1976)
+++ trunk/roundcubemail/installer/test.php	2008-10-14 12:40:11 UTC (rev 1977)
@@ -69,6 +69,20 @@
   echo html::a(array('href' => './?_mergeconfig=main'), 'main.inc.php') . '  ';
   echo html::a(array('href' => './?_mergeconfig=db'), 'db.inc.php');
   echo "</p>";
+  
+  
+  if (is_array($messages['dependencies'])) {
+    echo '<h3 class="warning">Dependency check failed</h3>';
+    echo '<p class="hint">Some of your configuration settings require other options to be configured or additional PHP modules to be installed</p>';
+    
+    echo '<ul class="configwarings">';
+    foreach ($messages['dependencies'] as $msg) {
+      echo html::tag('li', null, html::span('propname', $msg['prop']) . ': ' . $msg['explain']);
+    }
+    echo '</ul>';
+  }
+
+  
 }
 
 ?>
@@ -147,13 +161,22 @@
     $db_read = $DB->query("SELECT count(*) FROM {$RCI->config['db_table_users']}");
     if (!$db_read) {
         $RCI->fail('DB Schema', "Database not initialized");
+        echo '<p><input type="submit" name="initdb" value="Initialize database" /></p>';
         $db_working = false;
-        echo '<p><input type="submit" name="initdb" value="Initialize database" /></p>';
     }
+  /*
+    else if (!$RCI->db_schema_check($update = !empty($_POST['updatedb']))) {
+        $RCI->fail('DB Schema', "Database schema differs");
+        
+        echo $update ? '<p class="warning">Failed to update the database schema! Please manually execute the SQL statements from the SQL/*.update.sql file on your database</p>' :
+          '<p><input type="submit" name="updatedb" value="Update schema now" /></p>';
+        $db_working = false;
+    }
+  */
     else {
         $RCI->pass('DB Schema');
+        echo '<br />';
     }
-    echo '<br />';
 }
 
 // more database tests
@@ -169,7 +192,7 @@
     else {
       $RCI->fail('DB Write', $RCI->get_error());
     }
-    echo '<br />';    
+    echo '<br />';
     
     // check timezone settings
     $tz_db = 'SELECT ' . $DB->unixtimestamp($DB->now()) . ' AS tz_db';

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list