From c30f84f434d6c81b7687c701213be2d42d84269e Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 28 Mar 2023 09:13:33 -0400 Subject: [PATCH] BAO - Deprecate email/im/phone/website/openId create/add functions in favor of writeRecord --- CRM/Core/BAO/Email.php | 8 +++-- CRM/Core/BAO/IM.php | 29 +++++++++------- CRM/Core/BAO/OpenID.php | 28 ++++++++------- CRM/Core/BAO/Phone.php | 34 +++++++++---------- CRM/Core/BAO/Website.php | 14 +++----- tests/phpunit/CRM/Contact/BAO/ContactTest.php | 2 +- tests/phpunit/CRM/Core/BAO/PhoneTest.php | 12 ++----- 7 files changed, 64 insertions(+), 63 deletions(-) diff --git a/CRM/Core/BAO/Email.php b/CRM/Core/BAO/Email.php index 173b697cf9..c35b34d77d 100644 --- a/CRM/Core/BAO/Email.php +++ b/CRM/Core/BAO/Email.php @@ -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'); diff --git a/CRM/Core/BAO/IM.php b/CRM/Core/BAO/IM.php index b1a916c374..a305dab03b 100644 --- a/CRM/Core/BAO/IM.php +++ b/CRM/Core/BAO/IM.php @@ -18,34 +18,39 @@ /** * 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); } diff --git a/CRM/Core/BAO/OpenID.php b/CRM/Core/BAO/OpenID.php index c82a42dfab..df2a04705b 100644 --- a/CRM/Core/BAO/OpenID.php +++ b/CRM/Core/BAO/OpenID.php @@ -18,35 +18,39 @@ /** * 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); } diff --git a/CRM/Core/BAO/Phone.php b/CRM/Core/BAO/Phone.php index cf095fa29a..1c1b005588 100644 --- a/CRM/Core/BAO/Phone.php +++ b/CRM/Core/BAO/Phone.php @@ -18,39 +18,39 @@ /** * 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); } diff --git a/CRM/Core/BAO/Website.php b/CRM/Core/BAO/Website.php index 14c740d694..ab53574edb 100644 --- a/CRM/Core/BAO/Website.php +++ b/CRM/Core/BAO/Website.php @@ -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); } diff --git a/tests/phpunit/CRM/Contact/BAO/ContactTest.php b/tests/phpunit/CRM/Contact/BAO/ContactTest.php index 973254d8cc..180f4f37a4 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactTest.php @@ -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']] diff --git a/tests/phpunit/CRM/Core/BAO/PhoneTest.php b/tests/phpunit/CRM/Core/BAO/PhoneTest.php index 8f0c37d9aa..bf1a3734e3 100644 --- a/tests/phpunit/CRM/Core/BAO/PhoneTest.php +++ b/tests/phpunit/CRM/Core/BAO/PhoneTest.php @@ -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() { - } - } -- 2.25.1