Skip to content

Commit

Permalink
[REF] Minor parameter simplification
Browse files Browse the repository at this point in the history
The only value in this array used in the function is 'custom' which should be an array. I think it woul
d only ever be an array or NULL (which would then be an array with this change) but I left
a deprecation notice in case. Pass-by-ref isn't needed
  • Loading branch information
eileenmcnaughton committed Dec 15, 2021
1 parent 6fdd5d9 commit bd736ba
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::deprecatedFunctionWarning('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 bd736ba

Please sign in to comment.