Skip to content

Commit

Permalink
ScheduledCommunications - Delete when deleting saved search
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Sep 5, 2023
1 parent 2245b1b commit e9d2d24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ext/scheduled_communications/scheduled_communications.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ function scheduled_communications_civicrm_install(): void {
function scheduled_communications_civicrm_enable(): void {
_scheduled_communications_civix_civicrm_enable();
}

/**
* Implements hook_civicrm_post().
*/
function scheduled_communications_civicrm_post($op, $entity, $id, $object): void {
// Delete scheduled communications linked to a deleted saved search
if ($entity === 'SavedSearch' && $op === 'delete' && $id) {
civicrm_api4('ActionSchedule', 'delete', [
'checkPermissions' => FALSE,
'where' => [
['mapping_id', '=', '"saved_search"'],
['entity_value', '=', $id],
],
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
_.each(search.groups, function (smartGroup) {
msg += '<li class="crm-error"><i class="crm-i fa-exclamation-triangle"></i> ' + _.escape(ts('Smart group "%1" will also be deleted.', {1: smartGroup})) + '</li>';
});
_.each(search.schedule_title, (communication) => {
msg += '<li class="crm-error"><i class="crm-i fa-exclamation-triangle"></i> ' + _.escape(ts('Communication "%1" will also be deleted.', {1: communication})) + '</li>';
});
if (row.afform_count) {
_.each(ctrl.afforms[search.name], function (afform) {
msg += '<li class="crm-error"><i class="crm-i fa-exclamation-triangle"></i> ' + _.escape(ts('Form "%1" will also be deleted because it contains an embedded display from this search.', {1: afform.title})) + '</li>';
Expand Down

0 comments on commit e9d2d24

Please sign in to comment.