Skip to content

Commit

Permalink
API Deprecate swiftmailer
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 4, 2022
1 parent 7fd8ed1 commit 3e72260
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Control/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SilverStripe\Core\Convert;
use SilverStripe\Core\Environment;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
Expand Down Expand Up @@ -256,10 +257,13 @@ public function __construct(
}

/**
* @deprecated 4.12.0 Will be removed without equivalent functionality to replace it
*
* @return Swift_Message
*/
public function getSwiftMessage()
{
Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it');
if (!$this->swiftMessage) {
$message = new Swift_Message(null, null, 'text/html', 'utf-8');
// Set priority to fix PHP 8.1 SimpleMessage::getPriority() sscanf() null parameter
Expand All @@ -271,12 +275,15 @@ public function getSwiftMessage()
}

/**
* @deprecated 4.12.0 Will be removed without equivalent functionality to replace it
*
* @param Swift_Message $swiftMessage
*
* @return $this
*/
public function setSwiftMessage($swiftMessage)
{
Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it');
$dateTime = new DateTime();
$dateTime->setTimestamp(DBDatetime::now()->getTimestamp());
$swiftMessage->setDate($dateTime);
Expand Down Expand Up @@ -706,30 +713,39 @@ public function setBody($body)
}

/**
* @deprecated 4.12.0 Will be replaced with Symfony\Component\Mime\Email::html()
*
* @return $this
*/
public function invalidateBody()
{
Deprecation::notice('4.12.0', 'Will be replaced with Symfony\Component\Mime\Email::html()');
$this->setBody(null);

return $this;
}

/**
* @deprecated 4.12.0 Will be replaced with getData()
*
* @return string The base URL for the email
*/
public function BaseURL()
{
Deprecation::notice('4.12.0', 'Will be replaced with getData()');
return Director::absoluteBaseURL();
}

/**
* @deprecated Will be removed without equivalent functionality to replace it
*
* Debugging help
*
* @return string Debug info
*/
public function debug()
{
Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it');
$this->render();

$class = static::class;
Expand Down Expand Up @@ -794,31 +810,40 @@ public function setPlainTemplate($template)
}

/**
* @deprecated 4.12.0 Will be removed without equivalent functionality to replace it
*
* @param array $recipients
* @return $this
*/
public function setFailedRecipients($recipients)
{
Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it');
$this->failedRecipients = $recipients;

return $this;
}

/**
* @deprecated 4.12.0 Will be removed without equivalent functionality to replace it
*
* @return array
*/
public function getFailedRecipients()
{
Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it');
return $this->failedRecipients;
}

/**
* @deprecated 4.12.0 Will be replaced with getData()
*
* Used by {@link SSViewer} templates to detect if we're rendering an email template rather than a page template
*
* @return bool
*/
public function IsEmail()
{
Deprecation::notice('4.12.0', 'Will be replaced with getData()');
return true;
}

Expand Down Expand Up @@ -920,10 +945,13 @@ public function render($plainOnly = false)
}

/**
* @deprecated 4.12.0 Will be removed without equivalent functionality to replace it
*
* @return Swift_MimePart|false
*/
public function findPlainPart()
{
Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it');
foreach ($this->getSwiftMessage()->getChildren() as $child) {
if ($child instanceof Swift_MimePart && $child->getContentType() == 'text/plain') {
return $child;
Expand All @@ -933,23 +961,29 @@ public function findPlainPart()
}

/**
* @deprecated 4.12.0 Will be removed without equivalent functionality to replace it
*
* @return bool
*/
public function hasPlainPart()
{
Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it');
if ($this->getSwiftMessage()->getContentType() === 'text/plain') {
return true;
}
return (bool) $this->findPlainPart();
}

/**
* @deprecated 4.12.0 Will be removed without equivalent functionality to replace it
*
* Automatically adds a plain part to the email generated from the current Body
*
* @return $this
*/
public function generatePlainPartFromBody()
{
Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it');
$plainPart = $this->findPlainPart();
if ($plainPart) {
$this->getSwiftMessage()->detach($plainPart);
Expand Down
3 changes: 3 additions & 0 deletions src/Control/Email/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace SilverStripe\Control\Email;

/**
* @deprecated 4.12.0 Will be replaced with symfony/mailer
*/
interface Mailer
{

Expand Down
2 changes: 2 additions & 0 deletions src/Control/Email/SwiftMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Swift_Message;

/**
* @deprecated 4.12.0 Will be replaced with symfony/mailer
*
* Mailer objects are responsible for actually sending emails.
* The default Mailer class will use PHP's mail() function.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Control/Email/SwiftPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace SilverStripe\Control\Email;

/**
* @deprecated 4.12.0 Will be replaced with symfony/mailer
*/
class SwiftPlugin implements \Swift_Events_SendListener
{
/**
Expand Down

0 comments on commit 3e72260

Please sign in to comment.