In user_relationships_request_relationship the following code

function user_relationships_request_relationship($requester, $requestee, $type, $approved = FALSE) {
  // translate an ID into an object
  foreach (array('requester' => $requester, 'requestee' => $requestee, 'type' => $type) as $key => $value) {
    if (!is_object($value)) {
      $$key = $key == 'type' ? user_relationships_type_load($value) : user_load(array('uid' => $value));
    }
  }

  if (!variable_get('user_relationships_allow_multiple', TRUE)) {
    if (user_relationships_load(array('user' => $requester->uid, TRUE)) || user_relationships_load(array('user' => $requestee->uid, TRUE))) {
      return t('Users are not allowed to have multiple relationships');
    }
  }

should read

function user_relationships_request_relationship($requester, $requestee, $type, $approved = FALSE) {
  // translate an ID into an object
  foreach (array('requester' => $requester, 'requestee' => $requestee, 'type' => $type) as $key => $value) {
    if (!is_object($value)) {
      $$key = $key == 'type' ? user_relationships_type_load($value) : user_load(array('uid' => $value));
    }
  }

  if (!variable_get('user_relationships_allow_multiple', TRUE)) {
    if (user_relationships_load(array('user' => $requester->uid), TRUE) || user_relationships_load(array('user' => $requestee->uid), TRUE)) {
      return t('Users are not allowed to have multiple relationships');
    }
  }

Patch attached.

CommentFileSizeAuthor
ur.patch656 bytesstashlbai

Comments

ajayg’s picture

I see the changes you made. But what exactly are the consequances becasue of this to user? What behaviour you see that needed correction and you came up with the patch?

If I need to test this patch what is before and after behaviour for a user (or administrator)?

stashlbai’s picture

The change reflects the fact that the old code was calling user_relationships_load with the wrong arguments; which meant that a function calling user_relationships_request_relationship in an environment allowing multiple relationships received incorrect results. This can be confirmed by examining the call signature of user_relationships_load(), which does not rationally accept a single array with 'user'->val, true as its components.

I think it would be more interesting for you to explain what the call

user_relationships_load(array('user' => $requester->uid, TRUE))

is trying to retrieve, in the code as it exists? What does TRUE do in the array as first argument?

jaydub’s picture

Version: 5.x-2.8 » 5.x-2.x-dev
Status: Needs review » Fixed

#2 is right. The comments for the user_relationships_load() function show:

/**
  * Load relationship objects from the database.
  *
  * @param $param
  *   an array of parameters with the key being the column. columns from both the user_relationships and user_relationship_types tables will work
  *     columns from user_relationships: rid, requester_id, requestee_id, rtid, approved, created_at, updated_at, flags
  *     columns from user_relationship_types: name, plural_name, is_oneway, requires_approval, expires_val
  *   There are two special keys:
  *     1) array("between" => array($uid1, $uid2)) will return all relationships between the two user ids.
  *     2) array("user" => $uid) will return all relationships for the specified uid
  *
  *   arguments will process operators as well using the syntax: array(col => '> {value}'). 
  *     example: show all relationships created in 2007 
  *       $start_time = mktime(0,0,0,0,0,2007);
  *       $end_time = mktime(0,0,0,0,0,2008);
  *       user_relationships_load(array('created_at' => ">= {$start_time}", 'created_at' => '< {$end_time'}));
  * @param $count
  *   a boolean stating whether or not the return value should be the number of relationships found
  * @param $sort
  *   a string containing a valid column name which will become the key for the returned array of relationships
  * @param $order
  *   a string containing SQL stating the column and direction of the sort (ex. "requester_id ASC, rtid DESC")
  * @param $limit 
  *   a string containing SQL stating the limit (ex "10" or "10, 5")
  *
  * @return
  *   an array of relationships
  *   if the key is "rid" the array will be a single dimention: array($rid => $relationship, $rid => $relationship)
  *   otherwise it'll be multidimentional: array($rtid => array($relationship, $relationship))
  *
  *   each relationship will have the user's name, mail, and data attached as requester_name, requester_mail, requester_data
  *   or requestee_name, requestee_mail, requestee_data
 */
function user_relationships_load($param = array(), $count = FALSE, $sort = 'rid', $order = NULL, $limit = NULL, $include_user_info = FALSE, $reset = FALSE) {

The 2nd parameter is a boolean which fits the patched function call shown above where the 1st parameter is just the array('user' => $requester->uid).

This is a moot point now though as this has been fixed in CVS already:

http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/user_relati...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.