Make logging & message handling functions accept extra parameters to format messages using sprintf
This commit is contained in:
parent
efc7352404
commit
dba4c6fa9e
6 changed files with 126 additions and 127 deletions
|
@ -5,12 +5,12 @@ function add_cli_command($command, $handler, $short_desc, $usage_args=false, $lo
|
||||||
$override=false) {
|
$override=false) {
|
||||||
global $cli_commands;
|
global $cli_commands;
|
||||||
if (array_key_exists($command, $cli_commands) && !$override) {
|
if (array_key_exists($command, $cli_commands) && !$override) {
|
||||||
logging('ERROR', sprintf(_("The CLI command '%s' already exists.", $command)));
|
logging('ERROR', _("The CLI command '%s' already exists.", $command));
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_callable($handler)) {
|
if (!is_callable($handler)) {
|
||||||
logging('ERROR', sprintf(_("The CLI command '%s' handler is not callable !"), $command));
|
logging('ERROR', _("The CLI command '%s' handler is not callable !"), $command);
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,14 @@ $cli_command = null;
|
||||||
function usage($error=false) {
|
function usage($error=false) {
|
||||||
global $cli_commands, $cli_command, $argv;
|
global $cli_commands, $cli_command, $argv;
|
||||||
|
|
||||||
|
// If more than 1 arguments passed, format error message using sprintf
|
||||||
|
if (func_num_args() > 1) {
|
||||||
|
$error = call_user_func_array(
|
||||||
|
'sprintf',
|
||||||
|
array_merge(array($error), array_slice(func_get_args(), 1))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ($error)
|
if ($error)
|
||||||
echo "$error\n\n";
|
echo "$error\n\n";
|
||||||
printf(_("Usage: %s [-h] [-qd] command\n"), basename($argv[0]));
|
printf(_("Usage: %s [-h] [-qd] command\n"), basename($argv[0]));
|
||||||
|
@ -115,10 +123,10 @@ function handle_cli_args() {
|
||||||
$command_args[] = $argv[$i];
|
$command_args[] = $argv[$i];
|
||||||
else
|
else
|
||||||
usage(
|
usage(
|
||||||
sprintf(
|
_(
|
||||||
_("Invalid parameter \"%s\".\nNote: Command's parameter/argument must be place ".
|
"Invalid parameter \"%s\".\nNote: Command's parameter/argument must be place ".
|
||||||
"after the command."), $argv[$i]
|
"after the command."
|
||||||
)
|
), $argv[$i]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,11 +136,8 @@ function handle_cli_args() {
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
logging(
|
logging(
|
||||||
'DEBUG', sprintf(
|
'DEBUG', "Run %s command %s with argument(s) '%s'.",
|
||||||
"Run %s command %s with argument(s) '%s'.",
|
basename($argv[0]), $cli_command, implode("', '", $command_args)
|
||||||
basename($argv[0]), $cli_command,
|
|
||||||
implode("', '", $command_args)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -141,7 +146,7 @@ function handle_cli_args() {
|
||||||
exit($result?0:1);
|
exit($result?0:1);
|
||||||
}
|
}
|
||||||
catch(Exception $e) {
|
catch(Exception $e) {
|
||||||
log_exception(sprintf(_("An exception occured running command %s"), $cli_command));
|
log_exception($e, _("An exception occured running command %s"), $cli_command);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,7 +264,7 @@ function cli_show($command_args) {
|
||||||
$item = get_item($item_id);
|
$item = get_item($item_id);
|
||||||
|
|
||||||
if (!$item)
|
if (!$item)
|
||||||
logging('FATAL', sprintf(_("Item #%s not found."), $item_id));
|
logging('FATAL', _("Item #%s not found."), $item_id);
|
||||||
|
|
||||||
print_item_info($item);
|
print_item_info($item);
|
||||||
return True;
|
return True;
|
||||||
|
@ -283,7 +288,7 @@ function cli_delete($command_args) {
|
||||||
$item_id = $command_args[0];
|
$item_id = $command_args[0];
|
||||||
$item = get_item($item_id);
|
$item = get_item($item_id);
|
||||||
if (!$item)
|
if (!$item)
|
||||||
logging('FATAL', sprintf(_("Item #%s not found."), $item_id));
|
logging('FATAL', _("Item #%s not found."), $item_id);
|
||||||
|
|
||||||
print_item_info($item);
|
print_item_info($item);
|
||||||
|
|
||||||
|
@ -298,7 +303,7 @@ function cli_delete($command_args) {
|
||||||
echo "\n";
|
echo "\n";
|
||||||
|
|
||||||
if (!delete_item($item['id']))
|
if (!delete_item($item['id']))
|
||||||
logging('FATAL', sprintf(_("An error occured deleting item #%d."), $item_id));
|
logging('FATAL', _("An error occured deleting item #%d."), $item_id);
|
||||||
|
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
@ -376,31 +381,27 @@ function cli_cron($command_args) {
|
||||||
foreach($items['items'] as $item) {
|
foreach($items['items'] as $item) {
|
||||||
if ($item['date'] < $limit) {
|
if ($item['date'] < $limit) {
|
||||||
if ($just_try) {
|
if ($just_try) {
|
||||||
logging('DEBUG', sprintf(
|
logging('DEBUG', 'Just-try mode: do not really delete item #%s (%s, creation date: %s)',
|
||||||
'Just-try mode: do not really delete item #%s (%s, creation date: %s)',
|
|
||||||
$item['id'], $item['name'], format_time($item['date'])
|
$item['id'], $item['name'], format_time($item['date'])
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
else if (delete_item($item['id'])) {
|
else if (delete_item($item['id'])) {
|
||||||
logging('INFO', sprintf(
|
logging('INFO', 'Item #%s (%s) deleted (creation date: %s)',
|
||||||
'Item #%s (%s) deleted (creation date: %s)',
|
$item['id'], $item['name'], format_time($item['date'])
|
||||||
|
);
|
||||||
));
|
|
||||||
remove_item_attachments($item['id']);
|
remove_item_attachments($item['id']);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logging('ERROR', sprintf(
|
logging('ERROR', 'Fail to delete item "%s" (%s, creation date: %s)',
|
||||||
'Fail to delete item "%s" (%s, creation date: %s)',
|
|
||||||
$item['id'], $item['name'], format_time($item['date'])
|
$item['id'], $item['name'], format_time($item['date'])
|
||||||
));
|
);
|
||||||
$error = true;
|
$error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logging('DEBUG', sprintf(
|
logging('DEBUG', 'Item "%s" (%s) still valid (creation date: %s)',
|
||||||
'Item "%s" (%s) still valid (creation date: %s)',
|
|
||||||
$item['id'], $item['name'], format_time($item['date'])
|
$item['id'], $item['name'], format_time($item['date'])
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit($error?1:0);
|
exit($error?1:0);
|
||||||
|
|
|
@ -353,7 +353,10 @@ function search_items($params) {
|
||||||
logging('ERROR', 'search_items() : search in DB return false');
|
logging('ERROR', 'search_items() : search in DB return false');
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
log_exception($e, "An exception occured searching items with params ".preg_replace("/\n[ \t]*/"," ",print_r($params,1))." infos from database : ");
|
log_exception(
|
||||||
|
$e, "An exception occured searching items with params %s infos from database : ",
|
||||||
|
preg_replace("/\n[ \t]*/", " ", print_r($params, true))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,14 @@ function logging($level, $message) {
|
||||||
$_log_file_fd = fopen($log_file, 'a');
|
$_log_file_fd = fopen($log_file, 'a');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If more than 2 arguments passed, format message using sprintf
|
||||||
|
if (func_num_args() > 2) {
|
||||||
|
$message = call_user_func_array(
|
||||||
|
'sprintf',
|
||||||
|
array_merge(array($message), array_slice(func_get_args(), 2))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (php_sapi_name() == "cli") {
|
if (php_sapi_name() == "cli") {
|
||||||
$msg = implode(' - ', array(
|
$msg = implode(' - ', array(
|
||||||
date('Y/m/d H:i:s'),
|
date('Y/m/d H:i:s'),
|
||||||
|
@ -110,18 +118,27 @@ function get_debug_backtrace_context($ignore_last=0) {
|
||||||
return implode("\n", $msg);
|
return implode("\n", $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function log_exception($exception, $prefix='') {
|
function log_exception($exception, $prefix=null) {
|
||||||
|
// If more than 2 arguments passed, format prefix message using sprintf
|
||||||
|
if ($prefix && func_num_args() > 2) {
|
||||||
|
$prefix = call_user_func_array(
|
||||||
|
'sprintf',
|
||||||
|
array_merge(array($prefix), array_slice(func_get_args(), 2))
|
||||||
|
);
|
||||||
|
}
|
||||||
logging(
|
logging(
|
||||||
"ERROR",
|
"ERROR", "%s:\n%s\n## %s:%d : %s",
|
||||||
($prefix?"$prefix :\n":"An exception occured :\n").
|
($prefix?$prefix:"An exception occured"),
|
||||||
get_debug_backtrace_context(1). "\n" .
|
get_debug_backtrace_context(1),
|
||||||
"## ".$exception->getFile().":".$exception->getLine(). " : ". $exception->getMessage());
|
$exception->getFile(), $exception->getLine(),
|
||||||
|
$exception->getMessage());
|
||||||
}
|
}
|
||||||
set_exception_handler('log_exception');
|
set_exception_handler('log_exception');
|
||||||
|
|
||||||
// Handle PHP error logging
|
// Handle PHP error logging
|
||||||
function log_php_eror($errno, $errstr, $errfile, $errline) {
|
function log_php_eror($errno, $errstr, $errfile, $errline) {
|
||||||
logging("ERROR", "A PHP error occured : [$errno] $errstr\nFile : $errfile (line : $errline)");
|
logging("ERROR", "A PHP error occured : [%d] %s\nFile : %s (line : %d)",
|
||||||
|
$errno, $errstr, $errfile, $errline);
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
if ($log_level == 'DEBUG')
|
if ($log_level == 'DEBUG')
|
||||||
|
|
|
@ -85,13 +85,27 @@ $smarty->assign('session_key', $_SESSION['session_key']);
|
||||||
if (!isset($_SESSION['errors']))
|
if (!isset($_SESSION['errors']))
|
||||||
$_SESSION['errors']=array();
|
$_SESSION['errors']=array();
|
||||||
function add_error($error) {
|
function add_error($error) {
|
||||||
$_SESSION['errors'][]=$error;
|
// If more than one arguments passed, format error message using sprintf
|
||||||
|
if (func_num_args() > 2) {
|
||||||
|
$error = call_user_func_array(
|
||||||
|
'sprintf',
|
||||||
|
array_merge(array($error), array_slice(func_get_args(), 1))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$_SESSION['errors'][] = $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($_SESSION['messages']))
|
if (!isset($_SESSION['messages']))
|
||||||
$_SESSION['messages']=array();
|
$_SESSION['messages']=array();
|
||||||
function add_message($message) {
|
function add_message($message) {
|
||||||
$_SESSION['messages'][]=$message;
|
// If more than one arguments passed, format message using sprintf
|
||||||
|
if (func_num_args() > 2) {
|
||||||
|
$message = call_user_func_array(
|
||||||
|
'sprintf',
|
||||||
|
array_merge(array($message), array_slice(func_get_args(), 1))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$_SESSION['messages'][] = $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle CSS & JS files included
|
// Handle CSS & JS files included
|
||||||
|
@ -133,6 +147,13 @@ function display_template($template, $pagetitle=false) {
|
||||||
if (!$template)
|
if (!$template)
|
||||||
logging("FATAL", _("No template specified."));
|
logging("FATAL", _("No template specified."));
|
||||||
global $smarty;
|
global $smarty;
|
||||||
|
// If more than 2 arguments passed, format pagetitle using sprintf
|
||||||
|
if ($pagetitle & func_num_args() > 2) {
|
||||||
|
$pagetitle = call_user_func_array(
|
||||||
|
'sprintf',
|
||||||
|
array_merge(array($pagetitle), array_slice(func_get_args(), 2))
|
||||||
|
);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
_defineCommonTemplateVariables($template, $pagetitle);
|
_defineCommonTemplateVariables($template, $pagetitle);
|
||||||
$smarty->display($template);
|
$smarty->display($template);
|
||||||
|
|
|
@ -162,24 +162,14 @@ function cli_update_messages($command_args) {
|
||||||
$compendium_args = array();
|
$compendium_args = array();
|
||||||
foreach ($command_args as $path) {
|
foreach ($command_args as $path) {
|
||||||
if (!file_exists($path))
|
if (!file_exists($path))
|
||||||
logging(
|
logging('FATAL', _("Compendium file %s not found."), $path);
|
||||||
'FATAL', sprintf(
|
|
||||||
_("Compendium file %s not found."),
|
|
||||||
$path
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$compendium_args[] = '-C';
|
$compendium_args[] = '-C';
|
||||||
$compendium_args[] = $path;
|
$compendium_args[] = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pot_file = "$root_lang_dir/messages.pot";
|
$pot_file = "$root_lang_dir/messages.pot";
|
||||||
if (!is_file($pot_file))
|
if (!is_file($pot_file))
|
||||||
logging(
|
logging('FATAL', _("POT file not found (%s). Please run extract_messages first."), $pot_file);
|
||||||
'FATAL', sprintf(
|
|
||||||
_("POT file not found (%s). Please run extract_messages first."),
|
|
||||||
$pot_file
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($dh = opendir($root_lang_dir)) {
|
if ($dh = opendir($root_lang_dir)) {
|
||||||
$error = False;
|
$error = False;
|
||||||
|
@ -191,16 +181,14 @@ function cli_update_messages($command_args) {
|
||||||
)
|
)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
logging('DEBUG', sprintf(_("Lang directory '%s' found"), $file));
|
logging('DEBUG', _("Lang directory '%s' found"), $file);
|
||||||
|
|
||||||
// Check LC_MESSAGES directory exists
|
// Check LC_MESSAGES directory exists
|
||||||
$lang = $file;
|
$lang = $file;
|
||||||
$lang_dir = $root_lang_dir . '/' . $file . '/LC_MESSAGES' ;
|
$lang_dir = $root_lang_dir . '/' . $file . '/LC_MESSAGES' ;
|
||||||
if (!is_dir($lang_dir)) {
|
if (!is_dir($lang_dir)) {
|
||||||
logging('DEBUG', sprintf(
|
logging('DEBUG', _("LC_MESSAGES directory not found in lang '%s' directory, ignore it."),
|
||||||
_("LC_MESSAGES directory not found in lang '%s' directory, ignore it."),
|
$lang);
|
||||||
$lang)
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,10 +202,8 @@ function cli_update_messages($command_args) {
|
||||||
if (is_array($result) && $result[0] == 0) {
|
if (is_array($result) && $result[0] == 0) {
|
||||||
$created = true;
|
$created = true;
|
||||||
} else {
|
} else {
|
||||||
logging('ERROR', sprintf(
|
logging('ERROR', _("Fail to init messages in %s PO file using msginit (%s)."),
|
||||||
_("Fail to init messages in %s PO file using msginit (%s)."),
|
$lang, $po_file);
|
||||||
$lang, $po_file)
|
|
||||||
);
|
|
||||||
$error = True;
|
$error = True;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,25 +220,20 @@ function cli_update_messages($command_args) {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if (!is_array($result) || $result[0] != 0) {
|
if (!is_array($result) || $result[0] != 0) {
|
||||||
logging('ERROR', sprintf(
|
logging('ERROR', _("Fail to update messages in %s PO file using msgmerge (%s)."),
|
||||||
_("Fail to update messages in %s PO file using msgmerge (%s)."),
|
$lang, $po_file);
|
||||||
$lang, $po_file)
|
|
||||||
);
|
|
||||||
$error = True;
|
$error = True;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif (!$created) {
|
elseif (!$created) {
|
||||||
logging('DEBUG', sprintf(
|
logging('DEBUG', _("PO file not found in lang '%s' directory, ignore it."), $lang);
|
||||||
_("PO file not found in lang '%s' directory, ignore it."),
|
|
||||||
$lang)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir($dh);
|
closedir($dh);
|
||||||
return !$error;
|
return !$error;
|
||||||
}
|
}
|
||||||
|
|
||||||
logging('FATAL', sprintf(_("Fail to open root lang directory (%s)."), $root_dir_path));
|
logging('FATAL', _("Fail to open root lang directory (%s)."), $root_dir_path);
|
||||||
}
|
}
|
||||||
add_cli_command(
|
add_cli_command(
|
||||||
'update_messages',
|
'update_messages',
|
||||||
|
@ -286,70 +267,53 @@ function cli_compile_messages($command_args) {
|
||||||
if (dirname($real_lang_dir) != '.' || !is_dir($root_lang_dir . '/' . $real_lang_dir))
|
if (dirname($real_lang_dir) != '.' || !is_dir($root_lang_dir . '/' . $real_lang_dir))
|
||||||
continue;
|
continue;
|
||||||
$lang = $file;
|
$lang = $file;
|
||||||
logging('DEBUG', sprintf(_("Lang alias symlink found: %s -> %s"), $lang, $real_lang_dir));
|
logging('DEBUG', _("Lang alias symlink found: %s -> %s"), $lang, $real_lang_dir);
|
||||||
|
|
||||||
// Create JSON catalog symlink (if not exists)
|
// Create JSON catalog symlink (if not exists)
|
||||||
$json_link = "$root_dir_path/public_html/translations/$lang.json";
|
$json_link = "$root_dir_path/public_html/translations/$lang.json";
|
||||||
$link_target = "$real_lang_dir.json";
|
$link_target = "$real_lang_dir.json";
|
||||||
if (!file_exists($json_link)) {
|
if (!file_exists($json_link)) {
|
||||||
if (symlink($link_target, $json_link)) {
|
if (symlink($link_target, $json_link)) {
|
||||||
logging(
|
logging('INFO', _("JSON catalog symlink for %s -> %s created (%s)"),
|
||||||
'INFO',
|
$lang, $real_lang_dir, $json_link);
|
||||||
sprintf(
|
|
||||||
_("JSON catalog symlink for %s -> %s created (%s)"),
|
|
||||||
$lang, $real_lang_dir, $json_link)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logging(
|
logging('ERROR', _("Fail to create JSON catalog symlink for %s -> %s (%s)"),
|
||||||
'ERROR',
|
$lang, $real_lang_dir, $json_link);
|
||||||
sprintf(
|
|
||||||
_("Fail to create JSON catalog symlink for %s -> %s (%s)"),
|
|
||||||
$lang, $real_lang_dir, $json_link)
|
|
||||||
);
|
|
||||||
$error = True;
|
$error = True;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif (readlink($json_link) == $link_target) {
|
elseif (readlink($json_link) == $link_target) {
|
||||||
logging(
|
logging('DEBUG', _("JSON catalog symlink for %s -> %s already exist (%s)"),
|
||||||
'DEBUG',
|
$lang, $real_lang_dir, $json_link);
|
||||||
sprintf(
|
|
||||||
_("JSON catalog symlink for %s -> %s already exist (%s)"),
|
|
||||||
$lang, $real_lang_dir, $json_link)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logging(
|
logging(
|
||||||
'WARNING',
|
'WARNING',
|
||||||
sprintf(
|
_("JSON catalog file for %s already exist, but it's not a symlink to %s (%s)"),
|
||||||
_("JSON catalog file for %s already exist, but it's not a symlink to %s (%s)"),
|
$lang, $real_lang_dir, $json_link
|
||||||
$lang, $real_lang_dir, $json_link)
|
|
||||||
);
|
);
|
||||||
$error = True;
|
$error = True;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
logging('DEBUG', sprintf(_("Lang directory '%s' found"), $file));
|
logging('DEBUG', _("Lang directory '%s' found"), $file);
|
||||||
|
|
||||||
// Check LC_MESSAGES directory exists
|
// Check LC_MESSAGES directory exists
|
||||||
$lang = $file;
|
$lang = $file;
|
||||||
$lang_dir = $root_lang_dir . '/' . $file . '/LC_MESSAGES' ;
|
$lang_dir = $root_lang_dir . '/' . $file . '/LC_MESSAGES' ;
|
||||||
if (!is_dir($lang_dir)) {
|
if (!is_dir($lang_dir)) {
|
||||||
logging('DEBUG', sprintf(
|
logging('DEBUG', _("LC_MESSAGES directory not found in lang '%s' directory, ignore it."),
|
||||||
_("LC_MESSAGES directory not found in lang '%s' directory, ignore it."),
|
$lang);
|
||||||
$lang)
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test .PO file is present
|
// Test .PO file is present
|
||||||
$po_file = $lang_dir . '/' . TEXT_DOMAIN . '.po';
|
$po_file = $lang_dir . '/' . TEXT_DOMAIN . '.po';
|
||||||
if (!is_file($po_file)) {
|
if (!is_file($po_file)) {
|
||||||
logging('DEBUG', sprintf(
|
logging('DEBUG', _("PO file not found in lang '%s' directory, ignore it."),
|
||||||
_("PO file not found in lang '%s' directory, ignore it."),
|
$lang);
|
||||||
$lang)
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,9 +324,10 @@ function cli_compile_messages($command_args) {
|
||||||
array("msgfmt", "-o", $mo_file, $po_file)
|
array("msgfmt", "-o", $mo_file, $po_file)
|
||||||
);
|
);
|
||||||
if (!is_array($result) || $result[0] != 0) {
|
if (!is_array($result) || $result[0] != 0) {
|
||||||
logging('ERROR', sprintf(
|
logging(
|
||||||
|
'ERROR',
|
||||||
_("Fail to compile messages from %s PO file as MO file using msgfmt (%s)."),
|
_("Fail to compile messages from %s PO file as MO file using msgfmt (%s)."),
|
||||||
$lang, $po_file)
|
$lang, $po_file
|
||||||
);
|
);
|
||||||
$error = True;
|
$error = True;
|
||||||
}
|
}
|
||||||
|
@ -371,31 +336,24 @@ function cli_compile_messages($command_args) {
|
||||||
$json_catalog = po2json($lang, $po_file);
|
$json_catalog = po2json($lang, $po_file);
|
||||||
$json_file = "$root_dir_path/public_html/translations/$lang.json";
|
$json_file = "$root_dir_path/public_html/translations/$lang.json";
|
||||||
if(!$fd = fopen($json_file, 'w')) {
|
if(!$fd = fopen($json_file, 'w')) {
|
||||||
logging('ERROR', sprintf(
|
logging('ERROR', _("Fail to open %s JSON catalog file in write mode (%s)."),
|
||||||
_("Fail to open %s JSON catalog file in write mode (%s)."),
|
$lang, $json_file);
|
||||||
$lang, $json_file)
|
|
||||||
);
|
|
||||||
$error = True;
|
$error = True;
|
||||||
}
|
}
|
||||||
elseif (fwrite($fd, $json_catalog) === false) {
|
elseif (fwrite($fd, $json_catalog) === false) {
|
||||||
logging('ERROR', sprintf(
|
logging('ERROR', _("Fail to write %s JSON catalog in file (%s)."),
|
||||||
_("Fail to write %s JSON catalog in file (%s)."),
|
$lang, $json_file);
|
||||||
$lang, $json_file)
|
|
||||||
);
|
|
||||||
$error = True;
|
$error = True;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logging('INFO', sprintf(
|
logging('INFO', _("%s JSON catalog writed (%s)."), $lang, $json_file);
|
||||||
_("%s JSON catalog writed (%s)."),
|
|
||||||
$lang, $json_file)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir($dh);
|
closedir($dh);
|
||||||
|
|
||||||
return !$error;
|
return !$error;
|
||||||
}
|
}
|
||||||
logging('FATAL', sprintf(_("Fail to open root lang directory (%s)."), $root_dir_path));
|
logging('FATAL', _("Fail to open root lang directory (%s)."), $root_dir_path);
|
||||||
}
|
}
|
||||||
add_cli_command(
|
add_cli_command(
|
||||||
'compile_messages',
|
'compile_messages',
|
||||||
|
|
|
@ -125,8 +125,8 @@ function handle_show($request) {
|
||||||
));
|
));
|
||||||
|
|
||||||
display_template(
|
display_template(
|
||||||
"show.tpl",
|
"show.tpl", _("Element %s"),
|
||||||
sprintf(_("Element %s"), (is_array($item)?$item['name']:"#".$request -> id))
|
(is_array($item)?$item['name']:"#".$request -> id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
add_url_handler('|^item/(?P<id>[0-9]+)$|', 'handle_show');
|
add_url_handler('|^item/(?P<id>[0-9]+)$|', 'handle_show');
|
||||||
|
@ -139,7 +139,7 @@ function handle_create($request) {
|
||||||
if (isset($_POST['submit']) && empty($field_errors)) {
|
if (isset($_POST['submit']) && empty($field_errors)) {
|
||||||
$item = add_item($info);
|
$item = add_item($info);
|
||||||
if (is_array($item)) {
|
if (is_array($item)) {
|
||||||
add_message(sprintf(_("The element '% s' has been created."), $item['name']));
|
add_message(_("The element '% s' has been created."), $item['name']);
|
||||||
redirect('item/'.$item['id']);
|
redirect('item/'.$item['id']);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -180,11 +180,11 @@ function handle_modify($request) {
|
||||||
}
|
}
|
||||||
logging('DEBUG', 'Changes : '.vardump($changes));
|
logging('DEBUG', 'Changes : '.vardump($changes));
|
||||||
if (empty($changes)) {
|
if (empty($changes)) {
|
||||||
add_message(sprintf(_("You have not made any changes to element '% s'."), $item['name']));
|
add_message(_("You have not made any changes to element '% s'."), $item['name']);
|
||||||
redirect('item/'.$item['id']);
|
redirect('item/'.$item['id']);
|
||||||
}
|
}
|
||||||
else if (update_item($item['id'], $changes) === true) {
|
else if (update_item($item['id'], $changes) === true) {
|
||||||
add_message(sprintf(_("The element '% s' has been updated successfully."), $item['name']));
|
add_message(_("The element '% s' has been updated successfully."), $item['name']);
|
||||||
redirect('item/'.$item['id']);
|
redirect('item/'.$item['id']);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -207,7 +207,10 @@ function handle_modify($request) {
|
||||||
error_404();
|
error_404();
|
||||||
}
|
}
|
||||||
|
|
||||||
display_template("form.tpl", sprintf(_("Element %s: Modification"), (is_array($item)?$item['name']:"#".$request -> id)));
|
display_template(
|
||||||
|
"form.tpl", _("Element %s: Modification"),
|
||||||
|
(is_array($item)?$item['name']:"#".$request -> id)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
add_url_handler('|^item/(?P<id>[0-9]+)/modify$|', 'handle_modify');
|
add_url_handler('|^item/(?P<id>[0-9]+)/modify$|', 'handle_modify');
|
||||||
|
|
||||||
|
@ -216,7 +219,7 @@ function handle_archive($request) {
|
||||||
|
|
||||||
$item = get_item_from_url($request -> id);
|
$item = get_item_from_url($request -> id);
|
||||||
if(!is_array($item)) {
|
if(!is_array($item)) {
|
||||||
add_error(sprintf(_("Item #% s not found."), $request -> id));
|
add_error(_("Item #% s not found."), $request -> id);
|
||||||
redirect('item');
|
redirect('item');
|
||||||
}
|
}
|
||||||
elseif ($item['status'] == 'archived') {
|
elseif ($item['status'] == 'archived') {
|
||||||
|
@ -226,9 +229,7 @@ function handle_archive($request) {
|
||||||
add_error(_('You cannot archive this item.'));
|
add_error(_('You cannot archive this item.'));
|
||||||
}
|
}
|
||||||
else if (archive_item($item['id']) === true) {
|
else if (archive_item($item['id']) === true) {
|
||||||
add_message(sprintf(
|
add_message(_("The element '% s' has been archived successfully."), $item['name']);
|
||||||
_("The element '% s' has been archived successfully."),
|
|
||||||
$item['name']));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
add_error(_('An error occurred while archiving this item.'));
|
add_error(_('An error occurred while archiving this item.'));
|
||||||
|
@ -242,15 +243,13 @@ function handle_delete($request) {
|
||||||
|
|
||||||
$item = get_item_from_url($request -> id);
|
$item = get_item_from_url($request -> id);
|
||||||
if(!is_array($item)) {
|
if(!is_array($item)) {
|
||||||
add_error(sprintf(_("Item #% s not found."), $request -> id));
|
add_error(_("Item #% s not found."), $request -> id);
|
||||||
}
|
}
|
||||||
else if (!can_delete($item)) {
|
else if (!can_delete($item)) {
|
||||||
add_error(_('You cannot delete this item.'));
|
add_error(_('You cannot delete this item.'));
|
||||||
}
|
}
|
||||||
else if (delete_item($item['id']) === true) {
|
else if (delete_item($item['id']) === true) {
|
||||||
add_message(sprintf(
|
add_message(_("The element '% s' has been deleted successfully."), $item['name']);
|
||||||
_("The element '% s' has been deleted successfully."),
|
|
||||||
$item['name']));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
add_error(_('An error occurred while deleting this item.'));
|
add_error(_('An error occurred while deleting this item.'));
|
||||||
|
|
Loading…
Reference in a new issue