diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index d026cf8df7bc25dff5e02918aaa0d7aec32a74bf..d7b72b9e766c3b62c1890c845f1392bdad2838dc 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -48,24 +48,12 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping { * Delete the mapping. * * @param int $id - * Mapping id. * + * @deprecated * @return bool */ public static function del($id) { - // delete from mapping_field table - $mappingField = new CRM_Core_DAO_MappingField(); - $mappingField->mapping_id = $id; - $mappingField->delete(); - - // delete from mapping table - $mapping = new CRM_Core_DAO_Mapping(); - $mapping->id = $id; - if ($mapping->find(TRUE)) { - $result = $mapping->delete(); - return $result; - } - return FALSE; + return (bool) static::deleteRecord(['id' => $id]); } /** diff --git a/CRM/Core/DAO/MappingField.php b/CRM/Core/DAO/MappingField.php index 9c976231026f80f663620d16270064899a2b2f97..833fdff45f2dc4a443252d82fa86cbec28c010ed 100644 --- a/CRM/Core/DAO/MappingField.php +++ b/CRM/Core/DAO/MappingField.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/MappingField.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:d2ce640ccb1f30190097cced450038e0) + * (GenCodeChecksum:4333a20d925fb437b4764219e31ee017) */ /** diff --git a/CRM/Upgrade/Incremental/php/FiveFortyThree.php b/CRM/Upgrade/Incremental/php/FiveFortyThree.php index 413b61e62bb5a6ed4404360582c5fc5f759c39b8..48b8f98ef43d36c4f55ec7edd0529e830ef2a241 100644 --- a/CRM/Upgrade/Incremental/php/FiveFortyThree.php +++ b/CRM/Upgrade/Incremental/php/FiveFortyThree.php @@ -10,7 +10,8 @@ */ /** - * Upgrade logic for FiveFortyThree */ + * Upgrade logic for FiveFortyThree + */ class CRM_Upgrade_Incremental_php_FiveFortyThree extends CRM_Upgrade_Incremental_Base { /** @@ -49,12 +50,6 @@ class CRM_Upgrade_Incremental_php_FiveFortyThree extends CRM_Upgrade_Incremental // } } - /* - * Important! All upgrade functions MUST add a 'runSql' task. - * Uncomment and use the following template for a new upgrade version - * (change the x in the function name): - */ - /** * Upgrade function. * @@ -63,7 +58,7 @@ class CRM_Upgrade_Incremental_php_FiveFortyThree extends CRM_Upgrade_Incremental public function upgrade_5_43_alpha1(string $rev): void { $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); $this->addTask('Fix DB Collation if needed on the relatonship cache table', 'fixRelationshipCacheTableCollation'); - + $this->addTask('Make mapping field foreign key cascade delete', 'alterMappingFK'); $this->addTask('Replace legacy displayName smarty token in Online contribution workflow template', 'updateMessageToken', 'contribution_online_receipt', '$displayName', 'contact.display_name', $rev ); @@ -75,6 +70,22 @@ class CRM_Upgrade_Incremental_php_FiveFortyThree extends CRM_Upgrade_Incremental ); } + /** + * @param \CRM_Queue_TaskContext $ctx + * + * @return bool + */ + public static function alterMappingFK(CRM_Queue_TaskContext $ctx): bool { + CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mapping_field', 'FK_civicrm_mapping_field_mapping_id'); + CRM_Core_DAO::executeQuery(' + ALTER TABLE civicrm_mapping_field + ADD CONSTRAINT `FK_civicrm_mapping_field_mapping_id` + FOREIGN KEY (`mapping_id`) + REFERENCES `civicrm_mapping`(`id`) ON DELETE CASCADE + ', [], TRUE, NULL, FALSE, FALSE); + return TRUE; + } + public static function fixRelationshipCacheTableCollation():bool { $contactTableCollation = CRM_Core_BAO_SchemaHandler::getInUseCollation(); $dao = CRM_Core_DAO::executeQuery('SHOW TABLE STATUS LIKE \'civicrm_relationship_cache\''); diff --git a/xml/schema/Core/MappingField.xml b/xml/schema/Core/MappingField.xml index 0f4114aacf870af4e1ef250eb546f261c81b1b81..10cf1c4d542dfd03a7b0924f85ec8c763ba33c17 100644 --- a/xml/schema/Core/MappingField.xml +++ b/xml/schema/Core/MappingField.xml @@ -38,6 +38,7 @@ <table>civicrm_mapping</table> <key>id</key> <add>1.2</add> + <onDelete>CASCADE</onDelete> </foreignKey> <field> <name>name</name>