In the process it was necessary to change the signature of the method \MailPoet\Mailer\MetaInfo::getNewsletterMetaInfo() to accept a SubscriberEntity instead of a Subscriber model and also change \MailPoet\Cron\Workers\SendingQueue\SendingQueue::processQueue() as it calls getNewsletterMetaInfo(). Doing this was straightforward, but changing the test class for SendingQueue was a bit more involved. In particular, the test SendingQueueTest::testItEnforcesExecutionLimitsAfterQueueProcessing(). This test is a bit brittle and was creating Subscriber models without saving them to the database with invalid statuses and sources. Switching getNewsletterMetaInfo() to use entities, while SendingQueue::processQueue() still uses models, meant that it was necessary to save the subscribers to the database. Because of this, it was not possible anymore to use invalid statuses and sources, and thus, the test changed a bit. [MAILPOET-4379]
67 lines
2.2 KiB
PHP
67 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace MailPoet\Mailer;
|
|
|
|
use MailPoet\Entities\SubscriberEntity;
|
|
use MailPoet\Models\Newsletter;
|
|
|
|
class MetaInfo {
|
|
public function getSendingTestMetaInfo() {
|
|
return $this->makeMetaInfo('sending_test', 'unknown', 'administrator');
|
|
}
|
|
|
|
public function getPreviewMetaInfo() {
|
|
return $this->makeMetaInfo('preview', 'unknown', 'administrator');
|
|
}
|
|
|
|
public function getStatsNotificationMetaInfo() {
|
|
return $this->makeMetaInfo('email_stats_notification', 'unknown', 'administrator');
|
|
}
|
|
|
|
public function getWordPressTransactionalMetaInfo(SubscriberEntity $subscriber = null) {
|
|
return $this->makeMetaInfo(
|
|
'transactional',
|
|
$subscriber ? $subscriber->getStatus() : 'unknown',
|
|
$subscriber ? $subscriber->getSource() : 'unknown'
|
|
);
|
|
}
|
|
|
|
public function getConfirmationMetaInfo(SubscriberEntity $subscriber) {
|
|
return $this->makeMetaInfo('confirmation', $subscriber->getStatus(), $subscriber->getSource());
|
|
}
|
|
|
|
public function getNewSubscriberNotificationMetaInfo() {
|
|
return $this->makeMetaInfo('new_subscriber_notification', 'unknown', 'administrator');
|
|
}
|
|
|
|
public function getNewsletterMetaInfo($newsletter, SubscriberEntity $subscriber) {
|
|
$type = $newsletter->type ?? 'unknown';
|
|
switch ($newsletter->type) {
|
|
case Newsletter::TYPE_AUTOMATIC:
|
|
$group = isset($newsletter->options['group']) ? $newsletter->options['group'] : 'unknown';
|
|
$event = isset($newsletter->options['event']) ? $newsletter->options['event'] : 'unknown';
|
|
$type = sprintf('automatic_%s_%s', $group, $event);
|
|
break;
|
|
case Newsletter::TYPE_STANDARD:
|
|
$type = 'newsletter';
|
|
break;
|
|
case Newsletter::TYPE_WELCOME:
|
|
$type = 'welcome';
|
|
break;
|
|
case Newsletter::TYPE_NOTIFICATION:
|
|
case Newsletter::TYPE_NOTIFICATION_HISTORY:
|
|
$type = 'post_notification';
|
|
break;
|
|
}
|
|
return $this->makeMetaInfo($type, $subscriber->getStatus(), $subscriber->getSource());
|
|
}
|
|
|
|
private function makeMetaInfo($emailType, $subscriberStatus, $subscriberSource) {
|
|
return [
|
|
'email_type' => $emailType,
|
|
'subscriber_status' => $subscriberStatus,
|
|
'subscriber_source' => $subscriberSource ?: 'unknown',
|
|
];
|
|
}
|
|
}
|