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

Deprecate CRM_Event_BAO_Event::del() in favour of deleteRecord() #25018

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Changes from all commits
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
87 changes: 44 additions & 43 deletions CRM/Event/BAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
class CRM_Event_BAO_Event extends CRM_Event_DAO_Event {
class CRM_Event_BAO_Event extends CRM_Event_DAO_Event implements \Civi\Core\HookInterface {

/**
* Retrieve DB object and copy to defaults array.
Expand Down Expand Up @@ -171,57 +171,58 @@ public static function create(&$params) {
* Event id.
*
* @return mixed|null
*
* @deprecated
*/
public static function del($id) {
if (!$id) {
return NULL;
}

CRM_Utils_Hook::pre('delete', 'Event', $id);

$extends = ['event'];
$groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends);
foreach ($groupTree as $values) {
$query = "DELETE FROM %1 WHERE entity_id = %2";
CRM_Core_DAO::executeQuery($query, [
1 => [$values['table_name'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES],
2 => [$id, 'Integer'],
]);
}
return (bool) static::deleteRecord(['id' => $id]);
}

// Clean up references to profiles used by the event (CRM-20935)
$ufJoinParams = [
'module' => 'CiviEvent',
'entity_table' => 'civicrm_event',
'entity_id' => $id,
];
CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams);
$ufJoinParams = [
'module' => 'CiviEvent_Additional',
'entity_table' => 'civicrm_event',
'entity_id' => $id,
];
CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams);
/**
* 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' && $event->id) {

$extends = ['event'];
$groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends);
foreach ($groupTree as $values) {
$query = "DELETE FROM %1 WHERE entity_id = %2";
CRM_Core_DAO::executeQuery($query, [
1 => [$values['table_name'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES],
2 => [$event->id, 'Integer'],
]);
}

// price set cleanup, CRM-5527
CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $id);
// Clean up references to profiles used by the event (CRM-20935)
$ufJoinParams = [
'module' => 'CiviEvent',
'entity_table' => 'civicrm_event',
'entity_id' => $event->id,
];
CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams);
$ufJoinParams = [
'module' => 'CiviEvent_Additional',
'entity_table' => 'civicrm_event',
'entity_id' => $event->id,
];
CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams);

$event = new CRM_Event_DAO_Event();
$event->id = $id;
// price set cleanup, CRM-5527
CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $event->id);

if ($event->find(TRUE)) {
$locBlockId = $event->loc_block_id;
$result = $event->delete();
$eventDAO = new CRM_Event_DAO_Event();
$eventDAO->id = $event->id;

if (!is_null($locBlockId)) {
self::deleteEventLocBlock($locBlockId, $id);
if ($eventDAO->find(TRUE)) {
$locBlockId = $eventDAO->loc_block_id;
if (!is_null($locBlockId)) {
self::deleteEventLocBlock($locBlockId, $event->id);
}
}

CRM_Utils_Hook::post('delete', 'Event', $id, $event);
return $result;
}

return NULL;
}

/**
Expand Down