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 <raphael.barrois@polytechnique.org>
}
}
+ 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, '<pre>' . pl_entities($error) . '</pre>\n');
+ fclose($file);
+
+ Platal::page()->kill($userfriendly);
+ }
+ }
+
+
static public function &page()
{
global $platal;
'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),
$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:
--- /dev/null
+{**************************************************************************}
+{* *}
+{* 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 *}
+{* *}
+{**************************************************************************}
+
+<h1>Erreurs d'assertions</h1>
+<p>
+ {if $errors}
+ {$errors|smarty:nodefaults}
+ {else}
+ Il n'y a pas d'erreurs actuellement recensées.
+ {/if}
+</p>
+<form action="assert_errors" method="post">
+ <div>
+ <input type="submit" name="clear" value="Effacer les erreurs" />
+ </div>
+</form>
+
+
+{* vim:set et sws=2 sts=2 sw=2 enc=utf-8: *}