Fix newsletter::body type errors
[MAILPOET-3146]
This commit is contained in:
committed by
Veljko V
parent
1de06f5aa6
commit
ab9130f845
@@ -45,7 +45,7 @@ class Posts {
|
||||
}
|
||||
|
||||
public function getAlcPostsCount($renderedNewsletter, \MailPoet\Models\Newsletter $newsletter) {
|
||||
$templatePostsCount = substr_count($newsletter->body, 'data-post-id');
|
||||
$templatePostsCount = substr_count($newsletter->getBodyString(), 'data-post-id');
|
||||
$newsletterPostsCount = substr_count($renderedNewsletter['html'], 'data-post-id');
|
||||
return $newsletterPostsCount - $templatePostsCount;
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ use function MailPoetVendor\array_column;
|
||||
* @property array $segments
|
||||
* @property string $subject
|
||||
* @property string $preheader
|
||||
* @property string $body
|
||||
* @property string|array|null $body
|
||||
* @property string|null $schedule
|
||||
* @property bool|null $isScheduled
|
||||
* @property string|null $scheduledAt
|
||||
@@ -116,9 +116,7 @@ class Newsletter extends Model {
|
||||
}
|
||||
|
||||
if (isset($this->body) && ($this->body !== false)) {
|
||||
if (is_array($this->body)) {
|
||||
$this->body = (string)json_encode($this->body);
|
||||
}
|
||||
$this->body = $this->getBodyString();
|
||||
$this->set(
|
||||
'body',
|
||||
$this->body
|
||||
@@ -155,7 +153,7 @@ class Newsletter extends Model {
|
||||
|
||||
public function setStatus($status = null) {
|
||||
if ($status === self::STATUS_ACTIVE) {
|
||||
if (!$this->body || empty(json_decode($this->body))) {
|
||||
if (!$this->body || empty(json_decode($this->getBodyString()))) {
|
||||
$this->setError(
|
||||
Helpers::replaceLinkTags(
|
||||
__('This is an empty email without any content and it cannot be sent. Please update [link]the email[/link].'),
|
||||
@@ -342,6 +340,16 @@ class Newsletter extends Model {
|
||||
return SendingTask::getByNewsletterId($this->id);
|
||||
}
|
||||
|
||||
public function getBodyString(): string {
|
||||
if (is_array($this->body)) {
|
||||
return (string)json_encode($this->body);
|
||||
}
|
||||
if ($this->body === null) {
|
||||
return '';
|
||||
}
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
public function withSendingQueue() {
|
||||
$queue = $this->getQueue();
|
||||
if ($queue === false) {
|
||||
|
@@ -205,7 +205,7 @@ class NewsletterTest extends \MailPoetTest {
|
||||
$newsletter->type = Newsletter::TYPE_NOTIFICATION_HISTORY;
|
||||
$newsletter->parentId = $newsletter->id;
|
||||
// replace post id data tag with something else
|
||||
$newsletter->body = str_replace('data-post-id', 'id', $newsletter->body);
|
||||
$newsletter->body = str_replace('data-post-id', 'id', $newsletter->getBodyString());
|
||||
$newsletter->save();
|
||||
// returned result is false
|
||||
$result = $this->newsletterTask->preProcessNewsletter($this->newsletter, $this->queue);
|
||||
|
Reference in New Issue
Block a user