From 33b840a82d6bd318de505aec1278cfbe43be7298 Mon Sep 17 00:00:00 2001 From: meadsteve Date: Tue, 4 Jun 2013 21:09:16 +0100 Subject: [PATCH] Adding a default address that is always mailed to by notifications. --- PHPCI/Command/InstallCommand.php | 1 + PHPCI/Plugin/Email.php | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/PHPCI/Command/InstallCommand.php b/PHPCI/Command/InstallCommand.php index 8e06d7ed..ad9cbeb7 100644 --- a/PHPCI/Command/InstallCommand.php +++ b/PHPCI/Command/InstallCommand.php @@ -53,6 +53,7 @@ class InstallCommand extends Command $conf['phpci']['email_settings']['smtp_username'] = $this->ask('(Optional) Smtp Username: ', true); $conf['phpci']['email_settings']['smtp_password'] = $this->ask('(Optional) Smtp Password: ', true); $conf['phpci']['email_settings']['from_address'] = $this->ask('(Optional) Email address to send from: ', true); + $conf['phpci']['email_settings']['default_mailto_address'] = $this->ask('(Optional) Default address to email notifications to: ', true); $dbUser = $conf['b8']['database']['username']; $dbPass = $conf['b8']['database']['password']; diff --git a/PHPCI/Plugin/Email.php b/PHPCI/Plugin/Email.php index eec4cda8..d4758ddc 100644 --- a/PHPCI/Plugin/Email.php +++ b/PHPCI/Plugin/Email.php @@ -63,13 +63,14 @@ class Email implements \PHPCI\Plugin */ public function execute() { + $addresses = $this->getEmailAddresses(); + // Without some email addresses in the yml file then we // can't do anything. - if (!isset($this->options['addresses'])) { + if (count($addresses) == 0) { return false; } - $addresses = $this->options['addresses']; $sendFailures = array(); if($this->phpci->getSuccessStatus()) { @@ -90,6 +91,14 @@ class Email implements \PHPCI\Plugin } // This is a success if we've not failed to send anything. + $this->phpci->log(sprintf( + "%d emails sent", + (count($addresses) - count($sendFailures))) + ); + $this->phpci->log(sprintf( + "%d emails failed to send", + count($sendFailures)) + ); return (count($sendFailures) == 0); } @@ -148,6 +157,8 @@ class Email implements \PHPCI\Plugin switch($configName) { case 'smtp_address': return "localhost"; + case 'default_mailto_address': + return null; case 'smtp_port': return '25'; case 'from_address': @@ -157,4 +168,21 @@ class Email implements \PHPCI\Plugin } } } + + protected function getEmailAddresses() + { + $addresses = array(); + + if (isset($this->options['addresses'])) { + foreach ($this->options['addresses'] as $address) { + $addresses[] = $address; + } + } + + if (isset($this->options['default_mailto_address'])) { + $addresses[] = $this->options['default_mailto_address']; + return $addresses; + } + return $addresses; + } } \ No newline at end of file