Skip to content

Commit

Permalink
Merge pull request #18588 from eileenmcnaughton/phone
Browse files Browse the repository at this point in the history
dev/core#2046 Fix Phone:add to be a pseudonym for Phone.create
  • Loading branch information
eileenmcnaughton authored Sep 25, 2020
2 parents 64c8be5 + 717c290 commit 97ff3c5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CRM/Core/BAO/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ public static function create($blockName, $params, $entity = NULL, $contactId =
// and the primary handling is otherwise bypassed on importing an email update.
$blocks[] = CRM_Core_BAO_Email::create($blockFields);
}
elseif ($name === 'Phone') {
$blocks[] = CRM_Core_BAO_Phone::create($blockFields);
}
else {
$baoString = 'CRM_Core_BAO_' . $name;
$blocks[] = $baoString::add($blockFields);
Expand Down
17 changes: 9 additions & 8 deletions CRM/Core/BAO/Phone.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,26 @@ public static function create($params) {
) {
CRM_Core_BAO_Block::handlePrimary($params, get_class());
}
$phone = self::add($params);

return $phone;
return self::writeRecord($params);
}

/**
* Takes an associative array and adds phone.
*
* @deprecated use create.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
* @return object
* CRM_Core_BAO_Phone object on success, null otherwise
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public static function add(&$params) {
// Ensure mysql phone function exists
CRM_Core_DAO::checkSqlFunctionsExist();

return self::writeRecord($params);
public static function add($params) {
CRM_Core_Error::deprecatedFunctionWarning('Use the v4 api');
return self::create($params);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Contact/BAO/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ public function testTimestampsPhone() {
'location_type_id' => 1,
'contact_id' => $contactId,
];
CRM_Core_BAO_Phone::add($params);
CRM_Core_BAO_Phone::create($params);
$test->assertDBQuery('202-555-1000',
'SELECT phone FROM civicrm_phone WHERE contact_id = %1 ORDER BY id DESC LIMIT 1',
[1 => [$contactId, 'Integer']]
Expand Down
7 changes: 3 additions & 4 deletions tests/phpunit/CRM/Core/BAO/PhoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testAdd() {
'contact_id' => $contactId,
];

CRM_Core_BAO_Phone::add($params);
CRM_Core_BAO_Phone::create($params);

$phoneId = $this->assertDBNotNull('CRM_Core_DAO_Phone', $contactId, 'id', 'contact_id',
'Database check for created phone record.'
Expand All @@ -44,16 +44,15 @@ public function testAdd() {
"Check if phone field has expected value in new record ( civicrm_phone.id={$phoneId} )."
);

// Now call add() to modify the existing phone number
// Now call create() to modify the existing phone number

$params = [];
$params = [
'id' => $phoneId,
'contact_id' => $contactId,
'phone' => '(415) 222-5432',
];

CRM_Core_BAO_Phone::add($params);
CRM_Core_BAO_Phone::create($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} )."
Expand Down

0 comments on commit 97ff3c5

Please sign in to comment.