From: Raphaël Barrois Date: Mon, 22 Feb 2010 20:47:42 +0000 (+0100) Subject: Add Platal::assert() function X-Git-Tag: core/1.1.0~72 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=ec60dba7a82f71656896e0ea3acb4b74eafbb15c;p=platal.git Add Platal::assert() function Used to put assertion in the code. If an assertion fails, a message is written to spool/tmp/assert_errors, and another one is shown to the user Signed-off-by: Raphaël Barrois --- diff --git a/classes/platal.php b/classes/platal.php index 866d7c2..6d32374 100644 --- a/classes/platal.php +++ b/classes/platal.php @@ -356,6 +356,20 @@ abstract class Platal } } + public static function assert($cond, $error, $userfriendly) + { + global $globals; + if ($cond === false) { + header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error'); + $file = fopen($globals->spoolroot . '/spool/tmp/assert_erros', 'a'); + fwrite($file, '
' . pl_entities($error) . '
\n'); + fclose($file); + + Platal::page()->kill($userfriendly); + } + } + + static public function &page() { global $platal; diff --git a/modules/core.php b/modules/core.php index 63d7d9e..adbcf38 100644 --- a/modules/core.php +++ b/modules/core.php @@ -31,6 +31,7 @@ class CoreModule extends PLModule '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'), + 'assert_errors' => $this->make_hook('asserterror', AUTH_COOKIE, 'admin'), 'wiki_help' => $this->make_hook('wiki_help', AUTH_PUBLIC), 'wiki_preview' => $this->make_hook('wiki_preview', AUTH_COOKIE, 'user', NO_AUTH), @@ -188,6 +189,19 @@ class CoreModule extends PLModule $page->trigSuccess("Erreurs MySQL effacées."); } } + + function handler_asserterror(&$page) { + global $globals; + $page->coreTpl('assert_errors.tpl'); + $file = @file_get_contents($globals->spoolroot . '/spool/tmp/assert_errors'); + if ($file !== false) { + $page->assign('errors', utf8_encode($file)); + } + if (Post::has('clear')) { + @unlink($globals->spoolroot . '/spool/tmp/assert_errors'); + $page->trigSuccess("Erreurs d'assertion effacées."); + } + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --git a/templates/assert_errors.tpl b/templates/assert_errors.tpl new file mode 100644 index 0000000..058a5cf --- /dev/null +++ b/templates/assert_errors.tpl @@ -0,0 +1,38 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2010 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + +

Erreurs d'assertions

+

+ {if $errors} + {$errors|smarty:nodefaults} + {else} + Il n'y a pas d'erreurs actuellement recensées. + {/if} +

+
+
+ +
+
+ + +{* vim:set et sws=2 sts=2 sw=2 enc=utf-8: *}