From e9d2d24da52167fed886bce75a19ba7408f3ad26 Mon Sep 17 00:00:00 2001 From: colemanw Date: Tue, 5 Sep 2023 10:02:55 -0400 Subject: [PATCH] ScheduledCommunications - Delete when deleting saved search --- .../scheduled_communications.php | 16 ++++++++++++++++ .../crmSearchAdminSearchListing.component.js | 3 +++ 2 files changed, 19 insertions(+) diff --git a/ext/scheduled_communications/scheduled_communications.php b/ext/scheduled_communications/scheduled_communications.php index a6a677453ad7..9612b2210341 100644 --- a/ext/scheduled_communications/scheduled_communications.php +++ b/ext/scheduled_communications/scheduled_communications.php @@ -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], + ], + ]); + } +} diff --git a/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js b/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js index 9278b133a27f..9cb68b2bf078 100644 --- a/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js @@ -148,6 +148,9 @@ _.each(search.groups, function (smartGroup) { msg += '
  • ' + _.escape(ts('Smart group "%1" will also be deleted.', {1: smartGroup})) + '
  • '; }); + _.each(search.schedule_title, (communication) => { + msg += '
  • ' + _.escape(ts('Communication "%1" will also be deleted.', {1: communication})) + '
  • '; + }); if (row.afform_count) { _.each(ctrl.afforms[search.name], function (afform) { msg += '
  • ' + _.escape(ts('Form "%1" will also be deleted because it contains an embedded display from this search.', {1: afform.title})) + '
  • ';