CRM-17306 fix location update action
authoreileenmcnaugton <eileen@fuzion.co.nz>
Wed, 30 Sep 2015 00:21:46 +0000 (13:21 +1300)
committereileenmcnaugton <eileen@fuzion.co.nz>
Wed, 30 Sep 2015 00:23:21 +0000 (13:23 +1300)
Conflicts:
tests/phpunit/api/v3/SyntaxConformanceTest.php

 Please enter the commit message for your changes. Lines starting

CRM/Core/BAO/LocationType.php
tests/phpunit/api/v3/SyntaxConformanceTest.php

index 9a87b7bf7da041f5bc9b41a52c715276e27314dc..4a00bd8d8100a7e7eb558e468f04d6a1adae8f62 100644 (file)
@@ -123,15 +123,15 @@ class CRM_Core_BAO_LocationType extends CRM_Core_DAO_LocationType {
    * @return object
    */
   public static function create(&$params) {
-    $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
-    $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
-    $params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
+    if (empty($params['id'])) {
+      $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
+      $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
+      $params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
+    }
 
-    // action is taken depending upon the mode
     $locationType = new CRM_Core_DAO_LocationType();
     $locationType->copyValues($params);
-
-    if ($params['is_default']) {
+    if (!empty($params['is_default'])) {
       $query = "UPDATE civicrm_location_type SET is_default = 0";
       CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     }
index 9308064d271fb1386ff5da514ddeb1bfc315fb2e..aa403ce360853ccc1d6675301c351cbc46df84bf 100644 (file)
@@ -101,7 +101,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       'OptionGroup',
       'MailingRecipients',
       'UFMatch',
-      'LocationType',
       'CustomSearch',
       'Extension',
       'ReportTemplate',
@@ -118,7 +117,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       'UFJoin',
       'UFMatch',
       'Extension',
-      'LocationType',
       'System',
     );
     $this->onlyIDNonZeroCount['get'] = array(
@@ -565,6 +563,15 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
           'pcp_id',
         ),
       ),
+      'LocationType' => array(
+        'cant_update' => array(
+          // I'm on the fence about whether the test should skip or the behaviour is wrong.
+          // display_name is set to match name if display_name is not provided. It would be more 'normal'
+          // to only calculate a default IF id is not set - but perhaps the current behaviour is kind
+          // of what someone updating the name expects..
+          'name',
+        ),
+      ),
       'Pledge' => array(
         'cant_update' => array(
           'pledge_original_installment_amount',