From 398bff59254590cbaebec7d62b1f000f271648aa Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 19 Jun 2012 11:33:23 +0200 Subject: Replace rcube_mdb2/PEAR::MDB2 with rcube_db --- installer/check.php | 25 ++++++------ installer/config.php | 9 +---- installer/rcube_install.php | 94 +++++++-------------------------------------- installer/test.php | 4 +- installer/utils.php | 2 - 5 files changed, 29 insertions(+), 105 deletions(-) (limited to 'installer') diff --git a/installer/check.php b/installer/check.php index e5f30261c..3136563b1 100644 --- a/installer/check.php +++ b/installer/check.php @@ -6,7 +6,8 @@ $required_php_exts = array( 'DOM' => 'dom', 'Session' => 'session', 'XML' => 'xml', - 'JSON' => 'json' + 'JSON' => 'json', + 'PDO' => 'PDO', ); $optional_php_exts = array( @@ -21,19 +22,11 @@ $optional_php_exts = array( $required_libs = array( 'PEAR' => 'PEAR.php', - 'MDB2' => 'MDB2.php', 'Net_SMTP' => 'Net/SMTP.php', 'Net_IDNA2' => 'Net/IDNA2.php', 'Mail_mime' => 'Mail/mime.php', ); -$supported_dbs = array( - 'MySQL' => 'mysql', - 'MySQLi' => 'mysqli', - 'PostgreSQL' => 'pgsql', - 'SQLite (v2)' => 'sqlite', -); - $ini_checks = array( 'file_uploads' => 1, 'session.auto_start' => 0, @@ -61,8 +54,14 @@ $source_urls = array( 'DOM' => 'http://www.php.net/manual/en/book.dom.php', 'Intl' => 'http://www.php.net/manual/en/book.intl.php', 'Exif' => 'http://www.php.net/manual/en/book.exif.php', + 'PDO' => 'http://www.php.net/manual/en/book.pdo.php', + 'pdo_mysql' => 'http://www.php.net/manual/en/book.pdo-mysql.php', + 'pdo_pgsql' => 'http://www.php.net/manual/en/book.pdo-pgsql.php', + 'pdo_sqlite' => 'http://www.php.net/manual/en/book.pdo-sqlite.php', + 'pdo_sqlite2' => 'http://www.php.net/manual/en/book.pdo-sqlite.php', + 'pdo_sqlsrv' => 'http://www.php.net/manual/en/book.pdo-sqlsrv.php', + 'pdo_dblib' => 'http://www.php.net/manual/en/book.pdo-dblib.php', 'PEAR' => 'http://pear.php.net', - 'MDB2' => 'http://pear.php.net/package/MDB2', 'Net_SMTP' => 'http://pear.php.net/package/Net_SMTP', 'Mail_mime' => 'http://pear.php.net/package/Mail_mime', 'Net_IDNA2' => 'http://pear.php.net/package/Net_IDNA2', @@ -127,14 +126,14 @@ foreach ($optional_php_exts as $name => $ext) { $ext) { +foreach ($RCI->supported_dbs as $database => $ext) { if (extension_loaded($ext)) { $RCI->pass($database); } else { $_ext = $ext_dir . '/' . $prefix . $ext . '.' . PHP_SHLIB_SUFFIX; - $msg = @is_readable($_ext) ? 'Could be loaded. Please add in php.ini' : 'Not installed'; - $RCI->na($database, $msg, $source_urls[$database]); + $msg = @is_readable($_ext) ? 'Could be loaded. Please add in php.ini' : ''; + $RCI->na($database, $msg, $source_urls[$ext]); } echo '
'; } diff --git a/installer/config.php b/installer/config.php index bd676b12e..905fb06a3 100644 --- a/installer/config.php +++ b/installer/config.php @@ -267,13 +267,8 @@ echo $input_syslogfacility->show($RCI->getprop('syslog_facility'), LOG_USER);

Database settings for read/write operations:

'mysql', 'MySQLi' => 'mysqli', - 'PgSQL' => 'pgsql', 'SQLite' => 'sqlite'); - $select_dbtype = new html_select(array('name' => '_dbtype', 'id' => "cfgdbtype")); -foreach ($supported_dbs AS $database => $ext) { +foreach ($RCI->supported_dbs as $database => $ext) { if (extension_loaded($ext)) { $select_dbtype->add($database, $ext); } @@ -284,7 +279,7 @@ $input_dbname = new html_inputfield(array('name' => '_dbname', 'size' => 20, 'id $input_dbuser = new html_inputfield(array('name' => '_dbuser', 'size' => 20, 'id' => "cfgdbuser")); $input_dbpass = new html_passwordfield(array('name' => '_dbpass', 'size' => 20, 'id' => "cfgdbpass")); -$dsnw = MDB2::parseDSN($RCI->getprop('db_dsnw')); +$dsnw = rcube_db::parse_dsn($RCI->getprop('db_dsnw')); echo $select_dbtype->show($RCI->is_post ? $_POST['_dbtype'] : $dsnw['phptype']); echo '
'; diff --git a/installer/rcube_install.php b/installer/rcube_install.php index 01238596b..331e29625 100644 --- a/installer/rcube_install.php +++ b/installer/rcube_install.php @@ -50,6 +50,17 @@ class rcube_install 'des_key', 'session_lifetime', 'support_url', ); + // list of supported database drivers + var $supported_dbs = array( + 'MySQL' => 'pdo_mysql', + 'PostgreSQL' => 'pdo_pgsql', + 'SQLite' => 'pdo_sqlite', + 'SQLite (v2)' => 'pdo_sqlite2', + 'SQL Server (SQLSRV)' => 'pdo_sqlsrv', + 'SQL Server (DBLIB)' => 'pdo_dblib', + ); + + /** * Constructor */ @@ -371,7 +382,7 @@ class rcube_install $errors[] = "Missing columns in table '$table': " . join(',', $diff); } } - + return !empty($errors) ? $errors : false; } @@ -394,87 +405,8 @@ class rcube_install } } } - - return $schema; - } - - - /** - * 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 mdb2_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 - ); - - $dsnw = $this->config['db_dsnw']; - $schema = MDB2_Schema::factory($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_arr = MDB2::parseDSN($this->config['db_dsnw']); - - $ref_schema = INSTALL_PATH . 'SQL/' . $dsn_arr['phptype'] . '.schema.xml'; - - if (is_readable($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 '
'; var_dump($diff); echo '
'; - return false; - } - } - else - $this->raise_error(array('message' => "Could not find reference schema file ($ref_schema)")); - return false; - } - return false; + return $schema; } diff --git a/installer/test.php b/installer/test.php index 2dd330531..87896009c 100644 --- a/installer/test.php +++ b/installer/test.php @@ -125,9 +125,9 @@ else { $db_working = false; if ($RCI->configured) { if (!empty($RCI->config['db_dsnw'])) { - - $DB = new rcube_mdb2($RCI->config['db_dsnw'], '', false); + $DB = new rcube_db::factory($RCI->config['db_dsnw'], '', false); $DB->db_connect('w'); + if (!($db_error_msg = $DB->is_error())) { $RCI->pass('DSN (write)'); echo '
'; diff --git a/installer/utils.php b/installer/utils.php index 6c67d25c2..0e6cfecf3 100644 --- a/installer/utils.php +++ b/installer/utils.php @@ -23,7 +23,6 @@ function __autoload($classname) { $filename = preg_replace( array( - '/MDB2_(.+)/', '/Mail_(.+)/', '/Net_(.+)/', '/Auth_(.+)/', @@ -31,7 +30,6 @@ function __autoload($classname) '/^utf8$/' ), array( - 'MDB2/\\1', 'Mail/\\1', 'Net/\\1', 'Auth/\\1', -- cgit v1.2.3 From 91f2271fac29340b5eee3bb6657456bd5d161548 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 19 Jun 2012 12:00:07 +0200 Subject: Replace rcube_mdb2 with rcube_db --- bin/update.sh | 2 +- installer/test.php | 2 +- plugins/password/drivers/sql.php | 2 +- plugins/squirrelmail_usercopy/squirrelmail_usercopy.php | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'installer') diff --git a/bin/update.sh b/bin/update.sh index 83dd4a196..aa10c2fd7 100755 --- a/bin/update.sh +++ b/bin/update.sh @@ -137,7 +137,7 @@ if ($RCI->configured) { // check database schema if ($RCI->config['db_dsnw']) { - $DB = new rcube_db::factory($RCI->config['db_dsnw'], '', false); + $DB = rcube_db::factory($RCI->config['db_dsnw'], '', false); $DB->db_connect('w'); if ($db_error_msg = $DB->is_error()) { echo "Error connecting to database: $db_error_msg\n"; diff --git a/installer/test.php b/installer/test.php index 87896009c..f09b2f7c7 100644 --- a/installer/test.php +++ b/installer/test.php @@ -125,7 +125,7 @@ else { $db_working = false; if ($RCI->configured) { if (!empty($RCI->config['db_dsnw'])) { - $DB = new rcube_db::factory($RCI->config['db_dsnw'], '', false); + $DB = rcube_db::factory($RCI->config['db_dsnw'], '', false); $DB->db_connect('w'); if (!($db_error_msg = $DB->is_error())) { diff --git a/plugins/password/drivers/sql.php b/plugins/password/drivers/sql.php index e9207300e..449e2df5b 100644 --- a/plugins/password/drivers/sql.php +++ b/plugins/password/drivers/sql.php @@ -26,7 +26,7 @@ class rcube_sql_password else if (!is_array($dsn) && !preg_match('/\?new_link=true/', $dsn)) $dsn .= '?new_link=true'; - $db = new rcube_mdb2($dsn, '', FALSE); + $db = rcube_db::factory($dsn, '', false); $db->set_debug((bool)$rcmail->config->get('sql_debug')); $db->db_connect('w'); } diff --git a/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php b/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php index ee6bcc04b..bfa489ae5 100644 --- a/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php +++ b/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php @@ -151,10 +151,10 @@ class squirrelmail_usercopy extends rcube_plugin $this->prefs = array(); /* connect to squirrelmail database */ - $db = new rcube_mdb2($rcmail->config->get('squirrelmail_dsn')); - $db->db_connect('r'); // connect in read mode + $db = rcube_db::factory($rcmail->config->get('squirrelmail_dsn')); - // $db->set_debug(true); + $db->set_debug($rcmail->config->get('sql_debug')); + $db->db_connect('r'); // connect in read mode /* retrieve prefs */ $userprefs_table = $rcmail->config->get('squirrelmail_userprefs_table'); -- cgit v1.2.3 From 159691e7b1174146fc1c839288e5dd0162d3e6f9 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 19 Jun 2012 12:20:27 +0200 Subject: Don't use protected property rcube_db::$db_error --- installer/test.php | 2 +- program/include/rcube_contacts.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'installer') diff --git a/installer/test.php b/installer/test.php index f09b2f7c7..28eb76940 100644 --- a/installer/test.php +++ b/installer/test.php @@ -167,7 +167,7 @@ else if ($db_working && $_POST['updatedb']) { // test database if ($db_working) { $db_read = $DB->query("SELECT count(*) FROM {$RCI->config['db_table_users']}"); - if ($DB->db_error) { + if ($DB->is_error()) { $RCI->fail('DB Schema', "Database not initialized"); echo '

'; $db_working = false; diff --git a/program/include/rcube_contacts.php b/program/include/rcube_contacts.php index 6984b49cc..534a65cb9 100644 --- a/program/include/rcube_contacts.php +++ b/program/include/rcube_contacts.php @@ -934,8 +934,8 @@ class rcube_contacts extends rcube_addressbook $contact_id ); - if ($this->db->db_error) - $this->set_error(self::ERROR_SAVING, $this->db->db_error_msg); + if ($error = $this->db->is_error()) + $this->set_error(self::ERROR_SAVING, $error); else $added++; } -- cgit v1.2.3