From ff949e761dc99a5d054b3a9bebca0972d9c4df8c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Fri, 5 Apr 2013 23:24:43 +0200 Subject: [PATCH] Add (optional) raven error handler. --- .gitmodules | 3 +++ classes/xorg.php | 25 +++++++++++++++++++++++++ configs/platal.ini | 5 +++++ core | 2 +- include/common.inc.php | 17 +++++++++++++---- include/raven | 1 + modules/platal.php | 7 +++++++ 7 files changed, 55 insertions(+), 5 deletions(-) create mode 160000 include/raven diff --git a/.gitmodules b/.gitmodules index addee92..4cfddd9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "banana"] path = banana url = git://git.polytechnique.org/banana.git +[submodule "include/raven"] + path = include/raven + url = git://github.com/getsentry/raven-php.git diff --git a/classes/xorg.php b/classes/xorg.php index 5aa0bd9..e920dc1 100644 --- a/classes/xorg.php +++ b/classes/xorg.php @@ -78,6 +78,31 @@ class Xorg extends Platal $page->assign_by_ref('platal', $this); $page->run(); } + + public function setup_raven() + { + $sentry_dsn = self::globals()->core->sentry_dsn; + + if (strlen($sentry_dsn) == 0) { + return null; + } + + require_once('raven/lib/Raven/Autoloader.php'); + + Raven_Autoloader::register(); + + return new Raven_Client($sentry_dsn); + } + + protected function report_error($error) + { + parent::report_error($error); + + $raven = $this->setup_raven(); + if ($raven != null) { + $raven->captureException($error); + } + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --git a/configs/platal.ini b/configs/platal.ini index a421802..cfc3820 100644 --- a/configs/platal.ini +++ b/configs/platal.ini @@ -155,6 +155,11 @@ skin = "default" econfiance = "" +; $globals->core->sentry_dsn +; Key used to log errors to Sentry +sentry_dsn = "" + + ; The API section contains the configuration for the web services. [Api] diff --git a/core b/core index a315ff7..f3f26e2 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit a315ff7281b69e71aca8670df8c8b6063dddee9d +Subproject commit f3f26e2b84a4ddd6c1daf3013bfa8adc252b727a diff --git a/include/common.inc.php b/include/common.inc.php index 031c38c..d26f8f2 100644 --- a/include/common.inc.php +++ b/include/common.inc.php @@ -19,20 +19,20 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -function __autoload($cls) +function xorg_autoload($cls) { if (!pl_autoload($cls)) { $cls = strtolower($cls); if (substr($cls, 0, 4) == 'ufc_' || substr($cls, 0, 4) == 'ufo_' || $cls == 'profilefilter' || $cls == 'userfiltercondition' || $cls == 'userfilterorder') { - __autoload('userfilter'); + xorg_autoload('userfilter'); return; } else if (substr($cls, 0, 4) == 'pfc_' || substr($cls, 0, 4) == 'pfo_' || substr($cls, 0, 8) == 'plfilter') { - __autoload('plfilter'); + xorg_autoload('plfilter'); return; } else if (substr($cls, 0, 3) == 'de_') { - __autoload('direnum'); + xorg_autoload('direnum'); return; } else if ($cls == 'validate' || substr($cls, -3, 3) == 'req' || substr($cls, -8, 8) == 'validate' || substr($cls, 0, 8) == 'validate') { @@ -42,11 +42,20 @@ function __autoload($cls) require_once 'banana/hooks.inc.php'; Banana::load(substr($cls, 6)); return; + } else if (substr($cls, 0, 5) == 'raven') { + // Handled by Raven autoloader. + return; } include "$cls.inc.php"; } } +function __autoload($cls) +{ + return xorg_autoload($cls); +} + +spl_autoload_register('xorg_autoload'); // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?> diff --git a/include/raven b/include/raven new file mode 160000 index 0000000..cf35053 --- /dev/null +++ b/include/raven @@ -0,0 +1 @@ +Subproject commit cf3505369911d8f4ce3eb59dc9e1baba29cf72cf diff --git a/modules/platal.php b/modules/platal.php index 454a7bb..481b4c4 100644 --- a/modules/platal.php +++ b/modules/platal.php @@ -59,6 +59,8 @@ class PlatalModule extends PLModule 'exit' => $this->make_hook('exit', AUTH_PUBLIC), 'review' => $this->make_hook('review', AUTH_PUBLIC), 'deconnexion.php' => $this->make_hook('exit', AUTH_PUBLIC), + + 'error' => $this->make_hook('test_error', AUTH_COOKIE), ); } @@ -610,6 +612,11 @@ Adresse de secours : ' . $to)); } $wiz->apply($page, 'review', $action, $mode); } + + function handler_test_error($page) + { + throw new Exception("Blih"); + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: -- 2.1.4