Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Deprecate isValidEmail() method #262

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Tasks/ContentReviewEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SilverStripe\Control\Email\Email;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\BuildTask;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\FieldType\DBField;
Expand All @@ -30,7 +31,8 @@ class ContentReviewEmails extends BuildTask
*/
public function run($request)
{
if (!$this->isValidEmail($senderEmail = SiteConfig::current_site_config()->ReviewFrom)) {
$senderEmail = SiteConfig::current_site_config()->ReviewFrom;
if (!Deprecation::withSuppressedNotice(fn() => $this->isValidEmail($senderEmail))) {
throw new RuntimeException(
sprintf(
'Provided sender email address is invalid: "%s".',
Expand Down Expand Up @@ -116,7 +118,7 @@ protected function notifyOwner($ownerID, SS_List $pages)
$siteConfig = SiteConfig::current_site_config();
$owner = Member::get()->byID($ownerID);

if (!$this->isValidEmail($owner->Email)) {
if (!Deprecation::withSuppressedNotice(fn() => $this->isValidEmail($owner->Email))) {
$this->invalid_emails[] = $owner->Name . ': ' . $owner->Email;

return;
Expand Down Expand Up @@ -191,9 +193,11 @@ protected function getTemplateVariables($recipient, $config, $pages)

/**
* Check validity of email
* @deprecated 5.4.0 Use SilverStripe\Control\Email\Email::is_valid_address() instead.
*/
protected function isValidEmail(?string $email): bool
{
Deprecation::notice('5.4.0', 'Use ' . Email::class . '::is_valid_address() instead.');
return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
}
}
13 changes: 8 additions & 5 deletions tests/php/ContentReviewNotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\ContentReview\Extensions\SiteTreeContentReview;
use SilverStripe\ContentReview\Tasks\ContentReviewEmails;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Security\Group;
Expand Down Expand Up @@ -145,12 +146,14 @@ public function testIsValidEmail()
$member = $this->objFromFixture(Member::class, 'author');
$task = new ContentReviewEmails();

$this->assertTrue($method->invokeArgs($task, [$member->Email]));
$this->assertTrue($method->invokeArgs($task, ['[email protected]']));
Deprecation::withSuppressedNotice(function () use ($method, $task, $member) {
$this->assertTrue($method->invokeArgs($task, [$member->Email]));
$this->assertTrue($method->invokeArgs($task, ['[email protected]']));

$this->assertFalse($method->invokeArgs($task, [null]));
$this->assertFalse($method->invokeArgs($task, ['broken.email']));
$this->assertFalse($method->invokeArgs($task, ['broken@email']));
$this->assertFalse($method->invokeArgs($task, [null]));
$this->assertFalse($method->invokeArgs($task, ['broken.email']));
$this->assertFalse($method->invokeArgs($task, ['broken@email']));
});
}

/**
Expand Down
Loading