2009-08-19 05:55:23 +02:00
|
|
|
<?php
|
2010-04-23 02:11:41 +02:00
|
|
|
require_once 'Zend/Log/Writer/Abstract.php';
|
|
|
|
|
2009-08-19 05:55:23 +02:00
|
|
|
/**
|
2010-10-19 03:21:32 +02:00
|
|
|
* Sends an error message to an email.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
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.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-08-19 05:55:23 +02:00
|
|
|
* @subpackage dev
|
|
|
|
*/
|
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-05-25 05:15:26 +02:00
|
|
|
/**
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
2010-05-25 05:15:26 +02:00
|
|
|
* @var $send_from Email address to send log information from
|
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $send_from = 'errors@silverstripe.com';
|
2010-05-25 05:15:26 +02:00
|
|
|
|
2009-08-19 05:55:23 +02:00
|
|
|
protected $emailAddress;
|
|
|
|
|
|
|
|
protected $customSmtpServer;
|
|
|
|
|
|
|
|
public function __construct($emailAddress, $customSmtpServer = false) {
|
|
|
|
$this->emailAddress = $emailAddress;
|
|
|
|
$this->customSmtpServer = $customSmtpServer;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function factory($emailAddress, $customSmtpServer = false) {
|
2011-05-30 11:30:32 +02:00
|
|
|
return new SS_LogEmailWriter($emailAddress, $customSmtpServer);
|
|
|
|
}
|
2009-08-19 05:55:23 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
/**
|
2015-06-19 01:59:27 +02:00
|
|
|
* @deprecated 4.0 Use the "SS_LogEmailWriter.send_from" config setting instead
|
2013-03-21 19:48:54 +01:00
|
|
|
*/
|
2010-05-25 05:15:26 +02:00
|
|
|
public static function set_send_from($address) {
|
2015-06-19 01:59:27 +02:00
|
|
|
Deprecation::notice('4.0', 'Use the "SS_LogEmailWriter.send_from" config setting instead');
|
2013-03-21 19:48:54 +01:00
|
|
|
Config::inst()->update('SS_LogEmailWriter', 'send_from', $address);
|
2010-05-25 05:15:26 +02:00
|
|
|
}
|
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
/**
|
2015-06-19 01:59:27 +02:00
|
|
|
* @deprecated 4.0 Use the "SS_LogEmailWriter.send_from" config setting instead
|
2013-03-21 19:48:54 +01:00
|
|
|
*/
|
2010-05-25 05:15:26 +02:00
|
|
|
public static function get_send_from() {
|
2015-06-19 01:59:27 +02:00
|
|
|
Deprecation::notice('4.0', 'Use the "SS_LogEmailWriter.send_from" config setting instead');
|
2013-03-21 19:48:54 +01:00
|
|
|
return Config::inst()->get('SS_LogEmailWriter', 'send_from');
|
2010-05-25 05:15:26 +02:00
|
|
|
}
|
|
|
|
|
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'];
|
2013-03-21 19:48:54 +01:00
|
|
|
$from = Config::inst()->get('SS_LogEmailWriter', 'send_from');
|
2009-08-19 05:55:23 +02:00
|
|
|
|
|
|
|
// override the SMTP server with a custom one if required
|
2012-02-06 17:52:19 +01:00
|
|
|
$originalSMTP = ini_get('SMTP');
|
2009-08-19 05:55:23 +02:00
|
|
|
if($this->customSmtpServer) ini_set('SMTP', $this->customSmtpServer);
|
|
|
|
|
2012-02-06 17:52:19 +01:00
|
|
|
// Use plain mail() implementation to avoid complexity of Mailer implementation.
|
|
|
|
// Only use built-in mailer when we're in test mode (to allow introspection)
|
|
|
|
$mailer = Email::mailer();
|
|
|
|
if($mailer instanceof TestMailer) {
|
|
|
|
$mailer->sendHTML(
|
|
|
|
$this->emailAddress,
|
|
|
|
null,
|
|
|
|
$subject,
|
|
|
|
$data,
|
|
|
|
null,
|
2013-03-21 19:48:54 +01:00
|
|
|
"Content-type: text/html\nFrom: " . $from
|
2012-02-06 17:52:19 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
mail(
|
|
|
|
$this->emailAddress,
|
|
|
|
$subject,
|
|
|
|
$data,
|
2013-03-21 19:48:54 +01:00
|
|
|
"Content-type: text/html\nFrom: " . $from
|
2014-08-15 08:53:05 +02:00
|
|
|
);
|
2012-02-06 17:52:19 +01:00
|
|
|
}
|
2009-08-19 05:55:23 +02:00
|
|
|
|
|
|
|
// reset the SMTP server to the original
|
|
|
|
if($this->customSmtpServer) ini_set('SMTP', $originalSMTP);
|
|
|
|
}
|
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|