Add error handler and try/catch for all () calls
This commit is contained in:
parent
bddf8cfde4
commit
0fba1a777e
@ -6,6 +6,24 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Handle errors in plugin calls
|
||||||
|
*
|
||||||
|
* @param string $plugin name of the addon
|
||||||
|
* @param string $error_text text of error
|
||||||
|
* @param bool $uninstall uninstall plugin
|
||||||
|
*/
|
||||||
|
function handleerrors_plugin($plugin,$notice,$log,$uninstall=false){
|
||||||
|
logger("Addons: [" . $plugin . "] Error: ".$log, LOGGER_ERROR);
|
||||||
|
if ($notice != '') {
|
||||||
|
notice("[" . $plugin . "] Error: ".$notice, LOGGER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($uninstall) {
|
||||||
|
plugin_uninstall($plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unloads an addon.
|
* @brief Unloads an addon.
|
||||||
*
|
*
|
||||||
@ -17,7 +35,11 @@ function unload_plugin($plugin){
|
|||||||
@include_once('addon/' . $plugin . '/' . $plugin . '.php');
|
@include_once('addon/' . $plugin . '/' . $plugin . '.php');
|
||||||
if(function_exists($plugin . '_unload')) {
|
if(function_exists($plugin . '_unload')) {
|
||||||
$func = $plugin . '_unload';
|
$func = $plugin . '_unload';
|
||||||
$func();
|
try {
|
||||||
|
$func();
|
||||||
|
} catch ($e) {
|
||||||
|
handleerrors_plugin($plugin,"Unable to unload.",$e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +60,11 @@ function uninstall_plugin($plugin) {
|
|||||||
@include_once('addon/' . $plugin . '/' . $plugin . '.php');
|
@include_once('addon/' . $plugin . '/' . $plugin . '.php');
|
||||||
if(function_exists($plugin . '_uninstall')) {
|
if(function_exists($plugin . '_uninstall')) {
|
||||||
$func = $plugin . '_uninstall';
|
$func = $plugin . '_uninstall';
|
||||||
$func();
|
try {
|
||||||
|
$func();
|
||||||
|
} catch ($e) {
|
||||||
|
handleerrors_plugin($plugin,"Unable to uninstall.","Unable to run _uninstall : ".$e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
q("DELETE FROM addon WHERE aname = '%s' ",
|
q("DELETE FROM addon WHERE aname = '%s' ",
|
||||||
@ -64,7 +90,12 @@ function install_plugin($plugin) {
|
|||||||
@include_once('addon/' . $plugin . '/' . $plugin . '.php');
|
@include_once('addon/' . $plugin . '/' . $plugin . '.php');
|
||||||
if(function_exists($plugin . '_install')) {
|
if(function_exists($plugin . '_install')) {
|
||||||
$func = $plugin . '_install';
|
$func = $plugin . '_install';
|
||||||
$func();
|
try {
|
||||||
|
$func();
|
||||||
|
} catch ($e) {
|
||||||
|
handleerrors_plugin($plugin,"Install failed.","Install failed : ".$e->getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$plugin_admin = (function_exists($plugin . '_plugin_admin') ? 1 : 0);
|
$plugin_admin = (function_exists($plugin . '_plugin_admin') ? 1 : 0);
|
||||||
@ -94,7 +125,12 @@ function load_plugin($plugin) {
|
|||||||
@include_once('addon/' . $plugin . '/' . $plugin . '.php');
|
@include_once('addon/' . $plugin . '/' . $plugin . '.php');
|
||||||
if(function_exists($plugin . '_load')) {
|
if(function_exists($plugin . '_load')) {
|
||||||
$func = $plugin . '_load';
|
$func = $plugin . '_load';
|
||||||
$func();
|
try {
|
||||||
|
$func();
|
||||||
|
} catch ($e) {
|
||||||
|
handleerrors_plugin($plugin,"Unable to load.","FAILED loading : ".$e->getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// we can add the following with the previous SQL
|
// we can add the following with the previous SQL
|
||||||
// once most site tables have been updated.
|
// once most site tables have been updated.
|
||||||
@ -108,7 +144,7 @@ function load_plugin($plugin) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger("Addons: FAILED loading " . $plugin);
|
logger("Addons: FAILED loading " . $plugin . " (missing _load function)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,11 +196,21 @@ function reload_plugins() {
|
|||||||
|
|
||||||
if(function_exists($pl . '_unload')) {
|
if(function_exists($pl . '_unload')) {
|
||||||
$func = $pl . '_unload';
|
$func = $pl . '_unload';
|
||||||
$func();
|
try {
|
||||||
|
$func();
|
||||||
|
} catch ($e) {
|
||||||
|
handleerrors_plugin($plugin,"","UNLOAD FAILED (uninstalling) : ".$e->getMessage(),true);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(function_exists($pl . '_load')) {
|
if(function_exists($pl . '_load')) {
|
||||||
$func = $pl . '_load';
|
$func = $pl . '_load';
|
||||||
$func();
|
try {
|
||||||
|
$func();
|
||||||
|
} catch ($e) {
|
||||||
|
handleerrors_plugin($plugin,"","LOAD FAILED (uninstalling): ".$e->getMessage(),true);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
q("UPDATE addon SET tstamp = %d WHERE id = %d",
|
q("UPDATE addon SET tstamp = %d WHERE id = %d",
|
||||||
intval($t),
|
intval($t),
|
||||||
|
Reference in New Issue
Block a user