mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '4.3' into 4.4
This commit is contained in:
commit
dcbe6d0310
@ -49,9 +49,10 @@ class Email extends ViewableData
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This will be set in the config on a site-by-site basis
|
* This will be set in the config on a site-by-site basis
|
||||||
|
* @see https://docs.silverstripe.org/en/4/developer_guides/email/#administrator-emails
|
||||||
*
|
*
|
||||||
* @config
|
* @config
|
||||||
* @var string The default administrator email address.
|
* @var string|array The default administrator email address or array of [email => name]
|
||||||
*/
|
*/
|
||||||
private static $admin_email = null;
|
private static $admin_email = null;
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\Logging;
|
namespace SilverStripe\Logging;
|
||||||
|
|
||||||
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\Dev\Debug;
|
use SilverStripe\Dev\Debug;
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Control\Email\Email;
|
use SilverStripe\Control\Email\Email;
|
||||||
@ -133,13 +134,36 @@ class DebugViewFriendlyErrorFormatter implements FormatterInterface
|
|||||||
$output = $renderer->renderHeader();
|
$output = $renderer->renderHeader();
|
||||||
$output .= $renderer->renderInfo("Website Error", $this->getTitle(), $this->getBody());
|
$output .= $renderer->renderInfo("Website Error", $this->getTitle(), $this->getBody());
|
||||||
|
|
||||||
$adminEmail = Email::config()->get('admin_email');
|
if (!is_null($contactInfo = $this->addContactAdministratorInfo())) {
|
||||||
if ($adminEmail) {
|
$output .= $renderer->renderParagraph($contactInfo);
|
||||||
$mailto = Email::obfuscate($adminEmail);
|
|
||||||
$output .= $renderer->renderParagraph('Contact an administrator: ' . $mailto . '');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$output .= $renderer->renderFooter();
|
$output .= $renderer->renderFooter();
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the line with admin contact info
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
private function addContactAdministratorInfo()
|
||||||
|
{
|
||||||
|
if (!$adminEmail = Email::config()->admin_email) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_string($adminEmail)) {
|
||||||
|
return 'Contact an administrator: ' . Email::obfuscate($adminEmail);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_array($adminEmail) || !count($adminEmail)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$email = array_keys($adminEmail)[0];
|
||||||
|
$name = array_values($adminEmail)[0];
|
||||||
|
|
||||||
|
return sprintf('Contact %s: %s', Convert::raw2xml($name), Email::obfuscate($email));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,4 +92,27 @@ TEXT
|
|||||||
|
|
||||||
$this->assertSame('The Diary of Anne Frank', $formatter->output(200));
|
$this->assertSame('The Diary of Anne Frank', $formatter->output(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAdminEmailWithName()
|
||||||
|
{
|
||||||
|
Email::config()->set('admin_email', ['testy@mctest.face' => 'The ad&min']);
|
||||||
|
|
||||||
|
$formatter = new DebugViewFriendlyErrorFormatter();
|
||||||
|
$formatter->setTitle("There has been an error");
|
||||||
|
$formatter->setBody("The website server has not been able to respond to your request");
|
||||||
|
|
||||||
|
$expected = <<<TEXT
|
||||||
|
WEBSITE ERROR
|
||||||
|
There has been an error
|
||||||
|
-----------------------
|
||||||
|
The website server has not been able to respond to your request
|
||||||
|
|
||||||
|
Contact The ad&min: testy [at] mctest [dot] face
|
||||||
|
|
||||||
|
|
||||||
|
TEXT
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $formatter->output(404));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user