Skip to content

Commit

Permalink
Force smart group refresh on mailing schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
larssandergreen committed Oct 6, 2022
1 parent eeb036a commit 6eefa69
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,25 @@ protected static function doSubmitActions(array $params, CRM_Mailing_DAO_Mailing
// Create parent job if not yet created.
// Condition on the existence of a scheduled date.
if (!empty($params['scheduled_date']) && $params['scheduled_date'] != 'null' && empty($params['_skip_evil_bao_auto_schedule_'])) {

if ($params['is_completed'] !== 1) {
$mailingGroups = \Civi\Api4\MailingGroup::get()
->addSelect('group.id')
->addJoin('Group AS group', 'LEFT', ['entity_id', '=', 'group.id'])
->addWhere('mailing_id', '=', $mailing->id)
->addWhere('entity_table', '=', 'civicrm_group')
->addWhere('group_type', 'IN', ['Include', 'Exclude'])
->addClause('OR', ['group.saved_search_id', 'IS NOT NULL'], ['group.children', 'IS NOT NULL'])
->execute();
foreach ($mailingGroups as $mailingGroup) {
CRM_Contact_BAO_GroupContactCache::invalidateGroupContactCache($mailingGroup['group.id']);
$group = new CRM_Contact_DAO_Group();
$group->find(TRUE);
$group->id = $mailingGroup['group.id'];
CRM_Contact_BAO_GroupContactCache::load($group);
}
}

$job = new CRM_Mailing_BAO_MailingJob();
$job->mailing_id = $mailing->id;
// If we are creating a new Completed mailing (e.g. import from another system) set the job to completed.
Expand Down

0 comments on commit 6eefa69

Please sign in to comment.