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

Standardize deletion mechanics across ~13 BAOs #22207

Merged
merged 13 commits into from
Dec 6, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
MessageTemplates - Use standard delete function which calls hooks
  • Loading branch information
colemanw committed Dec 4, 2021
commit ec7e0f40f5e8049eec94aee3068fc86b677b423e
33 changes: 20 additions & 13 deletions CRM/Core/BAO/MessageTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* Class CRM_Core_BAO_MessageTemplate.
*/
class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate {
class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate implements \Civi\Test\HookInterface {

/**
* Fetch object based on array of properties.
Expand Down Expand Up @@ -165,7 +165,7 @@ public static function add(&$params) {
* Delete the Message Templates.
*
* @param int $messageTemplatesID
*
* @deprecated
* @throws \CRM_Core_Exception
*/
public static function del($messageTemplatesID) {
Expand All @@ -174,20 +174,27 @@ public static function del($messageTemplatesID) {
throw new CRM_Core_Exception(ts('Invalid Message template'));
}

// Set mailing msg template col to NULL
$query = "UPDATE civicrm_mailing
SET msg_template_id = NULL
WHERE msg_template_id = %1";

$params = [1 => [$messageTemplatesID, 'Integer']];
CRM_Core_DAO::executeQuery($query, $params);

$messageTemplates = new CRM_Core_DAO_MessageTemplate();
$messageTemplates->id = $messageTemplatesID;
$messageTemplates->delete();
static::deleteRecord(['id' => $messageTemplatesID]);
// Yikes - bad idea setting status messages in BAO CRUD functions. Don't do this.
CRM_Core_Session::setStatus(ts('Selected message template has been deleted.'), ts('Deleted'), 'success');
}

/**
* Callback for hook_civicrm_pre().
* @param \Civi\Core\Event\PreEvent $event
* @throws CRM_Core_Exception
*/
public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) {
if ($event->action === 'delete') {
// Set mailing msg template col to NULL
$query = "UPDATE civicrm_mailing
SET msg_template_id = NULL
WHERE msg_template_id = %1";
$params = [1 => [$event->id, 'Integer']];
CRM_Core_DAO::executeQuery($query, $params);
}
}

/**
* Get the Message Templates.
*
Expand Down