From b7ca70984d1da086faefd0311b4cc6b4340f4a13 Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Wed, 9 Jan 2013 18:59:07 +0100 Subject: [PATCH] NEW Adding a configuration option to get the Environment Checker to email its results --- code/EnvironmentChecker.php | 60 ++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/code/EnvironmentChecker.php b/code/EnvironmentChecker.php index 72a4395..e82299e 100644 --- a/code/EnvironmentChecker.php +++ b/code/EnvironmentChecker.php @@ -4,14 +4,22 @@ * 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; + } + } \ No newline at end of file