Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DNC enable/disable channel from Mautic prefs center #7303

Merged
merged 3 commits into from
Apr 12, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions app/bundles/LeadBundle/Controller/FrequencyRuleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,17 @@ protected function getFrequencyRuleFormData(Lead $lead, array $allChannels = nul
*/
protected function persistFrequencyRuleFormData(Lead $lead, array $formData, array $allChannels, $leadChannels, $currentChannelId = null)
{
/** @var LeadModel $model */
$model = $this->getModel('lead');
/** @var LeadModel $leadModel */
$leadModel = $this->getModel('lead.lead');

/** @var \Mautic\LeadBundle\Model\DoNotContact $dncModel */
$dncModel = $this->getModel('lead.dnc');

// iF subscribed_channels are enabled in form, then touch DNC
if (isset($this->request->request->get('lead_contact_frequency_rules')['lead_channels']['subscribed_channels'])) {
foreach ($formData['lead_channels']['subscribed_channels'] as $contactChannel) {
if (!isset($leadChannels[$contactChannel])) {
$contactable = $model->isContactable($lead, $contactChannel);
if ($contactable == DoNotContact::UNSUBSCRIBED) {
// Only resubscribe if the contact did not opt out themselves
$model->removeDncForLead($lead, $contactChannel);
}
$dncModel->removeDncForContact($lead->getId(), $contactChannel);
}
}
$dncChannels = array_diff($allChannels, $formData['lead_channels']['subscribed_channels']);
Expand All @@ -194,15 +193,10 @@ protected function persistFrequencyRuleFormData(Lead $lead, array $formData, arr
if ($currentChannelId) {
$channel = [$channel => $currentChannelId];
}
$model->addDncForLead(
$lead,
$channel,
'user',
($this->isPublicView) ? DoNotContact::UNSUBSCRIBED : DoNotContact::MANUAL
);
$dncModel->addDncForContact($lead->getId(), $channel, ($this->isPublicView) ? DoNotContact::UNSUBSCRIBED : DoNotContact::MANUAL, 'user');
}
}
}
$model->setFrequencyRules($lead, $formData, $this->leadLists);
$leadModel->setFrequencyRules($lead, $formData, $this->leadLists);
}
}