From: eileen Date: Wed, 18 May 2016 23:02:39 +0000 (+1200) Subject: CRM-18504 fix validation error when contact subtype is disabled X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=93ecb8e8666475cd5e2eab355bc9ea592dbecf08;p=civicrm-core.git CRM-18504 fix validation error when contact subtype is disabled --- diff --git a/CRM/Contact/BAO/ContactType.php b/CRM/Contact/BAO/ContactType.php index 48711b11e0..efc0ca1f2c 100644 --- a/CRM/Contact/BAO/ContactType.php +++ b/CRM/Contact/BAO/ContactType.php @@ -74,7 +74,7 @@ class CRM_Contact_BAO_ContactType extends CRM_Contact_DAO_ContactType { * @return array * Array of basic contact types information. */ - public static function &basicTypeInfo($all = FALSE) { + public static function basicTypeInfo($all = FALSE) { static $_cache = NULL; if ($_cache === NULL) { @@ -153,7 +153,7 @@ WHERE parent_id IS NULL * @return array * Array of sub type information */ - public static function &subTypeInfo($contactType = NULL, $all = FALSE, $ignoreCache = FALSE, $reset = FALSE) { + public static function subTypeInfo($contactType = NULL, $all = FALSE, $ignoreCache = FALSE, $reset = FALSE) { static $_cache = NULL; if ($reset === TRUE) { diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index ee953fbff4..bd804af104 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -651,15 +651,13 @@ ORDER BY civicrm_custom_group.weight, if (is_numeric($subType)) { return $subType; } - $contactTypes = civicrm_api3('Contact', 'getoptions', array('field' => 'contact_type')); - if ($entityType != 'Contact' && !array_key_exists($entityType, $contactTypes['values'])) { - // Not quite sure if we want to fail this hard. But quiet ignore would be pretty bad too. - // Am inclined to go with this for RC release & considering softening. + + $contactTypes = CRM_Contact_BAO_ContactType::basicTypeInfo(TRUE); + if ($entityType != 'Contact' && !array_key_exists($entityType, $contactTypes)) { throw new CRM_Core_Exception('Invalid Entity Filter'); } - $subTypes = civicrm_api3('Contact', 'getoptions', array('field' => 'contact_sub_type')); - if (!isset($subTypes['values'][$subType])) { - // Same comments about fail hard as above. + $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo($entityType, TRUE); + if (!array_key_exists($subType, $subTypes)) { throw new CRM_Core_Exception('Invalid Filter'); } return $subType; diff --git a/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php b/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php index c9dd9964bb..03ef858c5a 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php @@ -87,6 +87,20 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType['id'])); } + /** + * Test calling getTree for a custom field extending a disabled contact type. + */ + public function testGetTreeContactSubTypeForDisabledChangedContactType() { + $contactType = $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization')); + $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank'))); + $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'])); + $this->callAPISuccess('ContactType', 'create', array('id' => $contactType['id'], 'is_active' => 0)); + $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Big_Bank')); + $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']); + $this->customGroupDelete($customGroup['id']); + $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType['id'])); + } + /** * Test calling getTree with contact subtype data. *