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

Campaign decisions after contact removed #7802

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions app/bundles/CampaignBundle/Entity/LeadRepository.php
Expand Up @@ -211,7 +211,12 @@ public function getInactiveContacts($campaignId, $decisionId, $parentDecisionId,
$q = $this->getSlaveConnection($limiter)->createQueryBuilder();
$q->select('l.lead_id, l.date_added')
->from(MAUTIC_TABLE_PREFIX.'campaign_leads', 'l')
->where($q->expr()->eq('l.campaign_id', ':campaignId'))
->where(
$q->expr()->andX(
$q->expr()->eq('l.campaign_id', ':campaignId'),
$q->expr()->eq('l.manually_removed', 0)
)
)
// Order by ID so we can query by greater than X contact ID when batching
->orderBy('l.lead_id')
->setMaxResults($limiter->getBatchLimit())
Expand Down Expand Up @@ -291,7 +296,12 @@ public function getInactiveContactCount($campaignId, array $decisionIds, Contact
$q = $this->getSlaveConnection()->createQueryBuilder();
$q->select('count(*)')
->from(MAUTIC_TABLE_PREFIX.'campaign_leads', 'l')
->where($q->expr()->eq('l.campaign_id', ':campaignId'))
->where(
$q->expr()->andX(
$q->expr()->eq('l.campaign_id', ':campaignId'),
$q->expr()->eq('l.manually_removed', 0)
)
)
// Order by ID so we can query by greater than X contact ID when batching
->orderBy('l.lead_id')
->setParameter('campaignId', (int) $campaignId);
Expand Down
Expand Up @@ -60,4 +60,35 @@ public function testEventsAreExecutedForInactiveEventWithMultipleContact()
$this->assertCount(3, $byEvent[7]); // inactive event executed
$this->assertCount(0, $byEvent[10]); // the positive path should be 0
}

public function testContactsRemovedFromTheCampaignAreNotExecutedForInactiveEvents()
{
$this->runCommand('mautic:campaigns:trigger', ['-i' => 1, '--contact-ids' => '1,2,3']);

// Wait 20 seconds then execute the campaign again to send scheduled events
sleep(20);
$this->runCommand('mautic:campaigns:trigger', ['-i' => 1, '--contact-ids' => '1,2,3']);

// No open email decisions should be recorded yet
$byEvent = $this->getCampaignEventLogs([3]);
$this->assertCount(0, $byEvent[3]);

// Wait 20 seconds to go beyond the inaction timeframe
sleep(20);

// Remove a contact from the campaign
$this->db->createQueryBuilder()->update(MAUTIC_TABLE_PREFIX.'campaign_leads')
->set('manually_removed', 1)
->where('lead_id = 1')
->execute();

// Now they should be inactive
$this->runCommand('mautic:campaigns:validate', ['--decision-id' => 3, '--contact-ids' => '1,2,3']);

// Only two contacts should have been considered inactive because one was marked as manually removed
$byEvent = $this->getCampaignEventLogs([3, 7, 10]);
$this->assertCount(2, $byEvent[3]); // decision recorded
$this->assertCount(2, $byEvent[7]); // inactive event executed
$this->assertCount(0, $byEvent[10]); // the positive path should be 0
}
}