BAO - Deprecate email/im/phone/website/openId create/add functions in favor of writeR...
authorColeman Watts <coleman@civicrm.org>
Tue, 28 Mar 2023 13:13:33 +0000 (09:13 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 29 Mar 2023 21:58:32 +0000 (17:58 -0400)
CRM/Core/BAO/Email.php
CRM/Core/BAO/IM.php
CRM/Core/BAO/OpenID.php
CRM/Core/BAO/Phone.php
CRM/Core/BAO/Website.php
tests/phpunit/CRM/Contact/BAO/ContactTest.php
tests/phpunit/CRM/Core/BAO/PhoneTest.php

index 173b697cf9e597f711d8925d20327d30e4926805..c35b34d77d717e981e42f87ceda0f18723ba0a44 100644 (file)
@@ -25,13 +25,15 @@ class CRM_Core_BAO_Email extends CRM_Core_DAO_Email implements Civi\Core\HookInt
 
   /**
    * @deprecated
+   *
    * @param array $params
    * @return CRM_Core_BAO_Email
+   * @throws CRM_Core_Exception
    */
   public static function create($params) {
     // FIXME: switch CRM_Core_BAO_Block::create to call writeRecord (once Address, IM, Phone create functions go through it)
     // then this can be uncommented:
-    // CRM_Core_Error::deprecatedFunctionWarning('writeRecord');
+    CRM_Core_Error::deprecatedFunctionWarning('writeRecord');
     return self::writeRecord($params);
   }
 
@@ -41,7 +43,7 @@ class CRM_Core_BAO_Email extends CRM_Core_DAO_Email implements Civi\Core\HookInt
    */
   public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) {
     if (in_array($event->action, ['create', 'edit'])) {
-      CRM_Core_BAO_Block::handlePrimary($event->params, get_class());
+      CRM_Core_BAO_Block::handlePrimary($event->params, __CLASS__);
 
       if (!empty($event->params['email'])) {
         // lower case email field to optimize queries
@@ -96,8 +98,10 @@ WHERE  contact_id = {$event->params['contact_id']}
 
   /**
    * @deprecated
+   *
    * @param array $params
    * @return CRM_Core_BAO_Email
+   * @throws CRM_Core_Exception
    */
   public static function add($params) {
     CRM_Core_Error::deprecatedFunctionWarning('writeRecord');
index b1a916c374d3d42982d76f51e12c20cb18d41c0c..a305dab03b7448c4c9fdcbfc430375a6e899dba7 100644 (file)
 /**
  * This class contain function for IM handling
  */
-class CRM_Core_BAO_IM extends CRM_Core_DAO_IM {
+class CRM_Core_BAO_IM extends CRM_Core_DAO_IM implements Civi\Core\HookInterface {
   use CRM_Contact_AccessTrait;
 
   /**
-   * Create or update IM record.
+   * @deprecated
    *
    * @param array $params
-   *
-   * @return \CRM_Core_DAO|\CRM_Core_DAO_IM
-   * @throws \CRM_Core_Exception
+   * @return CRM_Core_DAO_IM
+   * @throws CRM_Core_Exception
    */
   public static function create($params) {
-    CRM_Core_BAO_Block::handlePrimary($params, __CLASS__);
+    CRM_Core_Error::deprecatedFunctionWarning('writeRecord');
     return self::writeRecord($params);
   }
 
   /**
-   * Create or update IM record.
-   *
+   * Event fired before modifying an IM.
+   * @param \Civi\Core\Event\PreEvent $event
+   */
+  public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) {
+    if (in_array($event->action, ['create', 'edit'])) {
+      CRM_Core_BAO_Block::handlePrimary($event->params, __CLASS__);
+    }
+  }
+
+  /**
    * @deprecated
    *
    * @param array $params
-   *
-   * @return \CRM_Core_DAO|\CRM_Core_DAO_IM
-   * @throws \CRM_Core_Exception
+   * @return CRM_Core_DAO_IM
+   * @throws CRM_Core_Exception
    */
   public static function add($params) {
-    CRM_Core_Error::deprecatedFunctionWarning('use the v4 api');
     return self::create($params);
   }
 
index c82a42dfabefe57cabe9c167cf7508e44473be69..df2a04705bf5ccd69ce87404daa87a5d7cc1487c 100644 (file)
 /**
  * This class contains function for Open Id
  */
-class CRM_Core_BAO_OpenID extends CRM_Core_DAO_OpenID {
+class CRM_Core_BAO_OpenID extends CRM_Core_DAO_OpenID implements Civi\Core\HookInterface {
   use CRM_Contact_AccessTrait;
 
   /**
-   * Create or update OpenID record.
+   * @deprecated
    *
    * @param array $params
-   *
    * @return CRM_Core_DAO_OpenID
-   *
-   * @throws \CRM_Core_Exception
+   * @throws CRM_Core_Exception
    */
   public static function create($params) {
-    CRM_Core_BAO_Block::handlePrimary($params, __CLASS__);
+    CRM_Core_Error::deprecatedFunctionWarning('writeRecord');
     return self::writeRecord($params);
   }
 
   /**
-   * Create or update OpenID record.
-   *
+   * Event fired before modifying an OpenID.
+   * @param \Civi\Core\Event\PreEvent $event
+   */
+  public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) {
+    if (in_array($event->action, ['create', 'edit'])) {
+      CRM_Core_BAO_Block::handlePrimary($event->params, __CLASS__);
+    }
+  }
+
+  /**
    * @deprecated
    *
    * @param array $params
-   *
-   * @return \CRM_Core_DAO|\CRM_Core_DAO_IM
-   * @throws \CRM_Core_Exception
+   * @return CRM_Core_DAO_OpenID
+   * @throws CRM_Core_Exception
    */
   public static function add($params) {
-    CRM_Core_Error::deprecatedFunctionWarning('use the v4 api');
     return self::create($params);
   }
 
index cf095fa29a6d9c127f7474211b74b5c2e2a23fd6..1c1b005588fd7e1a8e760dabe43f8a1781856fba 100644 (file)
 /**
  * Class contains functions for phone.
  */
-class CRM_Core_BAO_Phone extends CRM_Core_DAO_Phone {
+class CRM_Core_BAO_Phone extends CRM_Core_DAO_Phone implements Civi\Core\HookInterface {
   use CRM_Contact_AccessTrait;
 
   /**
-   * Create phone object - note that the create function calls 'add' but
-   * has more business logic
+   * @deprecated
    *
    * @param array $params
-   *
-   * @return \CRM_Core_DAO_Phone
-   *
-   * @throws \CRM_Core_Exception
+   * @return CRM_Core_DAO_Phone
+   * @throws CRM_Core_Exception
    */
   public static function create($params) {
-    CRM_Core_BAO_Block::handlePrimary($params, get_class());
+    CRM_Core_Error::deprecatedFunctionWarning('writeRecord');
     return self::writeRecord($params);
   }
 
   /**
-   * Takes an associative array and adds phone.
-   *
-   * @deprecated use create.
+   * Event fired before modifying a Phone.
+   * @param \Civi\Core\Event\PreEvent $event
+   */
+  public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) {
+    if (in_array($event->action, ['create', 'edit'])) {
+      CRM_Core_BAO_Block::handlePrimary($event->params, __CLASS__);
+    }
+  }
+
+  /**
+   * @deprecated
    *
    * @param array $params
-   *   (reference ) an assoc array of name/value pairs.
-   *
-   * @return object
-   *   CRM_Core_BAO_Phone object on success, null otherwise
-   *
+   * @return CRM_Core_DAO_Phone
    * @throws \CRM_Core_Exception
    */
   public static function add($params) {
-    CRM_Core_Error::deprecatedFunctionWarning('Use the v4 api');
     return self::create($params);
   }
 
index 14c740d694fb596c6945408f09bee875db04a917..ab53574edb25684cf7816639be332db6460feeef 100644 (file)
@@ -22,13 +22,11 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website {
   use CRM_Contact_AccessTrait;
 
   /**
-   * Create or update Website record.
+   * @deprecated
    *
    * @param array $params
-   *
-   * @deprecated
    * @return CRM_Core_DAO_Website
-   * @throws \CRM_Core_Exception
+   * @throws CRM_Core_Exception
    */
   public static function create($params) {
     CRM_Core_Error::deprecatedFunctionWarning('writeRecord');
@@ -36,16 +34,14 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website {
   }
 
   /**
-   * Create website.
+   * @deprecated
    *
    * @param array $params
-   *
    * @return CRM_Core_DAO_Website
-   * @throws \CRM_Core_Exception
-   * @deprecated
+   * @throws CRM_Core_Exception
    */
   public static function add($params) {
-    CRM_Core_Error::deprecatedFunctionWarning('use apiv4');
+    CRM_Core_Error::deprecatedFunctionWarning('writeRecord');
     return self::writeRecord($params);
   }
 
index 973254d8cc8f5469fc56107786148ac2a03c539e..180f4f37a457a4f149615f5e9b867d409ca7aeea 100644 (file)
@@ -1373,7 +1373,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase {
           'location_type_id' => 1,
           'contact_id' => $contactId,
         ];
-        CRM_Core_BAO_Phone::create($params);
+        CRM_Core_BAO_Phone::writeRecord($params);
         $test->assertDBQuery('202-555-1000',
           'SELECT phone FROM civicrm_phone WHERE contact_id = %1 ORDER BY id DESC LIMIT 1',
           [1 => [$contactId, 'Integer']]
index 8f0c37d9aa2dfbd6ea9c918601d440e395b1f2a8..bf1a3734e3abe7fb662c7440ea904c855a2d0cbb 100644 (file)
@@ -21,7 +21,6 @@ class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase {
   public function testAdd() {
     $contactId = $this->individualCreate();
 
-    $params = [];
     $params = [
       'phone' => '(415) 222-1011 x 221',
       'is_primary' => 1,
@@ -30,7 +29,7 @@ class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase {
       'contact_id' => $contactId,
     ];
 
-    CRM_Core_BAO_Phone::create($params);
+    CRM_Core_BAO_Phone::writeRecord($params);
 
     $phoneId = $this->assertDBNotNull('CRM_Core_DAO_Phone', $contactId, 'id', 'contact_id',
       'Database check for created phone record.'
@@ -48,7 +47,7 @@ class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase {
       'phone' => '(415) 222-5432',
     ];
 
-    CRM_Core_BAO_Phone::create($params);
+    CRM_Core_BAO_Phone::writeRecord($params);
 
     $this->assertDBCompareValue('CRM_Core_DAO_Phone', $phoneId, 'phone', 'id', '(415) 222-5432',
       "Check if phone field has expected value in updated record ( civicrm_phone.id={$phoneId} )."
@@ -84,11 +83,4 @@ class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase {
     $this->contactDelete($contactId);
   }
 
-  /**
-   * AllEntityPhones() method - get all Phones for a location block, with primary Phone first
-   * @todo FIXME: Fixing this test requires add helper functions in CiviTest to create location block and phone and link them to an event. Punting to 3.1 cycle. DGG
-   */
-  public function SKIPPED_testAllEntityPhones() {
-  }
-
 }