NEW Adding a configuration option to get the Environment Checker to email its results

This commit is contained in:
Julian Seidenberg 2013-01-09 18:59:07 +01:00 committed by Ingo Schommer
parent 135126ac2e
commit b7ca70984d

View File

@ -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;
}
}