From 048fa8d62866b6cc27dc35f7664bb21b8a288bc2 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Sun, 15 Jul 2018 12:03:26 +0100 Subject: [PATCH] Don't overwrite Product parameters on update --- CRM/Contribute/BAO/Product.php | 27 ++++++++++++------- .../phpunit/api/v3/SyntaxConformanceTest.php | 8 ++++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/CRM/Contribute/BAO/Product.php b/CRM/Contribute/BAO/Product.php index 4ef558ccda..05108e0d53 100644 --- a/CRM/Contribute/BAO/Product.php +++ b/CRM/Contribute/BAO/Product.php @@ -96,19 +96,26 @@ class CRM_Contribute_BAO_Product extends CRM_Contribute_DAO_Product { */ public static function add(&$params, $ids) { $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('premium', $ids)); - $params = array_merge(array( - 'id' => $id, - 'image' => '', - 'thumbnail' => '', - 'is_active' => 0, - 'is_deductible' => FALSE, - 'currency' => CRM_Core_Config::singleton()->defaultCurrency, - ), $params); + if (empty($id)) { + $defaultParams = [ + 'id' => $id, + 'image' => '', + 'thumbnail' => '', + 'is_active' => 0, + 'is_deductible' => FALSE, + 'currency' => CRM_Core_Config::singleton()->defaultCurrency, + ]; + $params = array_merge($defaultParams, $params); + } // Modify the submitted values for 'image' and 'thumbnail' so that we use // local URLs for these images when possible. - $params['image'] = CRM_Utils_String::simplifyURL($params['image'], TRUE); - $params['thumbnail'] = CRM_Utils_String::simplifyURL($params['thumbnail'], TRUE); + if (isset($params['image'])) { + $params['image'] = CRM_Utils_String::simplifyURL($params['image'], TRUE); + } + if (isset($params['thumbnail'])) { + $params['thumbnail'] = CRM_Utils_String::simplifyURL($params['thumbnail'], TRUE); + } // Save and return $premium = new CRM_Contribute_DAO_Product(); diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index 3174cc7617..62202dc02b 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -1436,6 +1436,14 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { //api has special handling on these 2 fields for backward compatibility reasons $entity['next_sched_contribution'] = $updateParams['next_sched_contribution_date']; } + if (isset($updateParams['image'])) { + // Image field is passed through simplifyURL function so may be different, do the same here for comparison + $entity['image'] = CRM_Utils_String::simplifyURL($updateParams['image'], TRUE); + } + if (isset($updateParams['thumbnail'])) { + // Thumbnail field is passed through simplifyURL function so may be different, do the same here for comparison + $entity['thumbnail'] = CRM_Utils_String::simplifyURL($updateParams['thumbnail'], TRUE); + } $update = $this->callAPISuccess($entityName, 'create', $updateParams); $checkParams = array( -- 2.25.1