From: dpradeep Date: Wed, 5 Jun 2013 12:32:15 +0000 (+0530) Subject: -- fixed for CRM-10983, prevent the generation of duplicate custom data. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=63dbed83d160dc7a5ae0012bec859a7cc0b28ff6;p=civicrm-core.git -- fixed for CRM-10983, prevent the generation of duplicate custom data. --- diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 5d4de53dbe..602cb981d1 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -311,7 +311,8 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup { $groupID = NULL, $subType = NULL, $subName = NULL, - $fromCache = TRUE + $fromCache = TRUE, + $onlySubType = NULL ) { if ($entityID) { $entityID = CRM_Utils_Type::escape($entityID, 'Integer'); @@ -401,13 +402,24 @@ LEFT JOIN civicrm_custom_field ON (civicrm_custom_field.custom_group_id = civicr $subTypePart = CRM_Core_DAO::VALUE_SEPARATOR . trim($subTypePart, CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR; $subTypeClauses[] = "civicrm_custom_group.extends_entity_column_value LIKE '%$subTypePart%'"; } - $subTypeClause = '(' . implode(' OR ', $subTypeClauses) . " OR civicrm_custom_group.extends_entity_column_value IS NULL )"; + + if ($onlySubType) { + $subTypeClause = '(' . implode(' OR ', $subTypeClauses) . ')'; + } + else { + $subTypeClause = '(' . implode(' OR ', $subTypeClauses) . " OR civicrm_custom_group.extends_entity_column_value IS NULL )"; + } } else { $subType = CRM_Core_DAO::VALUE_SEPARATOR . trim($subType, CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR; - $subTypeClause = "( civicrm_custom_group.extends_entity_column_value LIKE '%$subType%' - OR civicrm_custom_group.extends_entity_column_value IS NULL )"; + if ($onlySubType) { + $subTypeClause = "( civicrm_custom_group.extends_entity_column_value LIKE '%$subType%' )"; + } + else { + $subTypeClause = "( civicrm_custom_group.extends_entity_column_value LIKE '%$subType%' + OR civicrm_custom_group.extends_entity_column_value IS NULL )"; + } } $strWhere = " diff --git a/CRM/Custom/Form/CustomData.php b/CRM/Custom/Form/CustomData.php index 1eca7797fa..70e4e713d1 100644 --- a/CRM/Custom/Form/CustomData.php +++ b/CRM/Custom/Form/CustomData.php @@ -48,7 +48,7 @@ class CRM_Custom_Form_CustomData { * @return void */ static function preProcess(&$form, $subName = NULL, $subType = NULL, - $groupCount = NULL, $type = NULL, $entityID = NULL + $groupCount = NULL, $type = NULL, $entityID = NULL, $onlySubType = NULL ) { if ($type) { $form->_type = $type; @@ -122,7 +122,8 @@ class CRM_Custom_Form_CustomData { $gid, $subType, $form->_subName, - $getCachedTree + $getCachedTree, + $onlySubType ); if (property_exists($form, '_customValueCount') && !empty($groupTree)) { diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index bc3ea50288..b71f3dd55d 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -321,7 +321,7 @@ class CRM_Event_Form_Participant extends CRM_Contact_Form_Task { $this->assign('cdType', FALSE); if ($this->_cdType) { $this->assign('cdType', TRUE); - return CRM_Custom_Form_CustomData::preProcess($this); + return CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, NULL, NULL, NULL, TRUE); } //check the mode when this form is called either single or as diff --git a/templates/CRM/Event/Form/Participant.tpl b/templates/CRM/Event/Form/Participant.tpl index 1f77e35f77..2e1d685999 100644 --- a/templates/CRM/Event/Form/Participant.tpl +++ b/templates/CRM/Event/Form/Participant.tpl @@ -442,16 +442,6 @@ } loadData = true; } - - if ( loadData && roleGroupMapper[0] ) { - var splitGroup = roleGroupMapper[0].split(","); - for ( i = 0; i < splitGroup.length; i++ ) { - var roleCustomGroupId = splitGroup[i]; - if ( cj( '#'+roleCustomGroupId ).length > 0 ) { - cj( '#'+roleCustomGroupId ).remove( ); - } - } - } } else { var groupUnload = new Array( ); diff --git a/tests/phpunit/WebTest/Event/AddParticipationTest.php b/tests/phpunit/WebTest/Event/AddParticipationTest.php index a5cda779ff..e947d93f68 100644 --- a/tests/phpunit/WebTest/Event/AddParticipationTest.php +++ b/tests/phpunit/WebTest/Event/AddParticipationTest.php @@ -384,6 +384,43 @@ class WebTest_Event_AddParticipationTest extends CiviSeleniumTestCase { $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); } + /* + * Webtest for CRM-10983 + * + */ + function testCheckDuplicateCustomDataLoad() { + $this->webtestLogin(); + + $customSets = array( + array('entity' => 'ParticipantEventType', 'subEntity' => '- Any -', + 'triggerElement' => array('name' => "event_id", 'type' => "select")), + array('entity' => 'ParticipantEventName', 'subEntity' => '- Any -', + 'triggerElement' => array('name' => "event_id", 'type' => "select")), + array('entity' => 'ParticipantEventName', 'subEntity' => 'Rain-forest Cup Youth Soccer Tournament', + 'triggerElement' => array('name' => "event_id", 'type' => "select")), + array('entity' => 'ParticipantRole', 'subEntity' => '- Any -','triggerElement' => array('type' => "checkbox")), + array('entity' => 'ParticipantRole', 'subEntity' => 'Volunteer','triggerElement' => array('type' => "checkbox")) + ); + + $return = $this->addCustomGroupField($customSets); + + $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom"); + + // Select event. + $this->select('event_id', "label=regexp:Rain-forest Cup Youth Soccer Tournament."); + + // Select role. + $this->click('role_id[2]'); + + foreach($return as $values) { + foreach ($values as $entityType => $customData) { + //checking for duplicate custom data present or not + $this->assertElementPresent("xpath=//div[@id='{$customData['cgtitle']}'][@class='crm-accordion-wrapper ']"); + $this->assertEquals(1, $this->getXpathCount("//div[@id='{$customData['cgtitle']}'][@class='crm-accordion-wrapper ']")); + } + } + } + function _fillParticipantDetails($firstName, $lastName, $processorId) { $this->select("id=profiles_1", "label=New Individual"); $this->waitForElementPresent('_qf_Edit_next');