2009-08-19 05:55:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Sends an error message to an email whenever an error occurs
|
|
|
|
* in sapphire.
|
|
|
|
*
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
* @see SS_Log for more information on using writers.
|
2009-08-19 07:41:58 +02:00
|
|
|
*
|
2009-08-19 05:55:23 +02:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage dev
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once 'Zend/Log/Writer/Abstract.php';
|
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
class SS_LogEmailWriter extends Zend_Log_Writer_Abstract {
|
2009-08-19 05:55:23 +02:00
|
|
|
|
2010-02-25 00:05:42 +01:00
|
|
|
/**
|
|
|
|
* @var $send_from Email address to send log information from
|
|
|
|
*/
|
|
|
|
protected static $send_from = 'errors@silverstripe.com';
|
|
|
|
|
2009-08-19 05:55:23 +02:00
|
|
|
protected $emailAddress;
|
|
|
|
|
|
|
|
protected $customSmtpServer;
|
|
|
|
|
|
|
|
public function __construct($emailAddress, $customSmtpServer = false) {
|
|
|
|
$this->emailAddress = $emailAddress;
|
|
|
|
$this->customSmtpServer = $customSmtpServer;
|
|
|
|
}
|
|
|
|
|
2010-02-25 00:05:42 +01:00
|
|
|
public static function set_send_from($address) {
|
|
|
|
self::$send_from = $address;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_send_from() {
|
|
|
|
return self::$send_from;
|
|
|
|
}
|
|
|
|
|
2009-08-19 05:55:23 +02:00
|
|
|
/**
|
2009-08-19 23:55:03 +02:00
|
|
|
* Send an email to the email address set in
|
|
|
|
* this writer.
|
2009-08-19 05:55:23 +02:00
|
|
|
*/
|
|
|
|
public function _write($event) {
|
|
|
|
// If no formatter set up, use the default
|
|
|
|
if(!$this->_formatter) {
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$formatter = new SS_LogErrorEmailFormatter();
|
2009-08-19 05:55:23 +02:00
|
|
|
$this->setFormatter($formatter);
|
|
|
|
}
|
|
|
|
|
|
|
|
$formattedData = $this->_formatter->format($event);
|
|
|
|
$subject = $formattedData['subject'];
|
|
|
|
$data = $formattedData['data'];
|
|
|
|
|
|
|
|
$originalSMTP = ini_get('SMTP');
|
|
|
|
// override the SMTP server with a custom one if required
|
|
|
|
if($this->customSmtpServer) ini_set('SMTP', $this->customSmtpServer);
|
|
|
|
|
2010-02-25 00:05:42 +01:00
|
|
|
mail(
|
|
|
|
$this->emailAddress,
|
|
|
|
$subject,
|
|
|
|
$data,
|
|
|
|
"Content-type: text/html\nFrom: " . self::$send_from
|
|
|
|
);
|
2009-08-19 05:55:23 +02:00
|
|
|
|
|
|
|
// reset the SMTP server to the original
|
|
|
|
if($this->customSmtpServer) ini_set('SMTP', $originalSMTP);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|