-- fixed for CRM-10983, prevent the generation of duplicate custom data.
authordpradeep <pradeep.dorugade@webaccess.co.in>
Wed, 5 Jun 2013 12:32:15 +0000 (18:02 +0530)
committerdpradeep <pradeep.dorugade@webaccess.co.in>
Wed, 5 Jun 2013 12:32:15 +0000 (18:02 +0530)
CRM/Core/BAO/CustomGroup.php
CRM/Custom/Form/CustomData.php
CRM/Event/Form/Participant.php
templates/CRM/Event/Form/Participant.tpl
tests/phpunit/WebTest/Event/AddParticipationTest.php

index 5d4de53dbed215185faa413aaa07d9fe491cd98e..602cb981d12a5dd493d94cb7fc557b417fc60107 100644 (file)
@@ -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 = "
index 1eca7797fa77fe4ee88281cec09bdfffb81971ab..70e4e713d1c7d5efc4a380715dd89fe149255073 100644 (file)
@@ -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)) {
index bc3ea50288abfe4f03a31f4fe2a0885f060a8c2d..b71f3dd55d0650dad682d8b4d15206fb9fcb84d6 100644 (file)
@@ -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
index 1f77e35f77204a06778028cb523aee09aee5e452..2e1d685999a4690a7ac48c3aad21a25768e49d48 100644 (file)
           }
           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( );
index a5cda779ffc5c0e0457815eb30205f9b56abd029..e947d93f682aaf6679f03af92b8b0fab2fec6b70 100644 (file)
@@ -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');