From 83d9c85737f3cf0983c087593cf8c0855531c93b Mon Sep 17 00:00:00 2001 From: Amine Ben hammou Date: Wed, 7 Aug 2019 13:54:32 +0100 Subject: [PATCH] Use the rendered subject in stats email --- lib/Cron/Workers/StatsNotifications/Worker.php | 12 +++++++----- .../Cron/Workers/StatsNotifications/WorkerTest.php | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/Cron/Workers/StatsNotifications/Worker.php b/lib/Cron/Workers/StatsNotifications/Worker.php index bab7bd6633..cb605c63fd 100644 --- a/lib/Cron/Workers/StatsNotifications/Worker.php +++ b/lib/Cron/Workers/StatsNotifications/Worker.php @@ -82,8 +82,9 @@ class Worker { $newsletter = $this->getNewsletter($task); $link = NewsletterLink::findTopLinkForNewsletter($newsletter); $context = $this->prepareContext($newsletter, $link); + $subject = $newsletter->queue['newsletter_rendered_subject']; return [ - 'subject' => sprintf(_x('Stats for email %s', 'title of an automatic email containing statistics (newsletter open rate, click rate, etc)', 'mailpoet'), $newsletter->subject), + 'subject' => sprintf(_x('Stats for email %s', 'title of an automatic email containing statistics (newsletter open rate, click rate, etc)', 'mailpoet'), $subject), 'body' => [ 'html' => $this->renderer->render('emails/statsNotification.html', $context), 'text' => $this->renderer->render('emails/statsNotification.txt', $context), @@ -101,9 +102,9 @@ class Worker { throw new \Exception('Newsletter not found'); } return $newsletter - ->withSendingQueue() - ->withTotalSent() - ->withStatistics($this->woocommerce_helper); + ->withSendingQueue() + ->withTotalSent() + ->withStatistics($this->woocommerce_helper); } /** @@ -115,8 +116,9 @@ class Worker { $clicked = ($newsletter->statistics['clicked'] * 100) / $newsletter->total_sent; $opened = ($newsletter->statistics['opened'] * 100) / $newsletter->total_sent; $unsubscribed = ($newsletter->statistics['unsubscribed'] * 100) / $newsletter->total_sent; + $subject = $newsletter->queue['newsletter_rendered_subject']; $context = [ - 'subject' => $newsletter->subject, + 'subject' => $subject, 'preheader' => sprintf(_x( '%1$s%% opens, %2$s%% clicks, %3$s%% unsubscribes in a nutshell.', 'newsletter open rate, click rate and unsubscribe rate', 'mailpoet'), number_format($opened, 2), diff --git a/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php b/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php index 60c307e677..83e66912af 100644 --- a/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php +++ b/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php @@ -69,7 +69,7 @@ class WorkerTest extends \MailPoetTest { 'task_id' => $stats_notifications_task->id(), ]); $this->queue = SendingQueue::createOrUpdate([ - 'newsletter_rendered_subject' => 'Email Subject', + 'newsletter_rendered_subject' => 'Rendered Email Subject', 'task_id' => $sending_task->id(), 'newsletter_id' => $this->newsletter->id(), 'count_processed' => 5, @@ -150,7 +150,7 @@ class WorkerTest extends \MailPoetTest { ->with( $this->anything(), $this->callback(function($context){ - return $context['subject'] === 'Email Subject1'; + return $context['subject'] === 'Rendered Email Subject'; })); $this->stats_notifications->process(); @@ -263,7 +263,7 @@ class WorkerTest extends \MailPoetTest { 'task_id' => $stats_notifications_task->id(), ]); SendingQueue::createOrUpdate([ - 'newsletter_rendered_subject' => 'Email Subject2', + 'newsletter_rendered_subject' => 'Rendered Email Subject2', 'task_id' => $sending_task->id(), 'newsletter_id' => $newsletter->id(), 'count_processed' => 15,