diff options
author | git-marijus <mario@mariovavti.com> | 2018-04-08 11:48:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-08 11:48:05 +0200 |
commit | 73248fd227cf2673663be8e1be0fdc4e9154e5e6 (patch) | |
tree | d8c9441201d02bc6fb84e93ba7bb7cb97e093655 | |
parent | 7205ffb5c0f3973fadca198c4563b134662d6b17 (diff) | |
parent | ff77f14f2fb628a2192997052cc5813c421de2f7 (diff) | |
download | volse-hubzilla-73248fd227cf2673663be8e1be0fdc4e9154e5e6.tar.gz volse-hubzilla-73248fd227cf2673663be8e1be0fdc4e9154e5e6.tar.bz2 volse-hubzilla-73248fd227cf2673663be8e1be0fdc4e9154e5e6.zip |
Merge pull request #1048 from dentm42/plugin-error-trap
Trap plugin install/uninstall load/unload errors to avoid whitescreen
-rwxr-xr-x | include/plugin.php | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/include/plugin.php b/include/plugin.php index 62d443ab8..4545e1e8d 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -7,6 +7,27 @@ /** + * @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) { + $idx = array_search($plugin, \App::$plugins); + unset(\App::$plugins[$idx]); + uninstall_plugin($plugin); + set_config("system","addon", implode(", ",\App::$plugins)); + } +} + +/** * @brief Unloads an addon. * * @param string $plugin name of the addon @@ -17,7 +38,11 @@ function unload_plugin($plugin){ @include_once('addon/' . $plugin . '/' . $plugin . '.php'); if(function_exists($plugin . '_unload')) { $func = $plugin . '_unload'; - $func(); + try { + $func(); + } catch (Exception $e) { + handleerrors_plugin($plugin,"Unable to unload.",$e->getMessage()); + } } } @@ -38,7 +63,11 @@ function uninstall_plugin($plugin) { @include_once('addon/' . $plugin . '/' . $plugin . '.php'); if(function_exists($plugin . '_uninstall')) { $func = $plugin . '_uninstall'; - $func(); + try { + $func(); + } catch (Exception $e) { + handleerrors_plugin($plugin,"Unable to uninstall.","Unable to run _uninstall : ".$e->getMessage()); + } } q("DELETE FROM addon WHERE aname = '%s' ", @@ -64,7 +93,12 @@ function install_plugin($plugin) { @include_once('addon/' . $plugin . '/' . $plugin . '.php'); if(function_exists($plugin . '_install')) { $func = $plugin . '_install'; - $func(); + try { + $func(); + } catch (Exception $e) { + handleerrors_plugin($plugin,"Install failed.","Install failed : ".$e->getMessage()); + return; + } } $plugin_admin = (function_exists($plugin . '_plugin_admin') ? 1 : 0); @@ -94,7 +128,12 @@ function load_plugin($plugin) { @include_once('addon/' . $plugin . '/' . $plugin . '.php'); if(function_exists($plugin . '_load')) { $func = $plugin . '_load'; - $func(); + try { + $func(); + } catch (Exception $e) { + handleerrors_plugin($plugin,"Unable to load.","FAILED loading : ".$e->getMessage(),true); + return; + } // we can add the following with the previous SQL // once most site tables have been updated. @@ -108,7 +147,7 @@ function load_plugin($plugin) { return true; } else { - logger("Addons: FAILED loading " . $plugin); + logger("Addons: FAILED loading " . $plugin . " (missing _load function)"); return false; } } @@ -160,11 +199,21 @@ function reload_plugins() { if(function_exists($pl . '_unload')) { $func = $pl . '_unload'; - $func(); + try { + $func(); + } catch (Exception $e) { + handleerrors_plugin($plugin,"","UNLOAD FAILED (uninstalling) : ".$e->getMessage(),true); + continue; + } } if(function_exists($pl . '_load')) { $func = $pl . '_load'; - $func(); + try { + $func(); + } catch (Exception $e) { + handleerrors_plugin($plugin,"","LOAD FAILED (uninstalling): ".$e->getMessage(),true); + continue; + } } q("UPDATE addon SET tstamp = %d WHERE id = %d", intval($t), |