Log SQL errors.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 20 Dec 2008 17:05:47 +0000 (18:05 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 20 Dec 2008 17:05:47 +0000 (18:05 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/xdb.php
modules/core.php

index d012981..a51e210 100644 (file)
@@ -113,6 +113,11 @@ class XDB
             }
             if ($globals->debug) {
                 $text .= '<pre>' . pl_entities(XDB::_reformatQuery($query)) . '</pre>';
+            } else {
+                $file = fopen($globals->spoolroot . '/spool/tmp/query_errors', 'a');
+                fwrite($file, '<pre>' . pl_entities(XDB::_reformatQuery($query)) . '</pre>'
+                            . '<pre>' . XDB::$mysqli->error . '</pre>' . "\n");
+                fclose($file);
             }
             Platal::page()->kill($text);
             exit;
index 8792c62..fa54116 100644 (file)
@@ -30,6 +30,7 @@ class CoreModule extends PLModule
             'send_bug'    => $this->make_hook('bug', AUTH_COOKIE),
             'purge_cache' => $this->make_hook('purge_cache', AUTH_COOKIE, 'admin'),
             'kill_sessions' => $this->make_hook('kill_sessions', AUTH_COOKIE, 'admin'),
+            'sql_errors'  => $this->make_hook('sqlerror', AUTH_COOKIE, 'admin'),
             'get_rights'  => $this->make_hook('get_rights', AUTH_MDP, 'admin'),
 
             'wiki_help'    => $this->make_hook('wiki_help', AUTH_PUBLIC),
@@ -191,6 +192,21 @@ class CoreModule extends PLModule
         echo MiniWiki::wikiToHtml($text, $action == 'title');
         exit;
     }
+
+    function handler_sqlerror(&$page, $clear = null) {
+        global $globals;
+        $file = @fopen($globals->spoolroot . '/spool/tmp/query_errors', 'r');
+        if ($file !== false) {
+            echo '<html><body>';
+            fpassthru($file);
+            fclose($file);
+            echo '</html></body>';
+        }
+        if ($clear == 'clear') {
+            @unlink($globals->spoolroot . '/spool/tmp/query_errors');
+        }
+        exit;
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: