Fix Group Organization BAO not to error if the unique pairing up group_id & organizat...
authorEileen <eileen@fuzion.co.nz>
Tue, 26 Nov 2013 23:25:28 +0000 (12:25 +1300)
committerEileen <eileen@fuzion.co.nz>
Tue, 26 Nov 2013 23:25:28 +0000 (12:25 +1300)
CRM/Contact/BAO/GroupOrganization.php
api/v3/examples/GroupOrganizationCreate.php
api/v3/examples/GroupOrganizationDelete.php
api/v3/examples/GroupOrganizationGet.php
tests/phpunit/api/v3/GroupOrganizationTest.php

index 294def893faf9f86f5749bde60d505ae32876f51..b10bd0d772f553d7991e4184941d49272212db0e 100644 (file)
@@ -59,6 +59,9 @@ class CRM_Contact_BAO_GroupOrganization extends CRM_Contact_DAO_GroupOrganizatio
     }
     $groupOrganization = new CRM_Contact_DAO_GroupOrganization();
     $groupOrganization->copyValues($formatedValues);
+    // we have ensured we have group_id & organization_id so we can do a find knowing that
+    // this can only find a matching record
+    $groupOrganization->find(TRUE);
     $groupOrganization->save();
     return $groupOrganization;
   }
index a90fe3f51b975fd391461b5879ae0efc40020885..7192ba7ad1f5b5232a6399e60252bb6f709de4f5 100644 (file)
@@ -64,4 +64,4 @@ function group_organization_create_expectedresult(){
 *
 * API Standards documentation:
 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
-*/
\ No newline at end of file
+*/
index bda69751735db3101929468314db3481d6ddcaf8..4599299afcc18473bdb7b324d8f9da6669f5505a 100644 (file)
@@ -58,4 +58,4 @@ function group_organization_delete_expectedresult(){
 *
 * API Standards documentation:
 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
-*/
\ No newline at end of file
+*/
index aab63bb6f84bd78d1f85a4a6a1e001e9c9d5a3e9..5a09a709fc92182ddf1875f16c337cc717f0b46b 100644 (file)
@@ -58,4 +58,4 @@ function group_organization_get_expectedresult(){
 *
 * API Standards documentation:
 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
-*/
\ No newline at end of file
+*/
index 78bf4c24c770ebb04089991289005dd00061ca65..89cbce9a75f421fc9ea03811f93cbda4d1b429b2 100644 (file)
@@ -155,6 +155,17 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase {
     $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__, __FILE__);
   }
 
+  /**
+   * CRM-13841 - Load Group Org before save
+   */
+  public function testGroupOrganizationCreateTwice() {
+    $params = array(
+        'organization_id' => $this->_orgID,
+        'group_id' => $this->_groupID,    );
+    $result = $this->callAPISuccess('group_organization', 'create', $params);
+    $result2 = $this->callAPISuccess('group_organization', 'create', $params);
+    $this->assertEquals($result['values'], $result2['values']);
+  }
   /**
    * check with empty params array
    */