From f8407e39c856d7b5aa91b38e67392a650584de6c Mon Sep 17 00:00:00 2001 From: meadsteve Date: Sat, 1 Jun 2013 13:57:39 +0100 Subject: [PATCH] Email plugin now looks in the yaml file for an addresses setting. All these addresses will be mailed with a pass or fail message. --- PHPCI/Plugin/Email.php | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/PHPCI/Plugin/Email.php b/PHPCI/Plugin/Email.php index 09dd4ebd..eec4cda8 100644 --- a/PHPCI/Plugin/Email.php +++ b/PHPCI/Plugin/Email.php @@ -63,8 +63,34 @@ class Email implements \PHPCI\Plugin */ public function execute() { + // Without some email addresses in the yml file then we + // can't do anything. + if (!isset($this->options['addresses'])) { + return false; + } - return true; + $addresses = $this->options['addresses']; + $sendFailures = array(); + + if($this->phpci->getSuccessStatus()) { + $body = ""; + $sendFailures = $this->sendSeparateEmails( + $addresses, + "PASSED", + $body + ); + } + else { + $body = ""; + $sendFailures = $this->sendSeparateEmails( + $addresses, + "FAILED", + $body + ); + } + + // This is a success if we've not failed to send anything. + return (count($sendFailures) == 0); } /** @@ -85,6 +111,18 @@ class Email implements \PHPCI\Plugin return $failedAddresses; } + public function sendSeparateEmails(array $toAddresses, $subject, $body) + { + $failures = array(); + foreach($toAddresses as $address) { + $newFailures = $this->sendEmail($address, $subject, $body); + foreach($newFailures as $failure) { + $failures[] = $failure; + } + } + return $failures; + } + protected function loadSwiftMailerFromConfig() { /** @var \Swift_SmtpTransport $transport */