Skip to content

Commit

Permalink
Merge pull request #22253 from eileenmcnaughton/rel5
Browse files Browse the repository at this point in the history
[REF] Minor parameter simplification
  • Loading branch information
seamuslee001 committed Dec 15, 2021
2 parents 9c1644b + 355e277 commit daf96d3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions CRM/Contact/BAO/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,7 @@ public static function checkDuplicateRelationship(&$params, $id, $contactId = 0,
$relationship = CRM_Core_DAO::executeQuery($queryString);
while ($relationship->fetch()) {
// Check whether the custom field values are identical.
$result = self::checkDuplicateCustomFields($params, $relationship->id);
if ($result) {
if (self::checkDuplicateCustomFields($params['custom'] ?? [], $relationship->id)) {
return TRUE;
}
}
Expand All @@ -992,23 +991,27 @@ public static function checkDuplicateRelationship(&$params, $id, $contactId = 0,
* the same as the values of the custom fields of the relation with given
* $relationshipId.
*
* @param array $params (reference) an assoc array of name/value pairs
* @param array $params an assoc array of name/value pairs
* @param int $relationshipId ID of an existing duplicate relation
*
* @return boolean true if custom field values are identical
* @access private
* @static
*/
private static function checkDuplicateCustomFields(&$params, $relationshipId) {
private static function checkDuplicateCustomFields($params, $relationshipId) {
// Get the custom values of the existing relationship.
$existingValues = CRM_Core_BAO_CustomValueTable::getEntityValues($relationshipId, 'Relationship');
// Create a similar array for the new relationship.
$newValues = [];
if (isset($params['custom']) && is_array($params['custom'])) {
// $params['custom'] seems to be an array. Each value is again an array.
if (!is_array($params)) {
// No idea when this would happen....
CRM_Core_Error::deprecatedWarning('params should be an array');
}
else {
// $params seems to be an array, as it should be. Each value is again an array.
// This array contains one value (key -1), and this value seems to be
// an array with the information about the custom value.
foreach ($params['custom'] as $value) {
foreach ($params as $value) {
foreach ($value as $customValue) {
$newValues[$customValue['custom_field_id']] = $customValue['value'];
}
Expand Down

0 comments on commit daf96d3

Please sign in to comment.