mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 09:38:23 +01:00
Updated function dol_eval, added error handling
- There were cases that dol_eval() would break the whole system.
-That was happening in case of using a new version plugin on an old version dolibarr. New plugin validates through isModActive() instead of $conf->moduleName->enabled. Even if you were deactivating the plugin, or totally delete it, the records were still on database for menu, so there were no obvious solution. This update adds a backwards compatibility, makes doli more stable and counterparts the use of eval, making it more safe.
- Use of eval is not bad, as well there are techniques in any project that are project-related useful and smart. For example, Linux kernel uses GOTO. But in such cases, there needs to be a safety net.
-I found out this after a lot of trouble, I hope this small fix will save other developers.
👍
This commit is contained in:
committed by
Laurent Destailleur
parent
57e003a7f5
commit
3cc415af47
@@ -8914,6 +8914,7 @@ function verifCond($strToEvaluate)
|
|||||||
*/
|
*/
|
||||||
function dol_eval($s, $returnvalue = 0, $hideerrors = 1, $onlysimplestring = '1')
|
function dol_eval($s, $returnvalue = 0, $hideerrors = 1, $onlysimplestring = '1')
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
// Only global variables can be changed by eval function and returned to caller
|
// Only global variables can be changed by eval function and returned to caller
|
||||||
global $db, $langs, $user, $conf, $website, $websitepage;
|
global $db, $langs, $user, $conf, $website, $websitepage;
|
||||||
global $action, $mainmenu, $leftmenu;
|
global $action, $mainmenu, $leftmenu;
|
||||||
@@ -9017,6 +9018,13 @@ function dol_eval($s, $returnvalue = 0, $hideerrors = 1, $onlysimplestring = '1'
|
|||||||
eval($s);
|
eval($s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Error $e) {
|
||||||
|
$error = 'Caught error : ';
|
||||||
|
$error .= $e->getMessage() . ', ';
|
||||||
|
$error .= 'Trace : ';
|
||||||
|
$error .= json_encode($e->getTrace());
|
||||||
|
error_log($error, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user