odea/application/controllers/ErrorController.php

77 lines
2.6 KiB
PHP
Raw Normal View History

2012-02-02 18:29:14 +01:00
<?php
2012-02-15 10:25:21 +01:00
class ErrorController extends Zend_Controller_Action
2012-02-02 18:29:14 +01:00
{
public function errorAction()
{
$errors = $this->_getParam('error_handler');
switch ($errors->type) {
2012-02-15 10:25:21 +01:00
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
2012-02-02 18:29:14 +01:00
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'Page not found';
break;
2012-02-15 10:25:21 +01:00
2012-02-02 18:29:14 +01:00
default:
// application error
$this->getResponse()->setHttpResponseCode(500);
$this->view->message = 'Application error';
break;
}
2012-02-15 10:25:21 +01:00
2012-10-25 15:26:51 +02:00
$auth = Zend_Auth::getInstance();
$identity = $auth->getIdentity();
2012-09-06 16:27:23 +02:00
//Envoyer les erreurs par mail
$message = '';
$message.= 'Erreur Applicative : ';
$message.= "\n";
$message.= 'Message : '.$errors->exception->getMessage();
$message.= "\n";
2012-12-06 17:51:14 +01:00
$message.= 'Utilisateur : '.$identity->username;
2012-09-06 16:27:23 +02:00
$message.= "\n";
$message.= "File :".$errors->exception->getFile().", Ligne : ".$errors->exception->getLine();
$message.= "\n";
$message.= "Detail :\n".$errors->exception->getTraceAsString();
$message.= "\n\n";
$message.= "Request Parameters :\n ".print_r($this->getRequest()->getParams(), true)."\n";
$message.= "Referer : ".$_SERVER['HTTP_REFERER']."\n";
2012-12-06 17:51:14 +01:00
$c = Zend_Registry::get('config');
2012-10-25 16:41:54 +02:00
require_once 'Scores/Mail.php';
2012-09-06 16:27:23 +02:00
$mail = new Mail();
2012-12-06 17:51:14 +01:00
$mail->setSubject('[ERREUR APPLICATIVE] - '.$c->profil->server->name.' -'.date('Ymd'));
2012-09-06 16:27:23 +02:00
$mail->setBodyTexte($message);
$mail->setFrom('supportdev');
$mail->addToKey('supportdev');
$mail->send();
2012-02-02 18:29:14 +01:00
// Log exception, if logger available
if ($log = $this->getLog()) {
$log->crit($this->view->message, $errors->exception);
}
// conditionally display exceptions
if ($this->getInvokeArg('displayExceptions') == true) {
$this->view->exception = $errors->exception;
}
$this->view->request = $errors->request;
}
2012-02-15 10:25:21 +01:00
2012-02-02 18:29:14 +01:00
public function getLog()
{
$bootstrap = $this->getInvokeArg('bootstrap');
if (!$bootstrap->hasPluginResource('Log')) {
return false;
}
$log = $bootstrap->getResource('Log');
return $log;
}
}