Adding a default address that is always mailed to by notifications.

This commit is contained in:
meadsteve 2013-06-04 21:09:16 +01:00
parent eaac43e0e8
commit 33b840a82d
2 changed files with 31 additions and 2 deletions

View file

@ -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'];

View file

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