90 lines
2.7 KiB
PHP
90 lines
2.7 KiB
PHP
<?php
|
|
|
|
class App_Service_NotifyError
|
|
{
|
|
protected $_configs;
|
|
protected $_variabiliService;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->_configs = Zend_Registry::get('config');
|
|
$this->_variabiliService = new App_Service_VariabiliSito();
|
|
}
|
|
|
|
/**
|
|
* Notifica l'errore critico solo se il parametro memorizzato nelle variabili del sito è settato a zero
|
|
* Serve a notificarlo una volta sola fin quando non riattivo la notifica
|
|
*
|
|
* @param $nomeVariabileErrore
|
|
* @param $message
|
|
* @param $exception
|
|
* @param null $params
|
|
* @param bool $inviaEmail
|
|
* @throws Zend_Exception
|
|
*/
|
|
public function notificaErroreCritico($nomeVariabileErrore, $message, $exception, $params = null, $inviaEmail = true){
|
|
$variabileCheckNotififyError = $this->_variabiliService->get($nomeVariabileErrore);
|
|
if(!$variabileCheckNotififyError){
|
|
|
|
// Zend_Registry::get('log')->info(print_r($exception, true));
|
|
|
|
if($inviaEmail){
|
|
$this->inviaEmailDiErrore($message, $exception, $params);
|
|
}
|
|
|
|
$this->_variabiliService->set('I_CheckNotify_LoadMtTasks_Error', 1);
|
|
}
|
|
}
|
|
|
|
public function inviaEmailDiErrore($shortdesc, Exception $e = null, $params = null, $email = null)
|
|
{
|
|
$mail = new Zend_Mail('UTF-8');
|
|
|
|
if(!$email) $email = $this->_configs->get('test_email');
|
|
|
|
$subject = '--- SERVER AS Fatturab2b.net --- NOTIFICA ERRORE ---';
|
|
|
|
$message = '<br>ERROR MESSAGE: ' . $shortdesc;
|
|
|
|
if ($e != null) {
|
|
$message .= '<br><br>STACK TRACE ERRORE:<br>';
|
|
|
|
foreach ($e->getTrace() as $key => $value) {
|
|
$message .= "<br>[ " . $key . "] = " . $value;
|
|
if (is_array($value)) {
|
|
$message .= '<br>[';
|
|
foreach ($value as $key2 => $value2) {
|
|
$message .= "[ " . $key2 . "] = " . $value2 . "<br>";
|
|
}
|
|
$message .= ']<br>';
|
|
}
|
|
}
|
|
|
|
$message .= '<br>EXCEPTION STAMP:<br>';
|
|
|
|
$message .= "<pre>";
|
|
$message .= print_r($e,true);
|
|
$message .= "</pre>";
|
|
}
|
|
|
|
if($params){
|
|
$message .= '<br><br>PARAMETRI:<br>';
|
|
|
|
$message .= "<pre>";
|
|
$message .= print_r($params,true);
|
|
$message .= "</pre>";
|
|
|
|
$message .= '<br>';
|
|
}
|
|
|
|
$message .= '<br><br> Errore inviato dal server il ' . date('d/m/Y H:i:s');
|
|
|
|
$mail->setFrom($this->_configs->get('email_mittente'), $this->_configs->get('email_mittente_nome'))
|
|
->setSubject($subject)
|
|
->addTo($email, '')
|
|
->setBodyHtml($message)
|
|
->send();
|
|
}
|
|
|
|
}
|