I will do this myself if I get a chance, but thought I should create an issue for it. The 4.x branch of Invite is much better than the original 2.x branch that user_relationship_invites is built around, and includes rules and views support.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chrism2671’s picture

I've written a patch now that supports both versions. I will post it as soon as I've had a chance to test it thoroughly.

Martin Mayer’s picture

Can I help you testing the patch?

chrism2671’s picture

chrism2671’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, user_relationships-make-it-work-with-invite-4.x-2041769-3.patch, failed testing.

mrded’s picture

Version: 7.x-1.0-alpha5 » 7.x-1.x-dev
Status: Needs work » Needs review
mrded’s picture

chrism2671’s picture

As requested by someone, here is the full module code, for anyone struggling to apply the patch. If the patch doesn't apply cleanly, please report it in this thread.

Shawn DeArmond’s picture

Status: Needs review » Needs work

One thing didn't work quite right. If I sent a UR Invite to someone who already has an account on the site, they rightfully get the invite notice, but when accepted, the relationship is not established.

chrism2671’s picture

It should work, and did work in my testing. This part of the logic hasn't changed so afaik it should be ok. Do you know specifically what caused the issue you're seeing?

Shawn DeArmond’s picture

I looked through the code, but couldn't see where the relationship is being assigned. The invite is sent, of course, but no relationship.

Shawn DeArmond’s picture

So, it looks like what's going on here is this:

User already has an account, so user logs in. Clicks "accept" in the message area. Menu item 'invite/accept/%invite_by_code' is called, and function invite_accept() is fired.

As I step through that function, there is nothing that goes back to user_relationships_invite module, so nothing happens to the relationship request.

I think the best option here is to use hook_entity_update() on the 'invite' entity and fire off the relationship acceptance in that function.

Thoughts?

Shawn DeArmond’s picture

Status: Needs work » Needs review

This works for me, but I don't think I've tested it on all possibilities.

function user_relationship_invites_entity_update($entity, $type) {
  if ($type == 'invite' && $invite = user_relationship_invites_get_invite($entity->reg_code)) {
    db_delete('user_relationship_invites')
      ->condition('invite_code', $entity->reg_code)
      ->execute();
    $invitee = user_load($entity->invitee);
    if (user_relationships_can_receive($invitee, $invite->relationship_type)) {
      if ($entity->joined) {
        user_relationships_request_relationship($entity->uid, $invitee, $invite->relationship_type, TRUE);
      }
    }
  }
}
Shawn DeArmond’s picture

This is probably a better way: hook_invite_accept()

function user_relationship_invites_invite_accept($invite) {
  if ($ur_invite = user_relationship_invites_get_invite($invite->reg_code)) {
    db_delete('user_relationship_invites')
      ->condition('invite_code', $invite->reg_code)
      ->execute();
    $invitee = user_load($invite->invitee);
    if (user_relationships_can_receive($invitee, $ur_invite->relationship_type)) {
      user_relationships_request_relationship($invite->uid, $invitee, $ur_invite->relationship_type, TRUE);
    }
  }
}
chrism2671’s picture

OK I haven't checked it since you posted this; but then again my patch didn't change this section of code. (I will check it when I get time).

As I recall though, there is a checkbox that is added on the user reg form that says something like 'accept invitation', so the actual process of accepting it goes through the browser (rather than through the backend).

Shawn DeArmond’s picture

The invite for NEW users works fine. What I'm talking about is sending an invite to an EXISTING email address.

It also doesn't really create the user_relationships request, so it doesn't show up in any of the views.

Lastly, and I think this is a bug in the Invite module, the link to reject the invite is broken, if you're an existing user who has been sent an invite.

I'll look to filing an issue about that and post it here when I find it.

Shawn DeArmond’s picture

Here's some code for user_relationship_invites_invite_form_validate() that creates ur requests

    elseif ($version == 4
            && $form_state['invite']->type == 'invite_by_email'
            && $invitee = user_load_by_mail($form_state['values']['field_invitation_email_address']['und'][0]['value'])) {
      if ($invitee->status == 1) {
      // This is an existing, non-blocked user, identified by email address. Create relationship request.
        user_relationships_request_relationship($user, $invitee, $form_state['values']['rtid'], FALSE);
      }
    }

I'll wrap this all up in a patch momentarily.

Shawn DeArmond’s picture

Here's the updated patch including #14 and #17

chrism2671’s picture

Ah, I hadn't tested this case, I was under the impression that the invite module's sole purpose was to invite new users to the website. Exactly how are you using it then? How does this differ from the request relationship email that's in user_relationships?

Shawn DeArmond’s picture

It's not really any different, because, really, how would the inviter user know? Currently, Invite doesn't do anything to tell you that the user is already a member of the site. But in either case, they'll want a UR relationship, so it should oblige.

In my case, I'm likely to use both. I'll have a "find friends" screen to use the UR request email, and a "Send an Invite" screen, which the user will think is a new user. But if it's not a new user, it still needs to work similar to a UR request.

Edit: for clarity.

mrded’s picture

Refactor code and change to Drupal code standards.

madhudvs’s picture

madhudvs’s picture

Issue summary: View changes

hi guys.... it would be nice if new invite module works with UR
i tried both patchs #18 and #21 with no result...
if "Request relationship" is selected in invite block... the site breaks..
any updates in this regard ?

madhudvs’s picture

Status: Needs review » Closed (fixed)
mrded’s picture

Status: Closed (fixed) » Needs review

@madhudvs, why did you close the issue? It hasn't been done!

mrded’s picture

Guys what if we'll move the module to separate project? In this case we can create separate branch for different versions of Invite module.

I've already started to do that in my sandbox Invite User Relationships

mrded’s picture

Status: Needs review » Closed (won't fix)

I've released Invite User Relationships module which will integrates User Relationships with Invite 7.x-4.x module.

Please take a look.