mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Handle admin_email array config
This commit is contained in:
parent
018457a7c8
commit
204b39bfdf
@ -289,8 +289,19 @@ class Email extends ViewableData
|
||||
*/
|
||||
private function getDefaultFrom(): string
|
||||
{
|
||||
$defaultFrom = $this->config()->get('admin_email');
|
||||
if (!$defaultFrom) {
|
||||
// admin_email can have a string or an array config
|
||||
// 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();
|
||||
if (empty($host)) {
|
||||
throw new RuntimeException('Host not defined');
|
||||
|
@ -677,11 +677,22 @@ class EmailTest extends SapphireTest
|
||||
$method->setAccessible(true);
|
||||
|
||||
// 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, []));
|
||||
|
||||
// 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');
|
||||
$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