00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 class aliroErrorRecorder extends aliroDatabaseRow {
00046 protected static $instance = null;
00047 protected $DBclass = 'aliroCoreDatabase';
00048 protected $tableName = '#__error_log';
00049 protected $rowKey = 'id';
00050
00051 public static function getInstance ($request=null) {
00052 return (null == self::$instance) ? (self::$instance = new self()) : self::$instance;
00053 }
00054
00055 public function PHPerror ($errno, $errstr, $errfile, $errline, $errcontext) {
00056 if (!($errno & error_reporting())) return;
00057 $rawmessage = function_exists('T_') ? T_('PHP Error %s: %s in %s at line %s') : 'PHP Error %s: %s in %s at line %s';
00058 $message = sprintf($rawmessage, $errno, $errstr, $errfile, $errline);
00059 $lmessage = $message;
00060 if (is_array($errcontext)) {
00061 foreach ($errcontext as $key=>$value) if (!is_object($value) AND !(is_array($value))) $lmessage .= "; $key=$value";
00062 }
00063 $errorkey = "PHP/$errno/$errfile/$errline/$errstr";
00064 $this->recordError($message, $errorkey, $lmessage);
00065 aliroRequest::getInstance()->setErrorMessage(T_('A PHP error has been recorded in the log'), _ALIRO_ERROR_WARN);
00066 if ($errno & (E_USER_ERROR|E_COMPILE_ERROR|E_CORE_ERROR|E_ERROR)) die (T_('Serious PHP error - processing halted - see error log for details'));
00067 }
00068
00069 public function recordError ($smessage, $errorkey, $lmessage='', $exception=null) {
00070 $this->id = 0;
00071 $this->timestamp = date ('Y-m-d H:i:s');
00072 $this->smessage = $smessage;
00073 $this->lmessage = $lmessage ? $lmessage : $smessage;
00074 $this->referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
00075 $database = aliroCoreDatabase::getInstance();
00076 $this->errorkey = $database->getEscaped($errorkey);
00077 $this->get = $_SERVER['REQUEST_URI'];
00078 $this->post = base64_encode(serialize($_POST));
00079 $this->trace = aliroRequest::trace();
00080 if ($exception instanceof databaseException) {
00081 $this->dbname = $exception->dbname;
00082 $this->sql = $exception->sql;
00083 $this->dberror = $exception->getCode();
00084 $this->dbmessage = $exception->getMessage();
00085 $this->dbtrace = $exception->dbtrace;
00086 }
00087 else $this->dbname = $this->sql = $this->dberror = $this->dbmessage = null;
00088 $database->setQuery("SELECT id FROM #__error_log WHERE errorkey = '$this->errorkey'");
00089 $id = $database->loadResult();
00090 if (!$id) $this->store();
00091 else $database->doSQL("UPDATE #__error_log SET timestamp = NOW() WHERE id = $id");
00092
00093 $database = call_user_func(array($this->DBclass, 'getInstance'));
00094 $database->doSQL("DELETE LOW_PRIORITY FROM $this->tableName WHERE timestamp < SUBDATE(NOW(), INTERVAL 7 DAY)");
00095 }
00096 }