Render newsletters without clicked links
[MAILPOET-1571]
This commit is contained in:
@ -100,11 +100,11 @@ class Worker {
|
|||||||
->withStatistics();
|
->withStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function prepareContext(Newsletter $newsletter, NewsletterLink $link) {
|
private function prepareContext(Newsletter $newsletter, NewsletterLink $link = null) {
|
||||||
$clicked = ($newsletter->statistics['clicked'] * 100) / $newsletter->total_sent;
|
$clicked = ($newsletter->statistics['clicked'] * 100) / $newsletter->total_sent;
|
||||||
$opened = ($newsletter->statistics['opened'] * 100) / $newsletter->total_sent;
|
$opened = ($newsletter->statistics['opened'] * 100) / $newsletter->total_sent;
|
||||||
$unsubscribed = ($newsletter->statistics['unsubscribed'] * 100) / $newsletter->total_sent;
|
$unsubscribed = ($newsletter->statistics['unsubscribed'] * 100) / $newsletter->total_sent;
|
||||||
return [
|
$context = [
|
||||||
'subject' => $newsletter->subject,
|
'subject' => $newsletter->subject,
|
||||||
'preheader' => sprintf(_x(
|
'preheader' => sprintf(_x(
|
||||||
'%1$s%% opens, %2$s%% clicks, %3$s%% unsubscribes in a nutshell.', 'newsletter open rate, click rate and unsubscribe rate', 'mailpoet'),
|
'%1$s%% opens, %2$s%% clicks, %3$s%% unsubscribes in a nutshell.', 'newsletter open rate, click rate and unsubscribe rate', 'mailpoet'),
|
||||||
@ -112,14 +112,18 @@ class Worker {
|
|||||||
number_format($opened, 2),
|
number_format($opened, 2),
|
||||||
number_format($unsubscribed, 2)
|
number_format($unsubscribed, 2)
|
||||||
),
|
),
|
||||||
'topLinkClicks' => (int)$link->clicksCount,
|
$context['topLinkClicks'] = 0,
|
||||||
'topLink' => $link->url,
|
|
||||||
'linkSettings' => get_site_url(null, '/wp-admin/admin.php?page=mailpoet-settings#basics'),
|
'linkSettings' => get_site_url(null, '/wp-admin/admin.php?page=mailpoet-settings#basics'),
|
||||||
'linkStats' => get_site_url(null, '/wp-admin/admin.php?page=mailpoet-newsletters#/stats/' . $newsletter->id()),
|
'linkStats' => get_site_url(null, '/wp-admin/admin.php?page=mailpoet-newsletters#/stats/' . $newsletter->id()),
|
||||||
'premiumPluginActive' => is_plugin_active('mailpoet-premium/mailpoet-premium.php'),
|
'premiumPluginActive' => is_plugin_active('mailpoet-premium/mailpoet-premium.php'),
|
||||||
'clicked' => $clicked,
|
'clicked' => $clicked,
|
||||||
'opened' => $opened,
|
'opened' => $opened,
|
||||||
];
|
];
|
||||||
|
if($link) {
|
||||||
|
$context['topLinkClicks'] = (int)$link->clicksCount;
|
||||||
|
$context['topLink'] = $link->url;
|
||||||
|
}
|
||||||
|
return $context;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function markTaskAsFinished(ScheduledTask $task) {
|
private function markTaskAsFinished(ScheduledTask $task) {
|
||||||
|
@ -7,7 +7,7 @@ class NewsletterLink extends Model {
|
|||||||
public static $_table = MP_NEWSLETTER_LINKS_TABLE;
|
public static $_table = MP_NEWSLETTER_LINKS_TABLE;
|
||||||
|
|
||||||
static function findTopLinkForNewsletter(Newsletter $newsletter) {
|
static function findTopLinkForNewsletter(Newsletter $newsletter) {
|
||||||
return self::selectExpr('links.*')
|
$link = self::selectExpr('links.*')
|
||||||
->selectExpr('count(*)', 'clicksCount')
|
->selectExpr('count(*)', 'clicksCount')
|
||||||
->tableAlias('links')
|
->tableAlias('links')
|
||||||
->innerJoin(StatisticsClicks::$_table,
|
->innerJoin(StatisticsClicks::$_table,
|
||||||
@ -18,6 +18,10 @@ class NewsletterLink extends Model {
|
|||||||
->orderByDesc('clicksCount')
|
->orderByDesc('clicksCount')
|
||||||
->limit(1)
|
->limit(1)
|
||||||
->findOne();
|
->findOne();
|
||||||
|
if(!$link) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $link;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -186,4 +186,36 @@ class WorkerTest extends \MailPoetTest {
|
|||||||
$this->stats_notifications->process();
|
$this->stats_notifications->process();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItWorksForNewsletterWithNoStats() {
|
||||||
|
$newsletter = Newsletter::createOrUpdate([
|
||||||
|
'subject' => 'Email Subject2',
|
||||||
|
'type' => Newsletter::TYPE_STANDARD,
|
||||||
|
]);
|
||||||
|
$sending_task = ScheduledTask::createOrUpdate([
|
||||||
|
'type' => 'sending',
|
||||||
|
'status' => ScheduledTask::STATUS_COMPLETED,
|
||||||
|
]);
|
||||||
|
$stats_notifications_task = ScheduledTask::createOrUpdate([
|
||||||
|
'type' => Worker::TASK_TYPE,
|
||||||
|
'status' => ScheduledTask::STATUS_SCHEDULED,
|
||||||
|
'scheduled_at' => '2016-01-02 12:13:14',
|
||||||
|
'processed_at' => null,
|
||||||
|
]);
|
||||||
|
StatsNotification::createOrUpdate([
|
||||||
|
'newsletter_id' => $newsletter->id(),
|
||||||
|
'task_id' => $stats_notifications_task->id(),
|
||||||
|
]);
|
||||||
|
SendingQueue::createOrUpdate([
|
||||||
|
'newsletter_rendered_subject' => 'Email Subject2',
|
||||||
|
'task_id' => $sending_task->id(),
|
||||||
|
'newsletter_id' => $newsletter->id(),
|
||||||
|
'count_processed' => 15,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->mailer->expects($this->once())
|
||||||
|
->method('send');
|
||||||
|
|
||||||
|
$this->stats_notifications->process();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user