Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F223839
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/bin/updatedb.sh b/bin/updatedb.sh
index 017c14913..4b922ea83 100755
--- a/bin/updatedb.sh
+++ b/bin/updatedb.sh
@@ -1,182 +1,184 @@
#!/usr/bin/env php
<?php
/*
+-----------------------------------------------------------------------+
| bin/updatedb.sh |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2010-2012, The Roundcube Dev Team |
| Copyright (C) 2010-2012, Kolab Systems AG |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Update database schema |
+-----------------------------------------------------------------------+
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
require_once INSTALL_PATH . 'program/include/clisetup.php';
// get arguments
$opts = rcube_utils::get_opt(array(
'v' => 'version',
'd' => 'dir',
'p' => 'package',
));
if (empty($opts['dir'])) {
echo "ERROR: Database schema directory not specified (--dir).\n";
exit(1);
}
if (empty($opts['package'])) {
echo "ERROR: Database schema package name not specified (--package).\n";
exit(1);
}
// Check if directory exists
if (!file_exists($opts['dir'])) {
echo "ERROR: Specified database schema directory doesn't exist.\n";
exit(1);
}
$RC = rcube::get_instance();
$DB = rcube_db::factory($RC->config->get('db_dsnw'));
// Connect to database
$DB->db_connect('w');
if (!$DB->is_connected()) {
echo "Error connecting to database: " . $DB->is_error() . ".\n";
exit(1);
}
-// Read DB schema version from database (if system table exists)
+// Read DB schema version from database (if 'system' table exists)
if (in_array('system', (array)$DB->list_tables())) {
$DB->query("SELECT " . $DB->quote_identifier('value')
- ." FROM " . $DB->quote_identifier('system')
+ ." FROM " . $DB->quote_identifier($DB->table_name('system'))
." WHERE " . $DB->quote_identifier('name') ." = ?",
$opts['package'] . '-version');
$row = $DB->fetch_array();
$version = $row[0];
}
// DB version not found, but release version is specified
if (!$version && $opts['version']) {
// Map old release version string to DB schema version
// Note: This is for backward compat. only, do not need to be updated
$map = array(
'0.1-stable' => 1,
'0.1.1' => 2008030300,
'0.2-alpha' => 2008040500,
'0.2-beta' => 2008060900,
'0.2-stable' => 2008092100,
'0.3-stable' => 2008092100,
'0.3.1' => 2009090400,
'0.4-beta' => 2009103100,
'0.4.2' => 2010042300,
'0.5-beta' => 2010100600,
'0.5' => 2010100600,
'0.5.1' => 2010100600,
'0.6-beta' => 2011011200,
'0.6' => 2011011200,
'0.7-beta' => 2011092800,
'0.7' => 2011111600,
'0.7.1' => 2011111600,
'0.7.2' => 2011111600,
'0.7.3' => 2011111600,
'0.8-beta' => 2011121400,
'0.8-rc' => 2011121400,
'0.8.0' => 2011121400,
'0.8.1' => 2011121400,
'0.8.2' => 2011121400,
'0.8.3' => 2011121400,
'0.8.4' => 2011121400,
'0.9-beta' => 2012080700,
);
$version = $map[$opts['version']];
}
-// Assume last version before the system table was added
+// Assume last version before the 'system' table was added
if (empty($version)) {
$version = 2012080700;
}
$dir = $opts['dir'] . DIRECTORY_SEPARATOR . $DB->db_provider;
if (!file_exists($dir)) {
echo "DDL Upgrade files for " . $DB->db_provider . " driver not found.\n";
exit(1);
}
$dh = opendir($dir);
$result = array();
while ($file = readdir($dh)) {
if (preg_match('/^([0-9]+)\.sql$/', $file, $m) && $m[1] > $version) {
$result[] = $m[1];
}
}
sort($result, SORT_NUMERIC);
foreach ($result as $v) {
echo "Updating database schema ($v)... ";
$error = update_db_schema($opts['package'], $v, $dir . DIRECTORY_SEPARATOR . "$v.sql");
if ($error) {
echo "\nError in DDL upgrade $v: $error\n";
exit(1);
}
echo "[OK]\n";
}
exit(0);
function update_db_schema($package, $version, $file)
{
global $DB;
// read DDL file
if ($lines = file($file)) {
$sql = '';
foreach ($lines as $line) {
if (preg_match('/^--/', $line) || trim($line) == '')
continue;
$sql .= $line . "\n";
if (preg_match('/(;|^GO)$/', trim($line))) {
@$DB->query($sql);
$sql = '';
if ($error = $DB->is_error()) {
return $error;
}
}
}
}
// escape if 'system' table does not exist
if ($version < 2013011000) {
return;
}
- $DB->query("UPDATE " . $DB->quote_identifier('system')
+ $system_table = $DB->quote_identifier($DB->table_name('system'));
+
+ $DB->query("UPDATE " . $system_table
." SET " . $DB->quote_identifier('value') . " = ?"
." WHERE " . $DB->quote_identifier('name') . " = ?",
$version, $package . '-version');
if (!$DB->is_error() && !$DB->affected_rows()) {
- $DB->query("INSERT INTO " . $DB->quote_identifier('system')
+ $DB->query("INSERT INTO " . $system_table
." (" . $DB->quote_identifier('name') . ", " . $DB->quote_identifier('value') . ")"
." VALUES (?, ?)",
$package . '-version', $version);
}
return $DB->is_error();
}
?>
diff --git a/config/db.inc.php.dist b/config/db.inc.php.dist
index a596d647d..9bbf7d75b 100644
--- a/config/db.inc.php.dist
+++ b/config/db.inc.php.dist
@@ -1,61 +1,62 @@
<?php
/*
+-----------------------------------------------------------------------+
| Configuration file for database access |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2005-2012, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
+-----------------------------------------------------------------------+
*/
$rcmail_config = array();
// PEAR database DSN for read/write operations
// format is db_provider://user:password@host/database
// For examples see http://pear.php.net/manual/en/package.database.mdb2.intro-dsn.php
// currently supported db_providers: mysql, mysqli, pgsql, sqlite, mssql or sqlsrv
$rcmail_config['db_dsnw'] = 'mysql://roundcube:pass@localhost/roundcubemail';
// postgres example: 'pgsql://roundcube:pass@localhost/roundcubemail';
// Warning: for SQLite use absolute path in DSN:
// sqlite example: 'sqlite:////full/path/to/sqlite.db?mode=0646';
// PEAR database DSN for read only operations (if empty write database will be used)
// useful for database replication
$rcmail_config['db_dsnr'] = '';
// use persistent db-connections
// beware this will not "always" work as expected
// see: http://www.php.net/manual/en/features.persistent-connections.php
$rcmail_config['db_persistent'] = FALSE;
// you can define specific table names used to store webmail data
$rcmail_config['db_table_users'] = 'users';
$rcmail_config['db_table_identities'] = 'identities';
$rcmail_config['db_table_contacts'] = 'contacts';
$rcmail_config['db_table_contactgroups'] = 'contactgroups';
$rcmail_config['db_table_contactgroupmembers'] = 'contactgroupmembers';
$rcmail_config['db_table_session'] = 'session';
$rcmail_config['db_table_cache'] = 'cache';
$rcmail_config['db_table_cache_index'] = 'cache_index';
$rcmail_config['db_table_cache_thread'] = 'cache_thread';
$rcmail_config['db_table_cache_messages'] = 'cache_messages';
$rcmail_config['db_table_dictionary'] = 'dictionary';
$rcmail_config['db_table_searches'] = 'searches';
+$rcmail_config['db_table_system'] = 'system';
// you can define specific sequence names used in PostgreSQL
$rcmail_config['db_sequence_users'] = 'user_ids';
$rcmail_config['db_sequence_identities'] = 'identity_ids';
$rcmail_config['db_sequence_contacts'] = 'contact_ids';
$rcmail_config['db_sequence_contactgroups'] = 'contactgroups_ids';
$rcmail_config['db_sequence_searches'] = 'search_ids';
// end db config file
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Mar 1, 5:57 AM (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
166058
Default Alt Text
(9 KB)
Attached To
Mode
R3 roundcubemail
Attached
Detach File
Event Timeline
Log In to Comment