From e0e0010322ee937af94160087c5433928e1b6d9b Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 5 Jul 2023 13:10:35 +1200 Subject: [PATCH] Use consistent value for checkPermissions in merger We recently added a permission check when retrieving metadata here https://github.com/civicrm/civicrm-core/commit/0e88731ff38f4bcf5a4d53c7e2ced01f70533ff1#diff-fe60c89ebe94bbd40114d135459371cc53708db1f2952ade6c0ce9b3468c4dabR2306 However, when that function is called from getFieldValueAndLabel that is not being passed and is defaulting to TRUE. This is causing issues in a cron context where checkPermissions is being used (well actually in a unit test in our custom code simulating that possiblility) --- CRM/Dedupe/Merger.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index 99fd822328..45b6b91742 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -1541,12 +1541,12 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m continue; } $rows["move_$field"] = [ - 'main' => self::getFieldValueAndLabel($field, $main)['label'], - 'other' => self::getFieldValueAndLabel($field, $other)['label'], + 'main' => self::getFieldValueAndLabel($field, $main, $checkPermissions)['label'], + 'other' => self::getFieldValueAndLabel($field, $other, $checkPermissions)['label'], 'title' => $fields[$field]['label'], ]; - $value = self::getFieldValueAndLabel($field, $other)['value']; + $value = self::getFieldValueAndLabel($field, $other, $checkPermissions)['value']; //CRM-14334 if ($value === NULL || $value === '') { $value = 'null'; @@ -2767,14 +2767,15 @@ ORDER BY civicrm_custom_group.weight, /** * Get the field value & label for the given field. * - * @param $field - * @param $contact + * @param string $field + * @param array $contact + * @param bool $checkPermissions * * @return array * @throws \Exception */ - private static function getFieldValueAndLabel($field, $contact): array { - $fields = self::getMergeFieldsMetadata(); + private static function getFieldValueAndLabel(string $field, array $contact, bool $checkPermissions): array { + $fields = self::getMergeFieldsMetadata($checkPermissions); $value = $label = $contact[$field] ?? NULL; $fieldSpec = $fields[$field]; if (!empty($fieldSpec['serialize']) && is_array($value)) { -- 2.25.1