BAO - deprecate create for writeRecord: SubscriptionHistory
authorColeman Watts <coleman@civicrm.org>
Sat, 1 Apr 2023 23:50:11 +0000 (19:50 -0400)
committerColeman Watts <coleman@civicrm.org>
Sat, 1 Apr 2023 23:50:11 +0000 (19:50 -0400)
CRM/Contact/BAO/SubscriptionHistory.php

index 5deb2c729f440e2b6c1adbdba5630a41d800b395..10caeffe3840823eeaf58aa978417a3e494f97cf 100644 (file)
  */
 
 /**
- * BAO object for crm_email table.
+ * BAO object for civicrm_subscription_history table.
  */
-class CRM_Contact_BAO_SubscriptionHistory extends CRM_Contact_DAO_SubscriptionHistory {
+class CRM_Contact_BAO_SubscriptionHistory extends CRM_Contact_DAO_SubscriptionHistory implements \Civi\Core\HookInterface {
 
   /**
-   * Create a new subscription history record.
-   *
+   * @deprecated
    * @param array $params
-   *   Values for the new history record.
-   *
-   * @return object
-   *   $history  The new history object
+   * @return CRM_Contact_DAO_SubscriptionHistory
    */
   public static function create($params) {
-    $history = new CRM_Contact_BAO_SubscriptionHistory();
-    $history->date = date('YmdHis');
-    $history->copyValues($params);
-    $history->save();
-    return $history;
+    return self::writeRecord($params);
+  }
+
+  /**
+   * Callback for hook_civicrm_pre().
+   *
+   * @param \Civi\Core\Event\PreEvent $event
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event): void {
+    if ($event->action === 'create' || $event->action === 'edit') {
+      $event->params['date'] = date('YmdHis');
+    }
   }
 
   /**