- Avoids sending duplicate posts
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Cron\Workers\SendingQueue\Tasks;
|
namespace MailPoet\Cron\Workers\SendingQueue\Tasks;
|
||||||
|
|
||||||
|
use MailPoet\Models\Newsletter;
|
||||||
use MailPoet\Models\NewsletterPost;
|
use MailPoet\Models\NewsletterPost;
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
@ -18,9 +19,12 @@ class Posts {
|
|||||||
if(!count($matched_posts_ids)) {
|
if(!count($matched_posts_ids)) {
|
||||||
return $newsletter;
|
return $newsletter;
|
||||||
}
|
}
|
||||||
|
$newsletter_id = ($newsletter['type'] === Newsletter::TYPE_NOTIFICATION_HISTORY) ?
|
||||||
|
$newsletter['parent_id'] :
|
||||||
|
$newsletter['id'];
|
||||||
foreach($matched_posts_ids as $post_id) {
|
foreach($matched_posts_ids as $post_id) {
|
||||||
$newletter_post = NewsletterPost::create();
|
$newletter_post = NewsletterPost::create();
|
||||||
$newletter_post->newsletter_id = $newsletter['id'];
|
$newletter_post->newsletter_id = $newsletter_id;
|
||||||
$newletter_post->post_id = $post_id;
|
$newletter_post->post_id = $post_id;
|
||||||
$newletter_post->save();
|
$newletter_post->save();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Newsletter\Renderer\Blocks;
|
namespace MailPoet\Newsletter\Renderer\Blocks;
|
||||||
|
|
||||||
|
use MailPoet\Models\Newsletter;
|
||||||
use MailPoet\Newsletter\Renderer\StylesHelper;
|
use MailPoet\Newsletter\Renderer\StylesHelper;
|
||||||
|
|
||||||
class Renderer {
|
class Renderer {
|
||||||
@ -10,7 +11,10 @@ class Renderer {
|
|||||||
function __construct(array $newsletter, $posts = false) {
|
function __construct(array $newsletter, $posts = false) {
|
||||||
$this->newsletter = $newsletter;
|
$this->newsletter = $newsletter;
|
||||||
$this->posts = array();
|
$this->posts = array();
|
||||||
$this->ALC = new \MailPoet\Newsletter\AutomatedLatestContent($this->newsletter['id']);
|
$newsletter_id = ($newsletter['type'] === Newsletter::TYPE_NOTIFICATION_HISTORY) ?
|
||||||
|
$newsletter['parent_id'] :
|
||||||
|
$newsletter['id'];
|
||||||
|
$this->ALC = new \MailPoet\Newsletter\AutomatedLatestContent($newsletter_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function render($data, $column_count) {
|
function render($data, $column_count) {
|
||||||
@ -45,12 +49,12 @@ class Renderer {
|
|||||||
|
|
||||||
function processAutomatedLatestContent($args, $column_count) {
|
function processAutomatedLatestContent($args, $column_count) {
|
||||||
$posts_to_exclude = $this->getPosts();
|
$posts_to_exclude = $this->getPosts();
|
||||||
$ALCPosts = $this->ALC->getPosts($args, $posts_to_exclude);
|
$ALC_posts = $this->ALC->getPosts($args, $posts_to_exclude);
|
||||||
foreach($ALCPosts as $post) {
|
foreach($ALC_posts as $post) {
|
||||||
$posts_to_exclude[] = $post->ID;
|
$posts_to_exclude[] = $post->ID;
|
||||||
}
|
}
|
||||||
$transformed_posts = array(
|
$transformed_posts = array(
|
||||||
'blocks' => $this->ALC->transformPosts($args, $ALCPosts)
|
'blocks' => $this->ALC->transformPosts($args, $ALC_posts)
|
||||||
);
|
);
|
||||||
$this->setPosts($posts_to_exclude);
|
$this->setPosts($posts_to_exclude);
|
||||||
$transformed_posts = StylesHelper::applyTextAlignment($transformed_posts);
|
$transformed_posts = StylesHelper::applyTextAlignment($transformed_posts);
|
||||||
|
Reference in New Issue
Block a user