mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #10258 from creative-commoners/pulls/4.9/email-array
FIX Handle admin_email array config
This commit is contained in:
commit
e1dd712645
@ -289,8 +289,19 @@ class Email extends ViewableData
|
|||||||
*/
|
*/
|
||||||
private function getDefaultFrom(): string
|
private function getDefaultFrom(): string
|
||||||
{
|
{
|
||||||
$defaultFrom = $this->config()->get('admin_email');
|
// admin_email can have a string or an array config
|
||||||
if (!$defaultFrom) {
|
// https://docs.silverstripe.org/en/4/developer_guides/email/#administrator-emails
|
||||||
|
$adminEmail = $this->config()->get('admin_email');
|
||||||
|
if (is_array($adminEmail) && count($adminEmail) > 0) {
|
||||||
|
$defaultFrom = array_keys($adminEmail)[0];
|
||||||
|
} else {
|
||||||
|
if (is_string($adminEmail)) {
|
||||||
|
$defaultFrom = $adminEmail;
|
||||||
|
} else {
|
||||||
|
$defaultFrom = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($defaultFrom)) {
|
||||||
$host = Director::host();
|
$host = Director::host();
|
||||||
if (empty($host)) {
|
if (empty($host)) {
|
||||||
throw new RuntimeException('Host not defined');
|
throw new RuntimeException('Host not defined');
|
||||||
|
@ -677,11 +677,22 @@ class EmailTest extends SapphireTest
|
|||||||
$method->setAccessible(true);
|
$method->setAccessible(true);
|
||||||
|
|
||||||
// default to no-reply@mydomain.com if admin_email config not set
|
// default to no-reply@mydomain.com if admin_email config not set
|
||||||
|
Email::config()->set('admin_email', null);
|
||||||
$this->assertSame('no-reply@www.mysite.com', $method->invokeArgs($email, []));
|
$this->assertSame('no-reply@www.mysite.com', $method->invokeArgs($email, []));
|
||||||
|
|
||||||
// use admin_email config
|
// default to no-reply@mydomain.com if admin_email config is misconfigured
|
||||||
|
Email::config()->set('admin_email', 123);
|
||||||
|
$this->assertSame('no-reply@www.mysite.com', $method->invokeArgs($email, []));
|
||||||
|
|
||||||
|
// use admin_email config string syntax
|
||||||
Email::config()->set('admin_email', 'myadmin@somewhere.com');
|
Email::config()->set('admin_email', 'myadmin@somewhere.com');
|
||||||
$this->assertSame('myadmin@somewhere.com', $method->invokeArgs($email, []));
|
$this->assertSame('myadmin@somewhere.com', $method->invokeArgs($email, []));
|
||||||
|
$this->assertTrue(true);
|
||||||
|
|
||||||
|
// use admin_email config array syntax
|
||||||
|
Email::config()->set('admin_email', ['anotheradmin@somewhere.com' => 'Admin-email']);
|
||||||
|
$this->assertSame('anotheradmin@somewhere.com', $method->invokeArgs($email, []));
|
||||||
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user