Remove unused code
[PREMIUM-142]
This commit is contained in:
@@ -13,7 +13,6 @@ use MailPoet\Settings\SettingsController;
|
||||
use MailPoet\Tasks\Sending as SendingTask;
|
||||
use MailPoet\Util\Helpers;
|
||||
use MailPoet\Util\Security;
|
||||
use MailPoet\WooCommerce\Helper as WCHelper;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use MailPoetVendor\Carbon\Carbon;
|
||||
|
||||
@@ -567,75 +566,11 @@ class Newsletter extends Model {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withTotalSent() {
|
||||
// total of subscribers who received the email
|
||||
$this->totalSent = (int)SendingQueue::findTaskByNewsletterId($this->id)
|
||||
->where('tasks.status', SendingQueue::STATUS_COMPLETED)
|
||||
->sum('queues.count_processed');
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withScheduledToBeSent() {
|
||||
$this->totalScheduled = (int)SendingQueue::findTaskByNewsletterId($this->id)
|
||||
->where('tasks.status', SendingQueue::STATUS_SCHEDULED)
|
||||
->count();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withStatistics(WCHelper $woocommerceHelper) {
|
||||
$statistics = $this->getStatistics($woocommerceHelper);
|
||||
$this->statistics = $statistics;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$renderer = new Renderer($this);
|
||||
return $renderer->render();
|
||||
}
|
||||
|
||||
public function getStatistics(WCHelper $woocommerceHelper) {
|
||||
if (($this->type !== self::TYPE_WELCOME) && ($this->queue === false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$statisticsExprs = [
|
||||
'clicked' => StatisticsClicks::selectExpr('COUNT(DISTINCT subscriber_id) as cnt')->tableAlias("stat"),
|
||||
'opened' => StatisticsOpens::selectExpr('COUNT(DISTINCT subscriber_id) as cnt')->tableAlias("stat"),
|
||||
'unsubscribed' => StatisticsUnsubscribes::selectExpr('COUNT(DISTINCT subscriber_id) as cnt')->tableAlias("stat"),
|
||||
];
|
||||
$result = [];
|
||||
|
||||
foreach ($statisticsExprs as $name => $statisticsExpr) {
|
||||
$row = $statisticsExpr->where('newsletter_id', $this->id)->findOne();
|
||||
$result[$name] = !empty($row->cnt) ? (int)$row->cnt : 0;
|
||||
}
|
||||
|
||||
// WooCommerce revenues
|
||||
if ($woocommerceHelper->isWooCommerceActive()) {
|
||||
$currency = $woocommerceHelper->getWoocommerceCurrency();
|
||||
$row = StatisticsWooCommercePurchases::selectExpr('SUM(order_price_total) AS total')
|
||||
->selectExpr('count(*)', 'count')
|
||||
->where([
|
||||
'newsletter_id' => $this->id,
|
||||
'order_currency' => $currency,
|
||||
])
|
||||
->findOne();
|
||||
|
||||
$revenue = !empty($row->total) ? (float)$row->total : 0.0;
|
||||
$count = !empty($row->count) ? (int)$row->count : 0;
|
||||
$result['revenue'] = [
|
||||
'currency' => $currency,
|
||||
'value' => $revenue,
|
||||
'count' => $count,
|
||||
'formatted' => $woocommerceHelper->getRawPrice($revenue, ['currency' => $currency]),
|
||||
];
|
||||
} else {
|
||||
$result['revenue'] = null;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function wasScheduledForSubscriber($subscriberId) {
|
||||
/** @var \stdClass */
|
||||
$queue = SendingQueue::rawQuery(
|
||||
|
@@ -12,10 +12,8 @@ use MailPoet\Models\SendingQueue;
|
||||
use MailPoet\Models\StatisticsClicks;
|
||||
use MailPoet\Models\StatisticsOpens;
|
||||
use MailPoet\Models\StatisticsUnsubscribes;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Tasks\Sending as SendingTask;
|
||||
use MailPoet\Util\Security;
|
||||
use MailPoet\WooCommerce\Helper as WCHelper;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use MailPoetVendor\Carbon\Carbon;
|
||||
use MailPoetVendor\Idiorm\ORM;
|
||||
@@ -148,43 +146,6 @@ class NewsletterTest extends \MailPoetTest {
|
||||
expect($newsletterSegments[1]['name'])->contains('Deleted');
|
||||
}
|
||||
|
||||
public function testItCanHaveStatistics() {
|
||||
$newsletter = $this->newsletter;
|
||||
$sendingQueue = $this->sendingQueue;
|
||||
|
||||
$subscriber = Subscriber::createOrUpdate([
|
||||
'email' => 'john.doe@mailpoet.com',
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe',
|
||||
]);
|
||||
|
||||
$opens = StatisticsOpens::create();
|
||||
$opens->subscriberId = $subscriber->id;
|
||||
$opens->newsletterId = $this->newsletter->id;
|
||||
$opens->queueId = $sendingQueue->id;
|
||||
$opens->save();
|
||||
|
||||
$clicks = StatisticsClicks::create();
|
||||
$clicks->subscriberId = $subscriber->id;
|
||||
$clicks->newsletterId = $this->newsletter->id;
|
||||
$clicks->queueId = $sendingQueue->id;
|
||||
$clicks->linkId = 0;
|
||||
$clicks->count = 0;
|
||||
$clicks->save();
|
||||
|
||||
$unsubscribes = StatisticsUnsubscribes::create();
|
||||
$unsubscribes->subscriberId = $subscriber->id;
|
||||
$unsubscribes->newsletterId = $this->newsletter->id;
|
||||
$unsubscribes->queueId = $sendingQueue->id;
|
||||
$unsubscribes->save();
|
||||
|
||||
$newsletter->queue = $newsletter->getQueue()->asArray();
|
||||
$statistics = $newsletter->getStatistics($this->makeEmpty(WCHelper::class));
|
||||
expect($statistics['opened'])->equals(1);
|
||||
expect($statistics['clicked'])->equals(1);
|
||||
expect($statistics['unsubscribed'])->equals(1);
|
||||
}
|
||||
|
||||
public function testItCanCreateOrUpdate() {
|
||||
$isCreated = Newsletter::createOrUpdate(
|
||||
[
|
||||
|
Reference in New Issue
Block a user