public function processElasticemail()
{
$request = Yii::app()->request;
$category = trim($request->getQuery('category'));
$transaction = trim($request->getQuery('transaction'));
$status = trim($request->getQuery('status'));
if (empty($transaction) || empty($category)) {
Yii::app()->end();
}
$deliveryLog = CampaignDeliveryLog::model()->findByAttributes(array(
'email_message_id' => $transaction,
'status' => CampaignDeliveryLog::STATUS_SUCCESS,
));
if (empty($deliveryLog)) {
$deliveryLog = CampaignDeliveryLogArchive::model()->findByAttributes(array(
'email_message_id' => $transaction,
'status' => CampaignDeliveryLogArchive::STATUS_SUCCESS,
));
}
if (empty($deliveryLog)) {
Yii::app()->end();
}
$campaign = Campaign::model()->findByPk($deliveryLog->campaign_id);
if (empty($campaign)) {
Yii::app()->end();
}
$subscriber = ListSubscriber::model()->findByAttributes(array(
'list_id' => $campaign->list_id,
'subscriber_id' => $deliveryLog->subscriber_id,
'status' => ListSubscriber::STATUS_CONFIRMED,
));
if (empty($subscriber)) {
Yii::app()->end();
}
// All categories:
// https://elasticemail.com/support/delivery/http-web-notification
if ($status == 'AbuseReport') {
if (Yii::app()->options->get('system.cron.process_feedback_loop_servers.subscriber_action', 'unsubscribe') == 'delete') {
$subscriber->delete();
Yii::app()->end();
}
$subscriber->saveStatus(ListSubscriber::STATUS_UNSUBSCRIBED);
$count = CampaignTrackUnsubscribe::model()->countByAttributes(array(
'campaign_id' => $campaign->campaign_id,
'subscriber_id' => $subscriber->subscriber_id,
));
if (empty($count)) {
$trackUnsubscribe = new CampaignTrackUnsubscribe();
$trackUnsubscribe->campaign_id = $campaign->campaign_id;
$trackUnsubscribe->subscriber_id = $subscriber->subscriber_id;
$trackUnsubscribe->note = 'Unsubscribed via Web Hook!';
$trackUnsubscribe->ip_address = Yii::app()->request->userHostAddress;
$trackUnsubscribe->user_agent = StringHelper::truncateLength(Yii::app()->request->userAgent, 255);
$trackUnsubscribe->save(false);
}
// since 1.4.4 - complaints go into their own tables
$count = CampaignComplainLog::model()->countByAttributes(array(
'campaign_id' => $campaign->campaign_id,
'subscriber_id' => $subscriber->subscriber_id,
));
if (empty($count)) {
$complaintLog = new CampaignComplainLog();
$complaintLog->campaign_id = $campaign->campaign_id;
$complaintLog->subscriber_id = $subscriber->subscriber_id;
$complaintLog->message = 'Abuse complaint via ElasticEmail!';
$complaintLog->save(false);
}
//
Yii::app()->end();
}
if ($status == 'Unsubscribed') {
$subscriber->saveStatus(ListSubscriber::STATUS_UNSUBSCRIBED);
$count = CampaignTrackUnsubscribe::model()->countByAttributes(array(
'campaign_id' => $campaign->campaign_id,
'subscriber_id' => $subscriber->subscriber_id,
));
if (!empty($count)) {
Yii::app()->end();
}
$trackUnsubscribe = new CampaignTrackUnsubscribe();
$trackUnsubscribe->campaign_id = $campaign->campaign_id;
$trackUnsubscribe->subscriber_id = $subscriber->subscriber_id;
$trackUnsubscribe->note = 'Unsubscribed via Web Hook!';
$trackUnsubscribe->ip_address = Yii::app()->request->userHostAddress;
$trackUnsubscribe->user_agent = StringHelper::truncateLength(Yii::app()->request->userAgent, 255);
$trackUnsubscribe->save(false);
Yii::app()->end();
}
// $bounceCategories = array(
// 'NoMailbox', 'AccountProblem',
// 'Throttled', 'ConnectionTerminated',
//);
$bounceCategories = array('NoMailbox');
$bounceCategories = array_map('strtolower', $bounceCategories);
$categoryID = strtolower($category);
if (in_array($categoryID, $bounceCategories)) {
$hardBounceCategories = array('NoMailbox', 'AccountProblem');
$hardBounceCategories = array_map('strtolower', $hardBounceCategories);
$softBounceCategories = array('Throttled', 'ConnectionTerminated');
$softBounceCategories = array_map('strtolower', $softBounceCategories);
$bounceType = null;
if (in_array($categoryID, $hardBounceCategories)) {
$bounceType = CampaignBounceLog::BOUNCE_HARD;
} elseif (in_array($categoryID, $softBounceCategories)) {
$bounceType = CampaignBounceLog::BOUNCE_SOFT;
}
if ($bounceType === null) {
Yii::app()->end();
}
$count = CampaignBounceLog::model()->countByAttributes(array(
'campaign_id' => $campaign->campaign_id,
'subscriber_id' => $subscriber->subscriber_id,
));
if (!empty($count)) {
Yii::app()->end();
}
$bounceLog = new CampaignBounceLog();
$bounceLog->campaign_id = $campaign->campaign_id;
$bounceLog->subscriber_id = $subscriber->subscriber_id;
$bounceLog->message = $category;
$bounceLog->bounce_type = $bounceType;
$bounceLog->save();
if ($bounceLog->bounce_type == CampaignBounceLog::BOUNCE_HARD) {
$subscriber->addToBlacklist($bounceLog->message);
}
Yii::app()->end();
}
Yii::app()->end();
}