diff options
author | Aleksander Machniak <alec@alec.pl> | 2013-04-26 11:26:58 +0200 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2013-04-26 11:28:50 +0200 |
commit | ae0c133d45fbb95a8266db505033690af46b4363 (patch) | |
tree | 99978517f02452e40fee492a372897902d54e0a9 /bin/updatedb.sh | |
parent | 23ea51e98df7f1591ff0b788809b4eba784ab27d (diff) |
Fix error handling in CLI mode, use STDERR and non-empty exit code (#1489043)
Conflicts:
program/lib/Roundcube/rcube.php
Diffstat (limited to 'bin/updatedb.sh')
-rwxr-xr-x | bin/updatedb.sh | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/bin/updatedb.sh b/bin/updatedb.sh index 7fa8cceb9..aeeaf6856 100755 --- a/bin/updatedb.sh +++ b/bin/updatedb.sh @@ -31,18 +31,15 @@ $opts = rcube_utils::get_opt(array( )); if (empty($opts['dir'])) { - echo "ERROR: Database schema directory not specified (--dir).\n"; - exit(1); + rcube::raise_error("Database schema directory not specified (--dir).", false, true); } if (empty($opts['package'])) { - echo "ERROR: Database schema package name not specified (--package).\n"; - exit(1); + rcube::raise_error("Database schema package name not specified (--package).", false, true); } // Check if directory exists if (!file_exists($opts['dir'])) { - echo "ERROR: Specified database schema directory doesn't exist.\n"; - exit(1); + rcube::raise_error("Specified database schema directory doesn't exist.", false, true); } $RC = rcube::get_instance(); @@ -51,8 +48,7 @@ $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); + rcube::raise_error("Error connecting to database: " . $DB->is_error(), false, true); } // Read DB schema version from database (if 'system' table exists) @@ -113,8 +109,7 @@ if (empty($version)) { $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); + rcube::raise_error("DDL Upgrade files for " . $DB->db_provider . " driver not found.", false, true); } $dh = opendir($dir); @@ -132,13 +127,12 @@ foreach ($result as $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 "[FAILED]\n"; + rcube::raise_error("Error in DDL upgrade $v: $error", false, true); } echo "[OK]\n"; } -exit(0); function update_db_schema($package, $version, $file) { |