mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-08-18 12:30:02 +02:00
fix not working listing of exit-codes incl. assigning distinct ones
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* @link http://www.egroupware.org
|
||||
* @package admin
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2006-18 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2006-19 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,11 @@ elseif ($_SERVER['argc'] <= 1 || $_SERVER['argc'] == 2 && in_array($_SERVER['arg
|
||||
{
|
||||
usage();
|
||||
}
|
||||
elseif ($_SERVER['argv'][1] == '--exit-codes')
|
||||
{
|
||||
list_exit_codes();
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$arguments = $_SERVER['argv'];
|
||||
@@ -34,7 +39,7 @@ else
|
||||
// allow to specify instance by using a username with appended @domain-name
|
||||
$arg0s = explode(',',@array_shift($arguments));
|
||||
@list($user,$domain) = explode('@',$arg0s[0].'@');
|
||||
load_egw($user,$arg0s[1],$domain);
|
||||
load_egw($user, @$arg0s[1], $domain);
|
||||
|
||||
switch($action)
|
||||
{
|
||||
@@ -78,9 +83,6 @@ switch($action)
|
||||
case '--show-header';
|
||||
return run_command(new setup_cmd_showheader($arg0s[2]));
|
||||
|
||||
case '--exit-codes':
|
||||
return list_exit_codes();
|
||||
|
||||
default:
|
||||
// we allow to call admin_cmd classes directly, if they define the constant SETUP_CLI_CALLABLE
|
||||
if (substr($action,0,2) == '--' && class_exists($class = str_replace('-','_',substr($action,2))) &&
|
||||
@@ -107,7 +109,7 @@ switch($action)
|
||||
}
|
||||
return run_command(new $class($args));
|
||||
}
|
||||
usage($action);
|
||||
usage($action, 1);
|
||||
break;
|
||||
}
|
||||
exit(0);
|
||||
@@ -170,7 +172,7 @@ function run_command(admin_cmd $cmd)
|
||||
}
|
||||
if ($dry_run && $skip_checks)
|
||||
{
|
||||
echo lang('You can NOT use --try-run together with --skip-checks!')."\n\n";
|
||||
echo lang('You can NOT use --dry-run together with --skip-checks!')."\n\n";
|
||||
usage('', 99);
|
||||
}
|
||||
//_debug_array($cmd);
|
||||
@@ -195,7 +197,7 @@ function run_command(admin_cmd $cmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Api\Exception\WrongUserinput $e) {
|
||||
catch (Api\Exception $e) {
|
||||
echo "\n".$e->getMessage()."\n\n";
|
||||
exit($e->getCode());
|
||||
}
|
||||
@@ -632,29 +634,56 @@ function do_change_account_id($args)
|
||||
/**
|
||||
* List all exit codes used by the command line interface
|
||||
*
|
||||
* 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
|
||||
* The list is generated by "greping" this file for thrown exceptions.
|
||||
* Exceptions have to be in one line, to be recogniced!
|
||||
*/
|
||||
function list_exit_codes()
|
||||
{
|
||||
error_reporting(error_reporting() & ~E_NOTICE);
|
||||
|
||||
$codes = array('Ok');
|
||||
foreach(file(__FILE__) as $line)
|
||||
if (!function_exists('lang'))
|
||||
{
|
||||
$matches = null;
|
||||
if (preg_match('/fail\(([0-9]+),(.*)\);/',$line,$matches))
|
||||
function lang($str)
|
||||
{
|
||||
//echo "Line $n: $matches[1]: $matches[2]\n";
|
||||
@eval('$codes['.$matches[1].'] = '.$matches[2].';');
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
ksort($codes,SORT_NUMERIC);
|
||||
foreach($codes as $num => $msg)
|
||||
|
||||
$codes = array();
|
||||
$files = array('admin-cli.php');
|
||||
foreach(scandir(__DIR__.'/inc') as $file)
|
||||
{
|
||||
echo $num."\t".str_replace("\n","\n\t",$msg)."\n";
|
||||
if (substr($file,0,strlen('class.admin_cmd')) == 'class.admin_cmd')
|
||||
{
|
||||
$files[] = 'inc/'.$file;
|
||||
}
|
||||
}
|
||||
foreach($files as $file)
|
||||
{
|
||||
$content = file_get_contents(__DIR__.'/'.$file);
|
||||
|
||||
$matches = null;
|
||||
if (preg_match_all('/throw new (Api\\\\Exception[\\\\a-z_]*)\((.*),\\s*([0-9]+)\);/mi',$content,$matches))
|
||||
{
|
||||
//echo $file.":\n"; print_r($matches);
|
||||
foreach($matches[3] as $key => $code)
|
||||
{
|
||||
$src = preg_replace('/(self::)?\$[a-z_>-]+/i', "''", $matches[2][$key]); // gives fatal error otherwise
|
||||
@eval('$src = '.$src.';');
|
||||
|
||||
if (!empty($src) && (!isset($codes[$code]) || !in_array($src, $codes[$code])))
|
||||
{
|
||||
//if (isset($codes[$code])) echo "$file redefines #$code: ".implode(', ', $codes[$code])."\n";
|
||||
$codes[$code][] = $src;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$codes[0] = 'Ok';
|
||||
ksort($codes, SORT_NUMERIC);
|
||||
foreach($codes as $num => $msgs)
|
||||
{
|
||||
echo $num."\t".str_replace("\n","\n\t", implode(', ', (array)$msgs))."\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user