diff options
author | thomascube <thomas@roundcube.net> | 2008-10-14 12:40:11 +0000 |
---|---|---|
committer | thomascube <thomas@roundcube.net> | 2008-10-14 12:40:11 +0000 |
commit | 871ca9adfedfa0aedf1994af579a5ea6715cff5f (patch) | |
tree | f422ca99db7d3987bba20f3e1a8f19a89c35d498 /installer/rcube_install.php | |
parent | 81308b30ed9c24a55fe87811a782f95fad0e4f3a (diff) |
Add dependency checks for config options + update database schema with MDB2_Schema (doesn't work correctly yet)
Diffstat (limited to 'installer/rcube_install.php')
-rw-r--r-- | installer/rcube_install.php | 105 |
1 files changed, 103 insertions, 2 deletions
diff --git a/installer/rcube_install.php b/installer/rcube_install.php index 21e353c9c..808994dca 100644 --- a/installer/rcube_install.php +++ b/installer/rcube_install.php @@ -30,7 +30,7 @@ class rcube_install 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 @@ class rcube_install 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 @@ class rcube_install $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 @@ class rcube_install /** + * 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 |