diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index b1971d2add56..04e96089834f 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -1663,7 +1663,7 @@ public static function getContributionDetails($exportMode, $componentIds) { public static function createAddress($params, $billingLocationTypeID) { [$hasBillingField, $addressParams] = self::getBillingAddressParams($params, $billingLocationTypeID); if ($hasBillingField) { - $address = CRM_Core_BAO_Address::add($addressParams, FALSE); + $address = CRM_Core_BAO_Address::writeRecord($addressParams); return $address->id; } return NULL; diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index 004922b0d345..909b4e607fb8 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -20,96 +20,70 @@ /** * This is class to handle address related functions. */ -class CRM_Core_BAO_Address extends CRM_Core_DAO_Address { +class CRM_Core_BAO_Address extends CRM_Core_DAO_Address implements Civi\Core\HookInterface { use CRM_Contact_AccessTrait; /** - * Takes an associative array and creates a address. + * @deprecated * * @param array $params - * (reference ) an assoc array of name/value pairs. * @param bool $fixAddress - * True if you need to fix (format) address values. - * before inserting in db - * - * @return array|NULL|self - * array of created address + * @return CRM_Core_BAO_Address + * @throws CRM_Core_Exception */ public static function create(array &$params, $fixAddress = TRUE) { - return self::add($params, $fixAddress); + CRM_Core_Error::deprecatedFunctionWarning('writeRecord'); + if ($fixAddress) { + CRM_Core_BAO_Address::fixAddress($params); + } + return self::writeRecord($params); } /** - * Takes an associative array and adds address. + * @deprecated * * @param array $params - * (reference ) an assoc array of name/value pairs. * @param bool $fixAddress - * True if you need to fix (format) address values. - * before inserting in db - * - * @return CRM_Core_BAO_Address|null + * @return CRM_Core_BAO_Address + * @throws CRM_Core_Exception */ public static function add(&$params, $fixAddress = FALSE) { + return self::create($params, $fixAddress); + } - $address = new CRM_Core_DAO_Address(); - $checkPermissions = $params['check_permissions'] ?? TRUE; - - // fixAddress mode to be done - if ($fixAddress) { - CRM_Core_BAO_Address::fixAddress($params); - } - - $hook = empty($params['id']) ? 'create' : 'edit'; - CRM_Utils_Hook::pre($hook, 'Address', CRM_Utils_Array::value('id', $params), $params); - - CRM_Core_BAO_Block::handlePrimary($params, get_class()); - CRM_Core_BAO_Block::handleBilling($params, get_class()); - - // (prevent chaining 1 and 3) CRM-21214 - if (isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) { - self::fixSharedAddress($params); - } - - $address->copyValues($params); - $address->save(); - - if ($address->id) { - // first get custom field from master address if any - if (isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) { - $address->copyCustomFields($params['master_id'], $address->id, $hook); + /** + * Event fired before modifying an Address. + * @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__); + CRM_Core_BAO_Block::handleBilling($event->params, __CLASS__); + + // (prevent chaining 1 and 3) CRM-21214 + if (isset($event->params['master_id']) && !CRM_Utils_System::isNull($event->params['master_id'])) { + self::fixSharedAddress($event->params); } + } + } - if (isset($params['custom'])) { - $addressCustom = $params['custom']; - } - else { - $customFields = CRM_Core_BAO_CustomField::getFields('Address', FALSE, TRUE, NULL, NULL, - FALSE, FALSE, $checkPermissions ? CRM_Core_Permission::EDIT : FALSE); - - if (!empty($customFields)) { - $addressCustom = CRM_Core_BAO_CustomField::postProcess($params, - $address->id, - 'Address', - FALSE, - $checkPermissions - ); - } - } - if (!empty($addressCustom)) { - CRM_Core_BAO_CustomValueTable::store($addressCustom, 'civicrm_address', $address->id, $hook); + /** + * Event fired after modifying an Address. + * @param \Civi\Core\Event\PostEvent $event + */ + public static function self_hook_civicrm_post(\Civi\Core\Event\PostEvent $event) { + // Copy custom data from master address if not supplied + if ($event->action === 'create' && !isset($event->params['custom'])) { + if (isset($event->params['master_id']) && !CRM_Utils_System::isNull($event->params['master_id'])) { + $event->object->copyCustomFields($event->params['master_id'], $event->id, $event->action); } - + } + if (in_array($event->action, ['create', 'edit'])) { // call the function to sync shared address and create relationships // if address is already shared, share master_id with all children and update relationships accordingly // (prevent chaining 2) CRM-21214 - self::processSharedAddress($address->id, $params, $hook); - - // lets call the post hook only after we've done all the follow on processing - CRM_Utils_Hook::post($hook, 'Address', $address->id, $address); + self::processSharedAddress($event->id, $event->params, $event->action); } - - return $address; } /** @@ -1336,7 +1310,6 @@ public static function legacyCreate(array $params, bool $fixAddress) { return NULL; } CRM_Core_BAO_Block::sortPrimaryFirst($params['address']); - $contactId = NULL; $updateBlankLocInfo = CRM_Utils_Array::value('updateBlankLocInfo', $params, FALSE); $contactId = $params['contact_id']; @@ -1386,7 +1359,17 @@ public static function legacyCreate(array $params, bool $fixAddress) { $value['manual_geo_code'] = 0; } $value['contact_id'] = $contactId; - $blocks[] = self::add($value, $fixAddress); + + if ($fixAddress) { + self::fixAddress($value); + } + + // Format custom data + if (!isset($value['custom'])) { + $value['custom'] = CRM_Core_BAO_CustomField::postProcess($value, $value['id'] ?? NULL, 'Address'); + } + + $blocks[] = self::writeRecord($value); } return $blocks; } diff --git a/CRM/Core/BAO/Block.php b/CRM/Core/BAO/Block.php index 506e9515763b..a5abbe73c827 100644 --- a/CRM/Core/BAO/Block.php +++ b/CRM/Core/BAO/Block.php @@ -282,7 +282,10 @@ public static function create($blockName, $params) { } $blockFields = array_merge($value, $contactFields); - $blocks[] = $baoString::create($blockFields); + if ($baoString === 'CRM_Core_BAO_Address') { + CRM_Core_BAO_Address::fixAddress($blockFields); + } + $blocks[] = $baoString::writeRecord($blockFields); } return $blocks; diff --git a/CRM/Core/BAO/Email.php b/CRM/Core/BAO/Email.php index 173b697cf9e5..c35b34d77d71 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 @@ public static function create($params) { */ 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 @@ public static function self_hook_civicrm_post(\Civi\Core\Event\PostEvent $event) /** * @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 b1a916c374d3..a305dab03b74 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 c82a42dfabef..df2a04705bf5 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 cf095fa29a6d..1c1b005588fd 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 14c740d694fb..ab53574edb25 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 @@ public static function create($params) { } /** - * 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/CRM/Event/Form/ManageEvent/Location.php b/CRM/Event/Form/ManageEvent/Location.php index 5d7be182ea92..cc41a4447fbc 100644 --- a/CRM/Event/Form/ManageEvent/Location.php +++ b/CRM/Event/Form/ManageEvent/Location.php @@ -13,7 +13,6 @@ use Civi\Api4\LocBlock; use Civi\Api4\Email; use Civi\Api4\Phone; -use Civi\Api4\Address; /** * @@ -331,8 +330,15 @@ public function postProcess() { } - // Update the Blocks. - $addresses = empty($params['address']) ? [] : Address::save(FALSE)->setRecords($params['address'])->execute(); + // Update location Blocks. + $addresses = []; + // Don't use APIv4 for address because it doesn't handle custom fields in the format used by this form (custom_xx) + foreach ($params['address'] ?? [] as $address) { + CRM_Core_BAO_Address::fixAddress($address); + $address['custom'] = CRM_Core_BAO_CustomField::postProcess($address, $address['id'] ?? NULL, 'Address'); + $addresses[] = (array) CRM_Core_BAO_Address::writeRecord($address); + } + // Using APIv4 for email & phone, the form doesn't support custom data for them anyway $emails = empty($params['email']) ? [] : Email::save(FALSE)->setRecords($params['email'])->execute(); $phones = empty($params['phone']) ? [] : Phone::save(FALSE)->setRecords($params['phone'])->execute(); diff --git a/Civi/Api4/Action/Address/AddressSaveTrait.php b/Civi/Api4/Action/Address/AddressSaveTrait.php index d14fca6a1d99..3759e978ed34 100644 --- a/Civi/Api4/Action/Address/AddressSaveTrait.php +++ b/Civi/Api4/Action/Address/AddressSaveTrait.php @@ -55,7 +55,10 @@ protected function write(array $items) { $item = array_merge($item, \CRM_Core_BAO_Address::parseStreetAddress($item['street_address'])); } $item['skip_geocode'] = $this->skipGeocode; - $saved[] = \CRM_Core_BAO_Address::add($item, $this->fixAddress); + if ($this->fixAddress) { + \CRM_Core_BAO_Address::fixAddress($item); + } + $saved[] = \CRM_Core_BAO_Address::writeRecord($item); } return $saved; } diff --git a/Civi/Test/Api3TestTrait.php b/Civi/Test/Api3TestTrait.php index 49d81e97b435..e00452ab9749 100644 --- a/Civi/Test/Api3TestTrait.php +++ b/Civi/Test/Api3TestTrait.php @@ -428,6 +428,11 @@ public function runApi4Legacy($v3Entity, $v3Action, $v3Params = []) { if ($v4Entity != 'Setting' && !in_array('id', $v4Params['select'])) { $v4Params['select'][] = 'id'; } + // Convert 'custom' to 'custom.*' + $selectCustom = array_search('custom', $v4Params['select']); + if ($selectCustom !== FALSE) { + $v4Params['select'][$selectCustom] = 'custom.*'; + } } if ($options['limit'] && $v4Entity != 'Setting') { $v4Params['limit'] = $options['limit']; diff --git a/api/v3/Address.php b/api/v3/Address.php index f7988a249ae0..dd74c46c11b8 100644 --- a/api/v3/Address.php +++ b/api/v3/Address.php @@ -60,22 +60,11 @@ function civicrm_api3_address_create($params) { $params['check_permissions'] = 0; } - if (!isset($params['fix_address'])) { - $params['fix_address'] = TRUE; + if (!isset($params['fix_address']) || $params['fix_address']) { + CRM_Core_BAO_Address::fixAddress($params); } - /** - * Create array for BAO (expects address params in as an - * element in array 'address' - */ - $addressBAO = CRM_Core_BAO_Address::create($params, $params['fix_address']); - if (empty($addressBAO)) { - return civicrm_api3_create_error("Address is not created or updated "); - } - else { - $values = _civicrm_api3_dao_to_array($addressBAO, $params); - return civicrm_api3_create_success($values, $params, 'Address', $addressBAO); - } + return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Address'); } /** diff --git a/tests/phpunit/CRM/Contact/BAO/ContactTest.php b/tests/phpunit/CRM/Contact/BAO/ContactTest.php index 973254d8cc8f..e553e538445a 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactTest.php @@ -1373,7 +1373,7 @@ public function testTimestampsPhone() { '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']] @@ -1565,7 +1565,7 @@ public function testSharedAddressCopiesAllAddressFields() { 'is_billing' => 1, 'state_province_id' => '3934', ]; - $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE); + $addAddressA = CRM_Core_BAO_Address::writeRecord($addressParamsA); $addressParamsB[1] = [ 'contact_id' => $contactIdB, @@ -1574,7 +1574,7 @@ public function testSharedAddressCopiesAllAddressFields() { ]; CRM_Contact_BAO_Contact_Utils::processSharedAddress($addressParamsB); - $addAddressB = CRM_Core_BAO_Address::add($addressParamsB[1], FALSE); + $addAddressB = CRM_Core_BAO_Address::writeRecord($addressParamsB[1]); foreach ($addAddressA as $key => $value) { if (!in_array($key, ['id', 'contact_id', 'master_id', 'is_primary', 'is_billing', 'location_type_id', 'manual_geo_code'])) { diff --git a/tests/phpunit/CRM/Core/BAO/AddressTest.php b/tests/phpunit/CRM/Core/BAO/AddressTest.php index e1c573bf8f0a..5780a6c0a968 100644 --- a/tests/phpunit/CRM/Core/BAO/AddressTest.php +++ b/tests/phpunit/CRM/Core/BAO/AddressTest.php @@ -112,7 +112,8 @@ public function testAdd() { 'contact_id' => $contactId, ]; - $addAddress = CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE); + CRM_Core_BAO_Address::fixAddress($fixParams); + $addAddress = CRM_Core_BAO_Address::writeRecord($fixParams); $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id', 'Database check for created contact address.' @@ -216,7 +217,8 @@ public function testMultipleBillingAddressesCurrentmode() { 'contact_id' => $contactId, ]; - CRM_Core_BAO_Address::add($params['address']['1'], $fixAddress = TRUE); + CRM_Core_BAO_Address::fixAddress($params['address']['1']); + CRM_Core_BAO_Address::writeRecord($params['address']['1']); // Add address 2 $params['address']['2'] = [ @@ -236,7 +238,8 @@ public function testMultipleBillingAddressesCurrentmode() { 'contact_id' => $contactId, ]; - CRM_Core_BAO_Address::add($params['address']['2'], $fixAddress = TRUE); + CRM_Core_BAO_Address::fixAddress($params['address']['2']); + CRM_Core_BAO_Address::writeRecord($params['address']['2']); $addresses = CRM_Core_BAO_Address::getValues($entityBlock); @@ -281,7 +284,8 @@ public function testallAddress() { 'contact_id' => $contactId, ]; - CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE); + CRM_Core_BAO_Address::fixAddress($fixParams); + CRM_Core_BAO_Address::writeRecord($fixParams); $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id', 'Database check for created contact address.' @@ -304,7 +308,8 @@ public function testallAddress() { 'contact_id' => $contactId, ]; - CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE); + CRM_Core_BAO_Address::fixAddress($fixParams); + CRM_Core_BAO_Address::writeRecord($fixParams); $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id', 'Database check for created contact address.' @@ -341,7 +346,8 @@ public function testnullallAddress() { 'contact_id' => $contactId, ]; - CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE); + CRM_Core_BAO_Address::fixAddress($fixParams); + CRM_Core_BAO_Address::writeRecord($fixParams); $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id', 'Database check for created contact address.' @@ -585,7 +591,7 @@ public function testSharedAddressChaining1() { 'is_primary' => '1', 'contact_id' => $contactIdA, ]; - $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE); + $addAddressA = CRM_Core_BAO_Address::writeRecord($addressParamsA); $addressParamsB = [ 'street_address' => '123 Fake St.', @@ -594,7 +600,7 @@ public function testSharedAddressChaining1() { 'master_id' => $addAddressA->id, 'contact_id' => $contactIdB, ]; - $addAddressB = CRM_Core_BAO_Address::add($addressParamsB, FALSE); + $addAddressB = CRM_Core_BAO_Address::writeRecord($addressParamsB); $addressParamsC = [ 'street_address' => '123 Fake St.', @@ -603,7 +609,7 @@ public function testSharedAddressChaining1() { 'master_id' => $addAddressB->id, 'contact_id' => $contactIdC, ]; - $addAddressC = CRM_Core_BAO_Address::add($addressParamsC, FALSE); + $addAddressC = CRM_Core_BAO_Address::writeRecord($addressParamsC); $updatedAddressParamsA = [ 'id' => $addAddressA->id, @@ -612,7 +618,7 @@ public function testSharedAddressChaining1() { 'is_primary' => '1', 'contact_id' => $contactIdA, ]; - $updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE); + $updatedAddressA = CRM_Core_BAO_Address::writeRecord($updatedAddressParamsA); // CRM-21214 - Has Address C been updated with Address A's new values? $newAddressC = new CRM_Core_DAO_Address(); @@ -645,7 +651,7 @@ public function testSharedAddressChaining2() { 'is_primary' => '1', 'contact_id' => $contactIdA, ]; - $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE); + $addAddressA = CRM_Core_BAO_Address::writeRecord($addressParamsA); $addressParamsB = [ 'street_address' => '123 Fake St.', @@ -653,7 +659,7 @@ public function testSharedAddressChaining2() { 'is_primary' => '1', 'contact_id' => $contactIdB, ]; - $addAddressB = CRM_Core_BAO_Address::add($addressParamsB, FALSE); + $addAddressB = CRM_Core_BAO_Address::writeRecord($addressParamsB); $addressParamsC = [ 'street_address' => '123 Fake St.', @@ -662,7 +668,7 @@ public function testSharedAddressChaining2() { 'master_id' => $addAddressA->id, 'contact_id' => $contactIdC, ]; - $addAddressC = CRM_Core_BAO_Address::add($addressParamsC, FALSE); + $addAddressC = CRM_Core_BAO_Address::writeRecord($addressParamsC); $updatedAddressParamsA = [ 'id' => $addAddressA->id, @@ -672,7 +678,7 @@ public function testSharedAddressChaining2() { 'master_id' => $addAddressB->id, 'contact_id' => $contactIdA, ]; - $updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE); + $updatedAddressA = CRM_Core_BAO_Address::writeRecord($updatedAddressParamsA); $updatedAddressParamsB = [ 'id' => $addAddressB->id, @@ -681,7 +687,7 @@ public function testSharedAddressChaining2() { 'is_primary' => '1', 'contact_id' => $contactIdB, ]; - $updatedAddressB = CRM_Core_BAO_Address::add($updatedAddressParamsB, FALSE); + $updatedAddressB = CRM_Core_BAO_Address::writeRecord($updatedAddressParamsB); // CRM-21214 - Has Address C been updated with Address B's new values? $newAddressC = new CRM_Core_DAO_Address(); @@ -709,7 +715,7 @@ public function testSharedAddressChaining3() { 'is_primary' => '1', 'contact_id' => $contactIdA, ]; - $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE); + $addAddressA = CRM_Core_BAO_Address::writeRecord($addressParamsA); $updatedAddressParamsA = [ 'id' => $addAddressA->id, @@ -719,7 +725,7 @@ public function testSharedAddressChaining3() { 'master_id' => $addAddressA->id, 'contact_id' => $contactIdA, ]; - $updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE); + $updatedAddressA = CRM_Core_BAO_Address::writeRecord($updatedAddressParamsA); // CRM-21214 - AdressA shouldn't be master of itself. $this->assertEmpty($updatedAddressA->master_id); @@ -746,8 +752,9 @@ public function testSharedAddressCustomField() { 'contact_id' => $contactIdA, $customField => 'this is a custom text field', ]; + $addressParamsA['custom'] = CRM_Core_BAO_CustomField::postProcess($addressParamsA, NULL, 'Address'); - $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE); + $addAddressA = CRM_Core_BAO_Address::writeRecord($addressParamsA); // without having the custom field, we should still copy the values from master $addressParamsB = [ @@ -757,7 +764,7 @@ public function testSharedAddressCustomField() { 'master_id' => $addAddressA->id, 'contact_id' => $contactIdB, ]; - $addAddressB = CRM_Core_BAO_Address::add($addressParamsB, FALSE); + $addAddressB = CRM_Core_BAO_Address::writeRecord($addressParamsB); // 1. check if the custom fields values have been copied from master to shared address $address = $this->callAPISuccessGetSingle('Address', ['id' => $addAddressB->id, 'return' => $this->getCustomFieldName('text')]); @@ -766,7 +773,8 @@ public function testSharedAddressCustomField() { // 2. now, we update addressA custom field to see if it goes into addressB $addressParamsA['id'] = $addAddressA->id; $addressParamsA[$customField] = 'updated custom text field'; - $addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE); + $addressParamsA['custom'] = CRM_Core_BAO_CustomField::postProcess($addressParamsA, NULL, 'Address'); + CRM_Core_BAO_Address::writeRecord($addressParamsA); $address = $this->callAPISuccessGetSingle('Address', ['id' => $addAddressB->id, 'return' => $this->getCustomFieldName('text')]); $this->assertEquals($addressParamsA[$customField], $address[$customField]); @@ -846,7 +854,8 @@ public function testLongGeocodes() { 'contact_id' => $contactId, ]; - $addAddress = CRM_Core_BAO_Address::add($fixParams, TRUE); + CRM_Core_BAO_Address::fixAddress($fixParams); + $addAddress = CRM_Core_BAO_Address::writeRecord($fixParams); $addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id', 'Database check for created contact address.' diff --git a/tests/phpunit/CRM/Core/BAO/PhoneTest.php b/tests/phpunit/CRM/Core/BAO/PhoneTest.php index 8f0c37d9aa2d..bf1a3734e3ab 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 @@ public function testAdd() { '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 @@ public function testAdd() { '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 @@ public function testAllPhones() { $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() { - } - } diff --git a/tests/phpunit/api/v3/AddressTest.php b/tests/phpunit/api/v3/AddressTest.php index 6ea58248e58b..271628ae418a 100644 --- a/tests/phpunit/api/v3/AddressTest.php +++ b/tests/phpunit/api/v3/AddressTest.php @@ -375,9 +375,11 @@ public function testGetAddressLikeFail($version) { } /** - * FIXME: Api4 custom address fields broken? + * @param int $version + * @dataProvider versionThreeAndFour */ - public function testGetWithCustom() { + public function testGetWithCustom($version) { + $this->_apiversion = $version; $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); $params = $this->_params; diff --git a/tests/phpunit/api/v3/PaymentTest.php b/tests/phpunit/api/v3/PaymentTest.php index 446c5822e129..5e407b29934a 100644 --- a/tests/phpunit/api/v3/PaymentTest.php +++ b/tests/phpunit/api/v3/PaymentTest.php @@ -1184,7 +1184,7 @@ protected function addLocationToEvent(int $eventID): void { 'is_primary' => 1, ]; // api requires contact_id - perhaps incorrectly but use add to get past that. - $address = CRM_Core_BAO_Address::add($addressParams); + $address = CRM_Core_BAO_Address::writeRecord($addressParams); $location = $this->callAPISuccess('LocBlock', 'create', ['address_id' => $address->id]); $this->callAPISuccess('Event', 'create', [