4 +-----------------------------------------------------------------------+
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2010-2011, The Roundcube Dev Team |
9 | Licensed under the GNU GPL |
12 | Check local configuration and database schema after upgrading |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
22 define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
24 require_once INSTALL_PATH . 'program/include/clisetup.php';
25 require_once INSTALL_PATH . 'installer/rcube_install.php';
28 $opts = get_opt(array('v' => 'version'));
30 // ask user if no version is specified
31 if (!$opts['version']) {
32 echo "What version are you upgrading from? Type '?' if you don't know.\n";
33 if (($input = trim(fgets(STDIN))) && preg_match('/^[0-9.]+[a-z-]*$/', $input))
34 $opts['version'] = $input;
37 if ($opts['version'] && version_compare($opts['version'], RCMAIL_VERSION, '>'))
38 die("Nothing to be done here. Bye!\n");
41 $RCI = rcube_install::get_instance();
44 if ($RCI->configured) {
47 if ($messages = $RCI->check_config()) {
51 // list missing config options
52 if (is_array($messages['missing'])) {
53 echo "WARNING: Missing config options:\n";
54 echo "(These config options should be present in the current configuration)\n";
56 foreach ($messages['missing'] as $msg) {
57 echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
63 // list old/replaced config options
64 if (is_array($messages['replaced'])) {
65 echo "WARNING: Replaced config options:\n";
66 echo "(These config options have been replaced or renamed)\n";
68 foreach ($messages['replaced'] as $msg) {
69 echo "- '" . $msg['prop'] . "' was replaced by '" . $msg['replacement'] . "'\n";
75 // list obsolete config options (just a notice)
76 if (is_array($messages['obsolete'])) {
77 echo "NOTICE: Obsolete config options:\n";
78 echo "(You still have some obsolete or inexistent properties set. This isn't a problem but should be noticed)\n";
80 foreach ($messages['obsolete'] as $msg) {
81 echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
87 // ask user to update config files
89 echo "Do you want me to fix your local configuration? (y/N)\n";
90 $input = trim(fgets(STDIN));
92 // positive: let's merge the local config with the defaults
93 if (strtolower($input) == 'y') {
94 $copy1 = $copy2 = $write1 = $write2 = false;
96 // backup current config
97 echo ". backing up the current config files...\n";
98 $copy1 = copy(RCMAIL_CONFIG_DIR . '/main.inc.php', RCMAIL_CONFIG_DIR . '/main.old.php');
99 $copy2 = copy(RCMAIL_CONFIG_DIR . '/db.inc.php', RCMAIL_CONFIG_DIR . '/db.old.php');
101 if ($copy1 && $copy2) {
102 $RCI->merge_config();
104 echo ". writing " . RCMAIL_CONFIG_DIR . "/main.inc.php...\n";
105 $write1 = file_put_contents(RCMAIL_CONFIG_DIR . '/main.inc.php', $RCI->create_config('main', true));
106 echo ". writing " . RCMAIL_CONFIG_DIR . "/main.db.php...\n";
107 $write2 = file_put_contents(RCMAIL_CONFIG_DIR . '/db.inc.php', $RCI->create_config('db', true));
111 if ($write1 && $write2) {
113 echo "Your configuration files are now up-to-date!\n";
116 echo "Failed to write config files!\n";
117 echo "Grant write privileges to the current user or update the files manually according to the above messages.\n";
121 echo "Please update your config files manually according to the above messages.\n\n";
125 // check dependencies based on the current configuration
126 if (is_array($messages['dependencies'])) {
127 echo "WARNING: Dependency check failed!\n";
128 echo "(Some of your configuration settings require other options to be configured or additional PHP modules to be installed)\n";
130 foreach ($messages['dependencies'] as $msg) {
131 echo "- " . $msg['prop'] . ': ' . $msg['explain'] . "\n";
133 echo "Please fix your config files and run this script again!\n";
138 // check database schema
139 if ($RCI->config['db_dsnw']) {
140 $DB = new rcube_mdb2($RCI->config['db_dsnw'], '', false);
141 $DB->db_connect('w');
142 if ($db_error_msg = $DB->is_error()) {
143 echo "Error connecting to database: $db_error_msg\n";
146 else if ($err = $RCI->db_schema_check($DB, false)) {
147 $updatefile = INSTALL_PATH . 'SQL/' . (isset($RCI->db_map[$DB->db_provider]) ? $RCI->db_map[$DB->db_provider] : $DB->db_provider) . '.update.sql';
148 echo "WARNING: Database schema needs to be updated!\n";
149 echo join("\n", $err) . "\n\n";
152 if ($opts['version']) {
153 echo "Do you want to run the update queries to get the schmea fixed? (y/N)\n";
154 $input = trim(fgets(STDIN));
155 if (strtolower($input) == 'y') {
156 $success = $RCI->update_db($DB, $opts['version']);
161 echo "Open $updatefile and execute all queries below the comment with the currently installed version number.\n";
165 // index contacts for fulltext searching
166 if (version_compare($opts['version'], '0.6', '<')) {
167 system(INSTALL_PATH . 'bin/indexcontacts.sh');
171 echo "This instance of Roundcube is up-to-date.\n";
176 echo "This instance of Roundcube is not yet configured!\n";
177 echo "Open http://url-to-roundcube/installer/ in your browser and follow the instuctions.\n";