/** * Function to delete Relationship Types * * @param int $relationshipTypeId * @static */ static function del($relationshipTypeId) { // make sure relationshipTypeId is an integer // @todo review this as most delete functions rely on the api & form layer for this // or do a find first & throw error if no find if (!CRM_Utils_Rule::positiveInteger($relationshipTypeId)) { throw new CRM_Core_Exception(ts('Invalid relationship type')); } //check dependencies // delete all relationships $relationship = new CRM_Contact_DAO_Relationship(); $relationship->relationship_type_id = $relationshipTypeId; $relationship->delete(); // set all membership_type to null $query = "\nUPDATE civicrm_membership_type\n SET relationship_type_id = NULL\n WHERE relationship_type_id = %1\n"; $params = array(1 => array(CRM_Core_DAO::VALUE_SEPARATOR . $relationshipTypeId . CRM_Core_DAO::VALUE_SEPARATOR, 'String')); CRM_Core_DAO::executeQuery($query, $params); //fixed for CRM-3323 $mappingField = new CRM_Core_DAO_MappingField(); $mappingField->relationship_type_id = $relationshipTypeId; $mappingField->find(); while ($mappingField->fetch()) { $mappingField->delete(); } $relationshipType = new CRM_Contact_DAO_RelationshipType(); $relationshipType->id = $relationshipTypeId; return $relationshipType->delete(); }
/** * Delete Relationship Types. * * @param int $relationshipTypeId * * @throws CRM_Core_Exception * @return mixed */ public static function del($relationshipTypeId) { // make sure relationshipTypeId is an integer // @todo review this as most delete functions rely on the api & form layer for this // or do a find first & throw error if no find if (!CRM_Utils_Rule::positiveInteger($relationshipTypeId)) { throw new CRM_Core_Exception(ts('Invalid relationship type')); } //check dependencies // delete all relationships $relationship = new CRM_Contact_DAO_Relationship(); $relationship->relationship_type_id = $relationshipTypeId; $relationship->delete(); // remove this relationship type from membership types $mems = civicrm_api3('MembershipType', 'get', array('relationship_type_id' => array('LIKE' => "%{$relationshipTypeId}%"), 'return' => array('id', 'relationship_type_id', 'relationship_direction'))); foreach ($mems['values'] as $membershipTypeId => $membershipType) { $pos = array_search($relationshipTypeId, $membershipType['relationship_type_id']); // Api call may have returned false positives but currently the relationship_type_id uses // nonstandard serialization which makes anything more accurate impossible. if ($pos !== FALSE) { unset($membershipType['relationship_type_id'][$pos], $membershipType['relationship_direction'][$pos]); civicrm_api3('MembershipType', 'create', $membershipType); } } //fixed for CRM-3323 $mappingField = new CRM_Core_DAO_MappingField(); $mappingField->relationship_type_id = $relationshipTypeId; $mappingField->find(); while ($mappingField->fetch()) { $mappingField->delete(); } $relationshipType = new CRM_Contact_DAO_RelationshipType(); $relationshipType->id = $relationshipTypeId; return $relationshipType->delete(); }
/** * Function to delete Relationship Types * * @param int $relationshipTypeId * @static */ static function del($relationshipTypeId) { // make sure relationshipTypeId is an integer if (!CRM_Utils_Rule::positiveInteger($relationshipTypeId)) { CRM_Core_Error::fatal(ts('Invalid relationship type')); } //check dependencies // delete all relationships $relationship = new CRM_Contact_DAO_Relationship(); $relationship->relationship_type_id = $relationshipTypeId; $relationship->delete(); // set all membership_type to null $query = "\nUPDATE civicrm_membership_type\n SET relationship_type_id = NULL\n WHERE relationship_type_id = %1\n"; $params = array(1 => array($relationshipTypeId, 'Integer')); CRM_Core_DAO::executeQuery($query, $params); //fixed for CRM-3323 $mappingField = new CRM_Core_DAO_MappingField(); $mappingField->relationship_type_id = $relationshipTypeId; $mappingField->find(); while ($mappingField->fetch()) { $mappingField->delete(); } $relationshipType = new CRM_Contact_DAO_RelationshipType(); $relationshipType->id = $relationshipTypeId; return $relationshipType->delete(); }