From 89e61d6f7af993a0676cfaaaf07122de4176eee8 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 8 Jun 2018 13:35:57 +1200 Subject: [PATCH 1/2] core/#170 minimal fix for fatal on soft_credit field --- CRM/Report/Form/Contribute/Detail.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRM/Report/Form/Contribute/Detail.php b/CRM/Report/Form/Contribute/Detail.php index 30bac4767173..7910fa1453c5 100644 --- a/CRM/Report/Form/Contribute/Detail.php +++ b/CRM/Report/Form/Contribute/Detail.php @@ -717,7 +717,7 @@ public function alterDisplay(&$rows) { array_key_exists('civicrm_contribution_contribution_id', $row) ) { $query = " -SELECT civicrm_contact_id, civicrm_contact_sort_name, civicrm_contribution_total_amount, civicrm_contribution_currency +SELECT civicrm_contact_id, civicrm_contact_sort_name, civicrm_contribution_total_amount_sum, civicrm_contribution_currency FROM civireport_contribution_detail_temp2 WHERE civicrm_contribution_contribution_id={$row['civicrm_contribution_contribution_id']}"; $this->addToDeveloperTab($query); @@ -729,7 +729,7 @@ public function alterDisplay(&$rows) { $dao->civicrm_contact_id); $string = $string . ($string ? $separator : '') . "{$dao->civicrm_contact_sort_name} " . - CRM_Utils_Money::format($dao->civicrm_contribution_total_amount, $dao->civicrm_contribution_currency); + CRM_Utils_Money::format($dao->civicrm_contribution_total_amount_sum, $dao->civicrm_contribution_currency); } $rows[$rowNum]['civicrm_contribution_soft_credits'] = $string; } From c17dff4c7af5aa0a6cbc805b0d291b3867e587f2 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 10 Jun 2018 15:41:42 -0400 Subject: [PATCH 2/2] Improve CRM_Utils_Array::recursiveBuild to work with existing arrays. --- CRM/Utils/Array.php | 16 ++++++++++++++-- tests/phpunit/CRM/Utils/ArrayTest.php | 14 ++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CRM/Utils/Array.php b/CRM/Utils/Array.php index f4938febf89b..a9d6cdd07ef5 100644 --- a/CRM/Utils/Array.php +++ b/CRM/Utils/Array.php @@ -1205,12 +1205,24 @@ public static function recursiveValue($array, $path, $default = NULL) { * * @param $path * @param $value + * @param array $source * * @return array */ - public static function recursiveBuild($path, $value) { + public static function recursiveBuild($path, $value, $source = []) { $arrayKey = array_shift($path); - return [$arrayKey => (empty($path) ? $value : self::recursiveBuild($path, $value))]; + // Recurse through array keys + if ($path) { + if (!isset($source[$arrayKey])) { + $source[$arrayKey] = []; + } + $source[$arrayKey] = self::recursiveBuild($path, $value, $source[$arrayKey]); + } + // Final iteration + else { + $source[$arrayKey] = $value; + } + return $source; } } diff --git a/tests/phpunit/CRM/Utils/ArrayTest.php b/tests/phpunit/CRM/Utils/ArrayTest.php index 34d9d6c30ab2..979e5bbefa09 100644 --- a/tests/phpunit/CRM/Utils/ArrayTest.php +++ b/tests/phpunit/CRM/Utils/ArrayTest.php @@ -304,8 +304,14 @@ public function testRecursiveValue($array, $path, $default, $expected) { public function getBuildValueExamples() { return [ [ - [0, 'email', 2, 'location'], [0 => ['email' => [2 => ['location' => 'llama']]]] - ] + [], [0, 'email', 2, 'location'], [0 => ['email' => [2 => ['location' => 'llama']]]], + ], + [ + ['foo', 'bar', [['donkey']]], [2, 0, 1], ['foo', 'bar', [['donkey', 'llama']]], + ], + [ + ['a' => [1, 2, 3], 'b' => ['x' => [], 'y' => ['a' => 'donkey', 'b' => 'bear'], 'z' => [4, 5, 6]]], ['b', 'y', 'b'], ['a' => [1, 2, 3], 'b' => ['x' => [], 'y' => ['a' => 'donkey', 'b' => 'llama'], 'z' => [4, 5, 6]]], + ], ]; } @@ -317,8 +323,8 @@ public function getBuildValueExamples() { * * @dataProvider getBuildValueExamples */ - public function testBuildRecursiveValue($path, $expected) { - $result = CRM_Utils_Array::recursiveBuild($path, 'llama'); + public function testBuildRecursiveValue($source, $path, $expected) { + $result = CRM_Utils_Array::recursiveBuild($path, 'llama', $source); $this->assertEquals($expected, $result); }