added draft of an exception class for eGW, plus a global exception handler and replaced the fatal errors in the db-class plus the application rights check in the egw object with exceptions, modified the exceptions in admin_cmd* to use egw_excpetion*, instead just Exception

This commit is contained in:
Ralf Becker
2007-12-06 08:00:41 +00:00
parent 1fdebc6582
commit cae8bb40a8
14 changed files with 219 additions and 114 deletions

View File

@ -48,6 +48,9 @@ $GLOBALS['egw_info'] = array(
include('../header.inc.php');
// set our own exception handler, to not get the html from eGW's default one
set_exception_handler('admin_cli_exception_handler');
switch($action)
{
case '--edit-user':
@ -143,21 +146,9 @@ function run_command(admin_cmd $cmd)
}
}
//_debug_array($cmd);
$msg = $cmd->run($time,true,$skip_checks);
print_r($cmd->run($time,true,$skip_checks));
echo "\n";
if ($cmd->errno)
{
fail($cmd->errno,$cmd->error);
}
if (($value = unserialize($msg)) !== false && $msg !== serialize(false))
{
print_r($value);
echo "\n";
}
else
{
echo $msg."\n\n";
}
exit(0);
}
@ -374,10 +365,10 @@ function do_change_account_id($args)
* @param int $exit_code
* @param string $message
*/
function fail($exit_code,$message)
function admin_cli_exception_handler(Exception $e)
{
echo $message."\n";
exit($exit_code);
echo $e->getMessage()."\n";
exit($e->getCode());
}
/**
@ -385,6 +376,8 @@ function fail($exit_code,$message)
*
* The list is generated by "greping" this file for calls to the fail() function.
* Calls to fail() have to be in one line, to be recogniced!
*
* @ToDo adapt it to the exceptions
*/
function list_exit_codes()
{
@ -416,7 +409,7 @@ function do_subscribe_other($account_lid,$pw=null)
{
if (!($account_id = $GLOBALS['egw']->accounts->name2id($account_lid)))
{
fail(15,lang("Unknown account: %1 !!!",$account_lid));
throw new egw_exception_wrong_userinput(lang("Unknown account: %1 !!!",$account_lid),15);
}
$GLOBALS['egw_info']['user'] = array(
'account_id' => $account_id,