From 1d4cebf30b0815f2c3ffc15d3030f412c8aff62c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 20 Aug 2021 14:08:34 -0400 Subject: [PATCH] Core - Cleanup BAO::del() functions with unnecessary FK checks These were using PHP to enforce key constraints better taken care of by MySQL. --- CRM/Contribute/BAO/Product.php | 13 ++----------- CRM/Core/BAO/Tag.php | 24 ++---------------------- CRM/Core/DAO.php | 1 + 3 files changed, 5 insertions(+), 33 deletions(-) diff --git a/CRM/Contribute/BAO/Product.php b/CRM/Contribute/BAO/Product.php index eb79c86d7b..5d0a6ff42d 100644 --- a/CRM/Contribute/BAO/Product.php +++ b/CRM/Contribute/BAO/Product.php @@ -111,20 +111,11 @@ class CRM_Contribute_BAO_Product extends CRM_Contribute_DAO_Product { * Delete premium Types. * * @param int $productID - * + * @deprecated * @throws \CRM_Core_Exception */ public static function del($productID) { - //check dependencies - $premiumsProduct = new CRM_Contribute_DAO_PremiumsProduct(); - $premiumsProduct->product_id = $productID; - if ($premiumsProduct->find(TRUE)) { - throw new CRM_Core_Exception('Cannot delete a Premium that is linked to a Contribution page'); - } - // delete product - $premium = new CRM_Contribute_DAO_Product(); - $premium->id = $productID; - $premium->delete(); + static::deleteRecord(['id' => $productID]); } } diff --git a/CRM/Core/BAO/Tag.php b/CRM/Core/BAO/Tag.php index 17c0bc47cc..8a75503da1 100644 --- a/CRM/Core/BAO/Tag.php +++ b/CRM/Core/BAO/Tag.php @@ -349,31 +349,11 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { * Delete the tag. * * @param int $id - * Tag id. - * + * @deprecated * @return bool */ public static function del($id) { - // since this is a destructive operation, lets make sure - // id is a positive number - CRM_Utils_Type::validate($id, 'Positive'); - - // delete all crm_entity_tag records with the selected tag id - $entityTag = new CRM_Core_DAO_EntityTag(); - $entityTag->tag_id = $id; - $entityTag->delete(); - - // delete from tag table - $tag = new CRM_Core_DAO_Tag(); - $tag->id = $id; - - CRM_Utils_Hook::pre('delete', 'Tag', $id, $tag); - - if ($tag->delete()) { - CRM_Utils_Hook::post('delete', 'Tag', $id, $tag); - return TRUE; - } - return FALSE; + return (bool) static::deleteRecord(['id' => $id]); } /** diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 5bb34367c7..4e76a60f4d 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -957,6 +957,7 @@ class CRM_Core_DAO extends DB_DataObject { if (empty($record['id'])) { throw new CRM_Core_Exception("Cannot delete {$entityName} with no id."); } + CRM_Utils_Type::validate($record['id'], 'Positive'); CRM_Utils_Hook::pre('delete', $entityName, $record['id'], $record); $instance = new $className(); -- 2.25.1