Deprecate unnecessary del() functions
authorColeman Watts <coleman@civicrm.org>
Fri, 20 Aug 2021 18:22:06 +0000 (14:22 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 22 Aug 2021 02:13:38 +0000 (22:13 -0400)
12 files changed:
CRM/ACL/BAO/ACLEntityRole.php
CRM/Badge/BAO/Layout.php
CRM/Campaign/BAO/Campaign.php
CRM/Core/BAO/ActionSchedule.php
CRM/Core/BAO/EntityTag.php
CRM/Core/BAO/Job.php
CRM/Core/BAO/UFField.php
CRM/Mailing/BAO/MailingJob.php
CRM/Member/BAO/MembershipBlock.php
CRM/Member/BAO/MembershipPayment.php
CRM/Pledge/BAO/PledgePayment.php
CRM/Price/BAO/PriceFieldValue.php

index 177d07ffa64cffea10782d7b9a7ff5ed6b066727..fba736ac8ada7d8fcac00760b6871d446428d148 100644 (file)
@@ -69,10 +69,10 @@ class CRM_ACL_BAO_ACLEntityRole extends CRM_ACL_DAO_ACLEntityRole {
    *
    * @param int $entityRoleId
    *   ID of the EntityRole record to be deleted.
-   *
+   * @deprecated
    */
   public static function del($entityRoleId) {
-    return parent::deleteRecord(['id' => $entityRoleId]);
+    return self::deleteRecord(['id' => $entityRoleId]);
   }
 
 }
index b69409e1cb6dac5df487bdbeda61dacc6430b2e3..e631eb0ae3b54819cbb75e0b196bbaf0b84e8426 100644 (file)
@@ -106,13 +106,10 @@ class CRM_Badge_BAO_Layout extends CRM_Core_DAO_PrintLabel {
    * Delete name labels.
    *
    * @param int $printLabelId
-   *   ID of the name label to be deleted.
-   *
+   * @deprecated
    */
   public static function del($printLabelId) {
-    $printLabel = new CRM_Core_DAO_PrintLabel();
-    $printLabel->id = $printLabelId;
-    $printLabel->delete();
+    self::deleteRecord(['id' => $printLabelId]);
   }
 
   /**
index 40a0ae36d130733b511d90b79eebb4d7ef741351..a4dc88945d323b28011c0ed23c2378162976cf72 100644 (file)
@@ -77,24 +77,18 @@ class CRM_Campaign_BAO_Campaign extends CRM_Campaign_DAO_Campaign {
    * Delete the campaign.
    *
    * @param int $id
-   *   Id of the campaign.
    *
-   * @return bool|mixed
+   * @deprecated
+   * @return bool|int
    */
   public static function del($id) {
-    if (!$id) {
+    try {
+      self::deleteRecord(['id' => $id]);
+    }
+    catch (CRM_Core_Exception $e) {
       return FALSE;
     }
-
-    CRM_Utils_Hook::pre('delete', 'Campaign', $id);
-
-    $dao = new CRM_Campaign_DAO_Campaign();
-    $dao->id = $id;
-    $result = $dao->delete();
-
-    CRM_Utils_Hook::post('delete', 'Campaign', $id, $dao);
-
-    return $result;
+    return 1;
   }
 
   /**
index 5b6fbf84cf3895ac1bc77fcc4386f897c5c62c8d..209097cb6b097943604e56ed4ba3c20d9c590896 100644 (file)
@@ -213,20 +213,11 @@ FROM civicrm_action_schedule cas
    * Delete a Reminder.
    *
    * @param int $id
-   *   ID of the Reminder to be deleted.
-   *
+   * @deprecated
    * @throws CRM_Core_Exception
    */
   public static function del($id) {
-    if ($id) {
-      $dao = new CRM_Core_DAO_ActionSchedule();
-      $dao->id = $id;
-      if ($dao->find(TRUE)) {
-        $dao->delete();
-        return;
-      }
-    }
-    throw new CRM_Core_Exception(ts('Invalid value passed to delete function.'));
+    self::deleteRecord(['id' => $id]);
   }
 
   /**
index 9000ade79c99d61973e458be756ce683c66a8f45..36f5284ea91a83ac67c09c7745d82d8c340aff25 100644 (file)
@@ -96,7 +96,8 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag {
    * Delete the tag for a contact.
    *
    * @param array $params
-   *   (reference ) an assoc array of name/value pairs.
+   *
+   * WARNING: Nonstandard params searches by tag_id rather than id!
    */
   public static function del(&$params) {
     //invoke pre hook
index e78458fd2c7212b110d0d0aae64a7bdd4b610d55..dbb736ec96f1521a81d5a221bb8334af2359d22e 100644 (file)
@@ -85,25 +85,14 @@ class CRM_Core_BAO_Job extends CRM_Core_DAO_Job {
    * Function  to delete scheduled job.
    *
    * @param $jobID
-   *   ID of the job to be deleted.
    *
    * @return bool|null
+   * @deprecated
    * @throws CRM_Core_Exception
    */
   public static function del($jobID) {
-    if (!$jobID) {
-      throw new CRM_Core_Exception(ts('Invalid value passed to delete function.'));
-    }
-
-    $dao = new CRM_Core_DAO_Job();
-    $dao->id = $jobID;
-    if (!$dao->find(TRUE)) {
-      return NULL;
-    }
-
-    if ($dao->delete()) {
-      return TRUE;
-    }
+    self::deleteRecord(['id' => $jobID]);
+    return TRUE;
   }
 
   /**
index 2e1a4dc56d8aeba39ed7f2bb0416c6d49773d817..b26e8831b224abfcdc8dea9d3bd0643720475abe 100644 (file)
@@ -157,17 +157,11 @@ class CRM_Core_BAO_UFField extends CRM_Core_DAO_UFField {
    * Delete the profile Field.
    *
    * @param int $id
-   *   Field Id.
-   *
+   * @deprecated
    * @return bool
-   *
    */
   public static function del($id) {
-    //delete  field field
-    $field = new CRM_Core_DAO_UFField();
-    $field->id = $id;
-    $field->delete();
-    return TRUE;
+    return (bool) self::deleteRecord(['id' => $id]);
   }
 
   /**
index 020c65b7e16fc70dabeac638b174b1446c962487..46aa1fec5fc079dc65525ad7ec1fd1c80b5ddd98 100644 (file)
@@ -1117,20 +1117,11 @@ AND    record_type_id = $targetRecordID
    * Delete the mailing job.
    *
    * @param int $id
-   *   Mailing Job id.
-   *
-   * @return mixed
+   * @deprecated
+   * @return bool
    */
   public static function del($id) {
-    CRM_Utils_Hook::pre('delete', 'MailingJob', $id);
-
-    $jobDAO = new CRM_Mailing_BAO_MailingJob();
-    $jobDAO->id = $id;
-    $result = $jobDAO->delete();
-
-    CRM_Utils_Hook::post('delete', 'MailingJob', $jobDAO->id, $jobDAO);
-
-    return $result;
+    return (bool) self::deleteRecord(['id' => $id]);
   }
 
 }
index 94a7cb5ba3418bb49e4982cce22846340994670f..6c5dfdc93161f9f7fd4728313e6269a5cf210224 100644 (file)
@@ -37,18 +37,11 @@ class CRM_Member_BAO_MembershipBlock extends CRM_Member_DAO_MembershipBlock {
    * Delete membership Blocks.
    *
    * @param int $id
-   *
+   * @deprecated
    * @return bool
    */
   public static function del($id) {
-    $dao = new CRM_Member_DAO_MembershipBlock();
-    $dao->id = $id;
-    $result = FALSE;
-    if ($dao->find(TRUE)) {
-      $dao->delete();
-      $result = TRUE;
-    }
-    return $result;
+    return (bool) self::deleteRecord(['id' => $id]);
   }
 
 }
index 32d9af030f2c626c0156233fc911aa8e2fd2b3c9..e19b1fdbf2d5e30f584343c82b83a74d1e26e4b0 100644 (file)
@@ -84,18 +84,11 @@ class CRM_Member_BAO_MembershipPayment extends CRM_Member_DAO_MembershipPayment
    * Delete membership Payments.
    *
    * @param int $id
-   *
+   * @deprecated
    * @return bool
    */
   public static function del($id) {
-    $dao = new CRM_Member_DAO_MembershipPayment();
-    $dao->id = $id;
-    $result = FALSE;
-    if ($dao->find(TRUE)) {
-      $dao->delete();
-      $result = TRUE;
-    }
-    return $result;
+    return (bool) self::deleteRecord(['id' => $id]);
   }
 
 }
index 91930d465e8568799c583533e28b4cd015e659ad..e48e2788a410c425dbe6496eb23237026c526fb2 100644 (file)
@@ -203,27 +203,11 @@ WHERE     pledge_id = %1
    * Delete pledge payment.
    *
    * @param int $id
-   *
-   * @return int
-   *   pledge payment id
+   * @deprecated
+   * @return bool
    */
   public static function del($id) {
-    $payment = new CRM_Pledge_DAO_PledgePayment();
-    $payment->id = $id;
-    if ($payment->find()) {
-      $payment->fetch();
-
-      CRM_Utils_Hook::pre('delete', 'PledgePayment', $id, $payment);
-
-      $result = $payment->delete();
-
-      CRM_Utils_Hook::post('delete', 'PledgePayment', $id, $payment);
-
-      return $result;
-    }
-    else {
-      return FALSE;
-    }
+    return (bool) self::deleteRecord(['id' => $id]);
   }
 
   /**
index e33b1ed83b607d57ce86b321863aeea78b0ec592..5df67efec829ad5482625d3daac366f7b63afa8a 100644 (file)
@@ -217,19 +217,12 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue {
    * Delete the value.
    *
    * @param int $id
-   *   Id.
    *
+   * @deprecated
    * @return bool
-   *
    */
   public static function del($id) {
-    if (!$id) {
-      return FALSE;
-    }
-
-    $fieldValueDAO = new CRM_Price_DAO_PriceFieldValue();
-    $fieldValueDAO->id = $id;
-    return $fieldValueDAO->delete();
+    return (bool) self::deleteRecord(['id' => $id]);
   }
 
   /**