Add (optional) raven error handler.
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Fri, 5 Apr 2013 21:24:43 +0000 (23:24 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Fri, 5 Apr 2013 21:24:46 +0000 (23:24 +0200)
.gitmodules
classes/xorg.php
configs/platal.ini
core
include/common.inc.php
include/raven [new submodule]
modules/platal.php

index addee92..4cfddd9 100644 (file)
@@ -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
index 5aa0bd9..e920dc1 100644 (file)
@@ -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:
index a421802..cfc3820 100644 (file)
@@ -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 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit a315ff7281b69e71aca8670df8c8b6063dddee9d
+Subproject commit f3f26e2b84a4ddd6c1daf3013bfa8adc252b727a
index 031c38c..d26f8f2 100644 (file)
  *  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 (submodule)
index 0000000..cf35053
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit cf3505369911d8f4ce3eb59dc9e1baba29cf72cf
index 454a7bb..481b4c4 100644 (file)
@@ -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: