Yii::app()->hooks->removeAction('frontend_campaigns_after_track_url_before_redirect', array($this, '_urlActionChangeSubscriberListField'));
Yii::app()->hooks->addAction('frontend_campaigns_after_track_url_before_redirect', function(Controller $controller, Campaign $campaign, ListSubscriber $subscriber, CampaignUrl $url){
$models = CampaignTemplateUrlActionListField::model()->findAllByAttributes(array(
'campaign_id' => $campaign->campaign_id,
'url' => $url->destination,
));
if (empty($models)) {
return;
}
foreach ($models as $model) {
$valueModel = ListFieldValue::model()->findByAttributes(array(
'field_id' => $model->field_id,
'subscriber_id' => $subscriber->subscriber_id,
));
if (empty($valueModel)) {
$valueModel = new ListFieldValue();
$valueModel->field_id = $model->field_id;
$valueModel->subscriber_id = $subscriber->subscriber_id;
}
// append the value instead.
$valueModel->value .= $model->field_value;
$valueModel->value = explode(',', $valueModel->value);
// this will make sure we only keep unique tags and remove empty strings if any
$valueModel->value = implode(', ', array_filter(array_unique(array_map('trim', $valueModel->value))));
$valueModel->save();
}
}, 99);"