From d47ea20aa8bb8219f7a0760e81ba3db542392390 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 7 Apr 2018 16:54:49 -0700 Subject: we shouldn't need distinct here, since ids_to_querystr() will filter duplicates. It might have an effect on pager totals. Need to monitor for a few days. --- Zotlabs/Module/Channel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index 3d3eb2a85..6a334b59a 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -204,7 +204,7 @@ class Channel extends \Zotlabs\Web\Controller { $_SESSION['loadtime'] = datetime_convert(); } else { - $r = q("SELECT distinct parent AS item_id from item + $r = q("SELECT parent AS item_id from item left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids ) WHERE uid = %d $item_normal_update AND item_wall = 1 $simple_update -- cgit v1.2.3 From 0fba1a777e155781a8c59c85c4443dc4f56f165d Mon Sep 17 00:00:00 2001 From: "DM42.Net (Matt Dent)" Date: Sat, 7 Apr 2018 22:17:19 -0400 Subject: Add error handler and try/catch for all () calls --- include/plugin.php | 60 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/include/plugin.php b/include/plugin.php index 62d443ab8..29d24b410 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -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. * @@ -17,7 +35,11 @@ function unload_plugin($plugin){ @include_once('addon/' . $plugin . '/' . $plugin . '.php'); if(function_exists($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'); if(function_exists($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' ", @@ -64,7 +90,12 @@ function install_plugin($plugin) { @include_once('addon/' . $plugin . '/' . $plugin . '.php'); if(function_exists($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); @@ -94,7 +125,12 @@ function load_plugin($plugin) { @include_once('addon/' . $plugin . '/' . $plugin . '.php'); if(function_exists($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 // once most site tables have been updated. @@ -108,7 +144,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 +196,21 @@ function reload_plugins() { if(function_exists($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')) { $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", intval($t), -- cgit v1.2.3 From 35b4f0a863421fdfe27b6371516dc37805583317 Mon Sep 17 00:00:00 2001 From: "M.Dent" Date: Sat, 7 Apr 2018 23:01:18 -0400 Subject: Add class for Exceptions --- include/plugin.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/plugin.php b/include/plugin.php index 29d24b410..2ef33e6fa 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -37,7 +37,7 @@ function unload_plugin($plugin){ $func = $plugin . '_unload'; try { $func(); - } catch ($e) { + } catch (Exception $e) { handleerrors_plugin($plugin,"Unable to unload.",$e->getMessage()); } } @@ -62,7 +62,7 @@ function uninstall_plugin($plugin) { $func = $plugin . '_uninstall'; try { $func(); - } catch ($e) { + } catch (Exception $e) { handleerrors_plugin($plugin,"Unable to uninstall.","Unable to run _uninstall : ".$e->getMessage()); } } @@ -92,7 +92,7 @@ function install_plugin($plugin) { $func = $plugin . '_install'; try { $func(); - } catch ($e) { + } catch (Exception $e) { handleerrors_plugin($plugin,"Install failed.","Install failed : ".$e->getMessage()); return; } @@ -127,7 +127,7 @@ function load_plugin($plugin) { $func = $plugin . '_load'; try { $func(); - } catch ($e) { + } catch (Exception $e) { handleerrors_plugin($plugin,"Unable to load.","FAILED loading : ".$e->getMessage()); return; } @@ -198,7 +198,7 @@ function reload_plugins() { $func = $pl . '_unload'; try { $func(); - } catch ($e) { + } catch (Exception $e) { handleerrors_plugin($plugin,"","UNLOAD FAILED (uninstalling) : ".$e->getMessage(),true); continue; } @@ -207,7 +207,7 @@ function reload_plugins() { $func = $pl . '_load'; try { $func(); - } catch ($e) { + } catch (Exception $e) { handleerrors_plugin($plugin,"","LOAD FAILED (uninstalling): ".$e->getMessage(),true); continue; } -- cgit v1.2.3 From a0cba6564f5b42c0882ef1c6837677544d1ffb9f Mon Sep 17 00:00:00 2001 From: "M.Dent" Date: Sat, 7 Apr 2018 23:12:39 -0400 Subject: Uninstall plugin on Exception on load. --- include/plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/plugin.php b/include/plugin.php index 2ef33e6fa..2084f9107 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -128,7 +128,7 @@ function load_plugin($plugin) { try { $func(); } catch (Exception $e) { - handleerrors_plugin($plugin,"Unable to load.","FAILED loading : ".$e->getMessage()); + handleerrors_plugin($plugin,"Unable to load.","FAILED loading : ".$e->getMessage(),true); return; } -- cgit v1.2.3 From ff77f14f2fb628a2192997052cc5813c421de2f7 Mon Sep 17 00:00:00 2001 From: "M.Dent" Date: Sat, 7 Apr 2018 23:41:22 -0400 Subject: Remove remove plugin from \App::[] on uninstall --- include/plugin.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/plugin.php b/include/plugin.php index 2084f9107..4545e1e8d 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -20,7 +20,10 @@ function handleerrors_plugin($plugin,$notice,$log,$uninstall=false){ } if ($uninstall) { - plugin_uninstall($plugin); + $idx = array_search($plugin, \App::$plugins); + unset(\App::$plugins[$idx]); + uninstall_plugin($plugin); + set_config("system","addon", implode(", ",\App::$plugins)); } } -- cgit v1.2.3