2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 **************************************************************************/
28 private function __construct($date, $error, $state = array())
31 $this->error
= "" . $error;
32 $this->state
= $state;
35 private function toCSV()
37 return array($this->date
, $this->error
, serialize($this->state
));
40 public static function fromCSV(array $entry)
42 return new PlErrorReport($entry[0], $entry[1], unserialize($entry[2]));
45 public static function report($error)
47 $error = new PlErrorReport(date('Y-m-d G:i:s'), $error,
48 array('Session' => $_SESSION,
53 'Server' => $_SERVER));
55 $file = fopen(Platal
::globals()->spoolroot
. '/spool/tmp/site_errors', 'a');
56 fputcsv($file, $error->toCSV());
60 public static function iterate()
62 return new PlErrorReportIterator();
65 public static function feed(PlPage
$page, PlUser
$user)
67 $feed = new PlErrorReportFeed();
68 return $feed->run($page, $user);
71 public static function clear()
73 @unlink
(Platal
::globals()->spoolroot
. '/spool/tmp/site_errors');
77 class PlErrorReportIterator
implements PlIterator
81 public function __construct()
83 $file = Platal
::globals()->spoolroot
. '/spool/tmp/site_errors';
84 if (file_exists($file)) {
85 $this->file
= fopen($file, 'r');
91 public function next()
96 $entry = fgetcsv($this->file
);
97 if ($entry === false
) {
102 $value = PlErrorReport
::fromCSV($entry);
106 public function total()
111 public function first()
116 public function last()
122 class PlErrorReportFeed
extends PlFeed
124 public function __construct()
127 parent
::__construct($globals->core
->sitename
. ' :: News',
128 $globals->baseurl
. '/site_errors',
129 'Erreurs d\'exécution',
130 $globals->baseurl
. '/images/logo.png',
131 $globals->coreroot
. '/templates/site_errors.feed.tpl');
134 protected function fetch(PlUser
$user)
137 $it = PlErrorReport
::iterate();
139 while ($row = $it->next()) {
140 $title = explode("\n", $row->error
);
143 $line['id'] = $row->date +
count($data);
144 $line['author'] = 'admin';
145 $line['link'] = $globals->baseurl
. '/site_errors';
146 $line['data'] = $row;
147 $line['title'] = $title;
148 $line['last_modification'] = $row->date
;
149 $line['publication'] = $row->date
;
152 return PlIteratorUtils
::fromArray($data, 1, true
);
156 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: