Skip to content

Commit

Permalink
CRM-21258 support long display names.
Browse files Browse the repository at this point in the history
Gracefully truncate rather than hard-error if calculated field exceeds DB chars
  • Loading branch information
eileenmcnaughton committed Oct 4, 2017
1 parent a60be93 commit 3628dc8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ public static function add(&$params) {
$contact->display_name = $contact->sort_name = CRM_Utils_Array::value('organization_name', $params, '');
}
}
if (strlen($contact->display_name) > 128) {
$contact->display_name = substr($contact->display_name, 0, 128);
}
if (strlen($contact->sort_name) > 128) {
$contact->sort_name = substr($contact->sort_name, 0, 128);
}

$privacy = CRM_Utils_Array::value('privacy', $params);
if ($privacy &&
Expand Down
15 changes: 15 additions & 0 deletions tests/phpunit/api/v3/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2360,6 +2360,21 @@ public function testContactCreateFormatIsSuccessFalse() {
$this->assertEquals(0, $result);
}

/**
* Test long display names.
*
* CRM-21258
*/
public function testContactCreateLongDisplayName() {
$result = $this->callAPISuccess('Contact', 'Create', array(
'first_name' => str_pad('a', 64, 'a'),
'last_name' => str_pad('a', 64, 'a'),
'contact_type' => 'Individual',
));
$this->assertEquals('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', $result['values'][$result['id']]['display_name']);
$this->assertEquals('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', $result['values'][$result['id']]['sort_name']);
}

/**
* Test Single Entity format.
*/
Expand Down

0 comments on commit 3628dc8

Please sign in to comment.