Deprecate relationship::del
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 8 Mar 2023 20:58:17 +0000 (09:58 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 8 Mar 2023 20:58:17 +0000 (09:58 +1300)
CRM/Admin/Form/RelationshipType.php
CRM/Contact/BAO/RelationshipType.php
CRM/Contact/Form/Relationship.php
CRM/Contact/Page/View/Relationship.php
api/v3/Relationship.php

index 544807eb504ec304dcf2e3c63a84453455d809b4..c109a2835cd528bfadcff5be6fe61f5b47ca213b 100644 (file)
@@ -161,7 +161,7 @@ class CRM_Admin_Form_RelationshipType extends CRM_Admin_Form {
    */
   public function postProcess() {
     if ($this->_action & CRM_Core_Action::DELETE) {
-      CRM_Contact_BAO_RelationshipType::del($this->_id);
+      CRM_Contact_BAO_RelationshipType::deleteRecord(['id' => $this->_id]);
       CRM_Core_Session::setStatus(ts('Selected Relationship type has been deleted.'), ts('Record Deleted'), 'success');
     }
     else {
index 3daef9e626b0b78c8c52a9699d8d9d3793ff5f64..3059ac9e49b53f34520b244dc74b190697bdb982 100644 (file)
@@ -98,12 +98,8 @@ class CRM_Contact_BAO_RelationshipType extends CRM_Contact_DAO_RelationshipType
    * @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'));
-    }
+    CRM_Core_Error::deprecatedFunctionWarning('deleteRecord');
+
     return static::deleteRecord(['id' => $relationshipTypeId]);
   }
 
index 41c11d221ad8bbd0d3ed46b4adad5cc2caf0e7cd..47116d7d17592d1fafa632cdb103052aced48c7b 100644 (file)
@@ -508,7 +508,7 @@ class CRM_Contact_Form_Relationship extends CRM_Core_Form {
    *   Relationship ID
    */
   private function deleteAction($id) {
-    CRM_Contact_BAO_Relationship::del($id);
+    CRM_Contact_BAO_Relationship::deleteRecord(['id' => $id]);
     CRM_Core_Session::setStatus(ts('Selected relationship has been deleted successfully.'), ts('Record Deleted'), 'success');
 
     // reload all blocks to reflect this change on the user interface.
index 1b5ce208283dc33182881800ad8a35c518c8e46e..1740059051e3117d6bd3005197fdf65ae2f0384c 100644 (file)
@@ -181,7 +181,7 @@ class CRM_Contact_Page_View_Relationship extends CRM_Core_Page {
       }
 
       // delete relationship
-      CRM_Contact_BAO_Relationship::del($this->getEntityId());
+      CRM_Contact_BAO_Relationship::deleteRecord(['id' => $this->getEntityId()]);
       CRM_Core_Session::setStatus(ts('Selected relationship has been deleted successfully.'), ts('Record Deleted'), 'success');
 
       CRM_Utils_System::redirect($url);
@@ -240,7 +240,7 @@ class CRM_Contact_Page_View_Relationship extends CRM_Core_Page {
    */
   public function delete() {
     // calls a function to delete relationship
-    CRM_Contact_BAO_Relationship::del($this->getEntityId());
+    CRM_Contact_BAO_Relationship::deleteRecord(['id' => $this->getEntityId()]);
     CRM_Core_Session::setStatus(ts('Selected relationship has been deleted successfully.'), ts('Record Deleted'), 'success');
   }
 
index f1f7664beeb1f5ccfd8fd56f9ba34e4e778e32aa..4e7cbc9beef1e75ad622429b5823ffca2ba24e80 100644 (file)
@@ -56,22 +56,11 @@ function _civicrm_api3_relationship_create_spec(&$params) {
  *
  * @return array
  *   API Result Array
+ *
+ * @throws \CRM_Core_Exception
  */
-function civicrm_api3_relationship_delete($params) {
-
-  if (!CRM_Utils_Rule::integer($params['id'])) {
-    return civicrm_api3_create_error('Invalid value for relationship ID');
-  }
-
-  $relationBAO = new CRM_Contact_BAO_Relationship();
-  $relationBAO->id = $params['id'];
-  if (!$relationBAO->find(TRUE)) {
-    return civicrm_api3_create_error('Relationship id is not valid');
-  }
-  else {
-    $relationBAO->del($params['id']);
-    return civicrm_api3_create_success('Deleted relationship successfully');
-  }
+function civicrm_api3_relationship_delete(array $params): array {
+  return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
 /**