mirror of
https://github.com/silverstripe/silverstripe-environmentcheck
synced 2024-10-22 17:05:40 +02:00
NEW Adding a configuration option to get the Environment Checker to email its results
This commit is contained in:
parent
135126ac2e
commit
b7ca70984d
@ -4,15 +4,23 @@
|
||||
* Provides an interface for checking the given EnvironmentCheckSuite.
|
||||
*/
|
||||
class EnvironmentChecker extends RequestHandler {
|
||||
|
||||
static $url_handlers = array(
|
||||
'' => 'index',
|
||||
);
|
||||
|
||||
protected $checkSuiteName;
|
||||
|
||||
protected $title;
|
||||
|
||||
protected $errorCode = 500;
|
||||
|
||||
public static $to_email_address = null;
|
||||
|
||||
public static $from_email_address = null;
|
||||
|
||||
public static $email_results = false;
|
||||
|
||||
function __construct($checkSuiteName, $title) {
|
||||
parent::__construct();
|
||||
|
||||
@ -20,14 +28,6 @@ class EnvironmentChecker extends RequestHandler {
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the HTTP status code that should be returned when there's an error.
|
||||
* Defaults to 500
|
||||
*/
|
||||
function setErrorCode($errorCode) {
|
||||
$this->errorCode = $errorCode;
|
||||
}
|
||||
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
@ -49,11 +49,51 @@ class EnvironmentChecker extends RequestHandler {
|
||||
$response->setStatusCode($this->errorCode);
|
||||
}
|
||||
|
||||
$response->setBody($result->customise(array(
|
||||
$resultText = $result->customise(array(
|
||||
"Title" => $this->title,
|
||||
"ErrorCode" => $this->errorCode,
|
||||
))->renderWith("EnvironmentChecker"));
|
||||
))->renderWith("EnvironmentChecker");
|
||||
|
||||
if (self::$email_results && !$result->ShouldPass()) {
|
||||
$email = new Email(self::$from_email_address, self::$to_email_address, $this->title, $resultText);
|
||||
$email->send();
|
||||
}
|
||||
|
||||
$response->setBody($resultText);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the HTTP status code that should be returned when there's an error.
|
||||
* Defaults to 500
|
||||
*/
|
||||
function setErrorCode($errorCode) {
|
||||
$this->errorCode = $errorCode;
|
||||
}
|
||||
|
||||
public static function set_from_email_address($from) {
|
||||
self::$from_email_address = $from;
|
||||
}
|
||||
|
||||
public static function get_from_email_address() {
|
||||
return self::$from_email_address;
|
||||
}
|
||||
|
||||
public static function set_to_email_address($to) {
|
||||
self::$to_email_address = $to;
|
||||
}
|
||||
|
||||
public static function get_to_email_address() {
|
||||
return self::$to_email_address;
|
||||
}
|
||||
|
||||
public static function set_email_results($results) {
|
||||
self::$email_results = $results;
|
||||
}
|
||||
|
||||
public static function get_email_results() {
|
||||
return self::$email_results;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user