It would be nice when a registered user invites someone that it would automatically (and with mutual approval), make them friends if the invitee registers.

Comments

fred0’s picture

I'll second that.

Anonymous’s picture

yess, please!!!

4drian’s picture

Would love this too. Invite appears to be pretty stable on D6. Is this functionality in the roadmap or would it take a specific requirement and/or sponsorship to complete?

alex.k’s picture

Status: Active » Postponed

It would be nice to do it, especially because 5.2.x branch has it. However, I don't use Invite module, so it is not high on my list... Please vote here if you really need it. If someone can contribute a port, I'd be happy to help out.

But it is on the roadmap to integrate with http://drupal.org/project/ldap_provisioning, which is what I use for inviting users to the site.

SeanBannister’s picture

+1 Yes I'll be needing this feature for 2 clients, 6 sites.

jaydub’s picture

Assigned: Unassigned » jaydub

I'll provisionally assign this to myself. A quick glance at the code from the 5.x branch doesn't look too hard to port.

However the status of the Invite module itself for Drupal 6 looks a bit worrisome. Looks like no activity for going on 2+ months now.

If Invite for Drupal 6 is not working then my work will halt and this issue will stay postponed until Invite moves forward (hopefully this will not be the case).

jaydub’s picture

Status: Postponed » Needs review
StatusFileSize
new3.18 KB

Ok anyone want to try out this port?

fred0’s picture

Just started testing. Didn't get very far before finding that the /admin/user/relationships/settings menu fails to a blank page. Process of elimination (delete functions one at a time and try page load again) leads me to believe that the offending code are the 2 lines that begin at module_load_include of this function:

/**
 * Implementation of hook_form_alter().
*/
function user_relationship_invites_form_alter(&$form, $form_state, $form_id) {
  if (!(module_exists('invite') && module_exists('user_relationships_api') && module_exists('user_relationships_ui'))) {
    return;
  }

  if ($form_id == 'invite_form') {
    global $user;

    $new_user = drupal_anonymous_user();
    module_load_include('inc', 'user_relationships_ui', 'user_relationships_ui.forms');
    $form += user_relationships_ui_request_form($user->uid, $new_user->uid, $form_state['values']);
    $form['rtid']['#weight'] = 0;
    $form['#validate'][] = 'user_relationship_invites_invite_form_validate';
  }
}
fred0’s picture

Might also be the inclusion of $form_state in the line

function user_relationship_invites_form_alter(&$form, $form_state, $form_id) {

Deleting that also seems to fix the blank page problem.

However, deleting it also causes the registration page for the invited user to fail to show the relationship type in the "are you a friend of user" question. It also returns an error on registration:
warning: Invalid argument supplied for foreach() in /sites/all/modules/user_relationships/user_relationships_api/user_relationships_api.api.inc on line 33.

avpaderno’s picture

$form_state is an argument passed to any implementation of hook_form_alter() in Drupal 6, and Drupal 7 (see the documentation); therefore that is not the reason the patch is not working.

avpaderno’s picture

Title: Are there any plans to work with the invite module? » Are there any plans to work with invite.module?

@#8: In the reported code, the line starting with if (!(module_exists('invite') seems wrong; if the patch should allow to integrate this module with invite.module, then the line should rather start with if ((module_exists('invite').

fred0’s picture

Good eye!
Thanks Kiam. That seems to solve the blank page issue. I'll test the rest and report back.

avpaderno’s picture

Status: Needs review » Needs work

The patch need to be changed.
It's not clear why the code is checking if both user_relationships_api.module, and user_relationships_ui.module exist when one module requires the other; in this case, if module_exists('user_relationships_ui') returns TRUE, also module_exists('user_relationships_api') returns TRUE because of the dependencies between the two modules.

module_exists() doesn't check if a module exists (like the name would make think), but checks if the module is in the list of the loaded modules; that means that if the module file exists but the module is not enabled, the function will return FALSE.

jaydub’s picture

Status: Needs work » Needs review

Regarding a blank page, no such problem here. It would be very helpful if you can have error display turned on or be able to check your logs to see what if any PHP error is reported before you start removing or changing code.

Regarding #11 the line in question is:

  if (!(module_exists('invite') && module_exists('user_relationships_api') && module_exists('user_relationships_ui'))) {
    return;
  }

If you look closely you can see that the ! negation test is against the 3 module_exists calls. So the negation tests whether all 3 modules exist and thus is in fact not a bug.

avpaderno’s picture

Status: Needs review » Needs work

It's true. My apologies for reporting something not correct.

Still, the code is calling module_exists() three times, when it should call it twice; one of the last two modules depend on the other, and it's not possible to load one when the other is not loaded. In this case, as user_relationships_ui depends from user_relationships_api it's enough to write

if (!(module_exists('invite') && module_exists('user_relationships_ui'))) {
  return;
}
fred0’s picture

Status: Needs work » Needs review

jaydub: thanks for the clarification.

The blank white screen also occurs on the Add type relationships setting page.

Per your suggestion I enabled error display, but the blank white screen seems to fail enough that no error is displayed. I also checked the logs and there were no relevant entries.

Drupal 6.9
Invite 6.x-2.x-dev (2008-Nov-14)
UR 6.x-1.x-dev (2009-Jan-27) -also tried with 6.x-1.0

The only component of either of the modules I don't have enabled is UR-Node Access.

Since deleting the $form_state from the function like #9, deleting the 2 lines like #8 or deleting the ! like #11 (which causes the function to skip using $form_state['values']) "fixes" the problem, something about that particular variable is causing the issue I am seeing.

fred0’s picture

I should add that List and Add default work fine.

jaydub’s picture

#16, deleting the $form_state parameter is a non-starter. That's part of hook_form_alter: http://api.drupal.org/api/function/hook_form_alter/6

#8 & #11, you remove these and don't get a white screen BUT does the module then proceed to do what it's supposed to do which is to integrate Invite with UR? I doubt it since the code you are changing would result in the integration not working.

Can anyone else verify that the code in #7 results in a white screen when visiting the UR settings page or add relationship type page? I do not get a white screen.

if you get a white screen, PHP surely is bombing and the error has to be somewhere. Do you have PHP error logging enabled in your php.ini?

fred0’s picture

I did not. Turned it on and got this:
httpd: PHP Fatal error: Cannot redeclare user_relationships_ui_request_validate() (previously declared in /sites/all/modules/user_relationships/user_relationships_ui/user_relationships_ui.admin_actions.inc:121) in /sites/all/modules/user_relationships/user_relationships_ui/user_relationships_ui.actions.inc on line 47

avpaderno’s picture

For what I can see, $form_state['values'] is passed to a form builder function only for multistep forms; normal form builder functions don't get any value for that array key.

avpaderno’s picture

It's the same function that has been written twice in different files; they are not two different functions with the same name.

jaydub’s picture

Kiam@avpnet.org, do you get a white screen in any situation?

jaydub’s picture

#19 yep looks like a function is declared twice. Not sure which one is the newer implementation. Have to kick this up to alex.k to see if he knows.

In user_relationships_ui.actions.inc

/**
 * Validate relationship request.
 */
function user_relationships_ui_request_validate($form, &$form_state) {
  $requester = user_load($form_state['values']['requester']);
  $requestee = user_load($form_state['values']['requestee']);

  if (user_access('can have relationships', $requestee)) {
    //check that a type has been chosen
    $rtid = $form_state['values']['rtid'];
    if (!$rtid || !user_relationships_type_load($rtid)) {
      form_set_error('rtid', user_relationships_ui_get_message('relationship_type_not_set'));
      return;
    }
    $current_relationships = user_relationships_load(array('between' => array($requester->uid, $requestee->uid)));

    if (!db_result(db_query(
      "SELECT COUNT(*) FROM {user_relationship_types}" . ($current_relationships ? " WHERE rtid NOT IN ('%s') ORDER BY name" : ''),
      implode(',', array_keys($current_relationships))
    ))) {
      drupal_set_message(user_relationships_ui_get_message('too_many_relationships'), 'error');
      drupal_goto();
    }
    else if ($current_relationships[$form_values['rtid']]) {
      $message_name = $current_relationships[$form_values['rtid']]->approved ? 'existing_relationship' : 'existing_request';
      form_set_error('rtid', user_relationships_ui_get_message($message_name, array(
        '%requester'                => $requester->name,
        '%requestee'                => $requestee->name,
        '%relationship_name'        => $$current_relationships[$form_values['rtid']]->name,
        '%relationship_plural_name' => $$current_relationships[$form_values['rtid']]->plural_name
      )));
    }
  }
  else {
    drupal_set_message(user_relationships_ui_get_message('not_accepting_requests'));
    drupal_goto();
  }
}

In user_relationships_ui.admin_actions.inc

function user_relationships_ui_request_validate($form, &$form_state) {
  $requester = user_load($form_state['values']['requester']);
  $requestee = user_load($form_state['values']['requestee']);

  if (user_access('can have relationships', $requestee)) {
    $current_relationships = user_relationships_load(array('between' => array($requester->uid, $requestee->uid)));

    if (!db_result(db_query(
      "SELECT COUNT(*) FROM {user_relationship_types}" . ($current_relationships ? " WHERE rtid NOT IN ('%s') ORDER BY name" : ''),
      implode(',', array_keys($current_relationships))
    ))) {
      drupal_set_message(user_relationships_ui_get_message('too_many_relationships'), 'error');
      drupal_goto();
    }
    else if ($current_relationships[$form_values['rtid']]) {
      $message_name = $current_relationships[$form_values['rtid']]->approved ? 'existing_relationship' : 'existing_request';
      form_set_error('rtid', user_relationships_ui_get_message($message_name, array(
        '%requester'                => $requester->name,
        '%requestee'                => $requestee->name,
        '%relationship_name'        => $$current_relationships[$form_values['rtid']]->name,
        '%relationship_plural_name' => $$current_relationships[$form_values['rtid']]->plural_name
      )));
    }
  }
  else {
    drupal_set_message(user_relationships_ui_get_message('not_accepting_requests'));
    drupal_goto();
  }
}
jaydub’s picture

The functions have both been in their respective files since the files were added to CVS for the 6.1 branch so not sure what's the deal here. The original module author is out of the picture now so it's up to us to sort out whether to remove or rename.

avpaderno’s picture

The code is the same in both the files, so there isn't a newer version.

jaydub’s picture

no they aren't the same....look at the code right after the first IF test.

avpaderno’s picture

No, I don't get any WSOD. I copied the module contained in the archive attached here, and I don't have any problems using it in the test site I have on my PC.

I don't know if this is related, but in the triggers page for UR-API, I see an empty page.

fred0’s picture

Well, as a test, I deleted that function first from one file (then replaced it), then the other. Removing it from user_relationships_ui.admin_actions.inc did nothing (still got WSOD). Removing it from user_relationships_ui.actions.inc allows the pages to load normally.

I'd just like to add here that in any of my posts in this thread I was never advocating removing variables or functions. My descriptions of deleting things was simply as a process of elimination test to see what might be causing the WSOD.

fred0’s picture

Following up on this, I started with a clean install of Drupal 6.9 to re-test for the WSOD.
After basic install, I enabled Blog, Path, Pathauto and Token modules. Then enabled Invite. Next enabled UR-API and UR-UI and check settings page: all ok. Next enabled UR-Invites and rechecked: still ok. Enabled remaining UR modules 1 by 1 checking every time: ok. Enabled Views and UR-Views: ok.
Added relationships for testing and invited a new user. Everything worked fine.
Logs were clear of errors too.

Next, since Kiam mentioned Triggers, I tried to enable the Trigger module and got a validation error. Immediately went back to UR and started getting the WSOD as I describe above. Triggers had failed to enable so, I tried again and this time it succeeded. The WSOD persisted however. I then disabled and uninstalled Triggers, but the WSOD still persists.
There was no log error to accompany the validation error. The WSOD gives the same log error as I listed in #19.

avpaderno’s picture

@#26: Yes, I was wrong.
In this case it's enough to see if the code for the form uses a form item named rtid; if that is the case, then the code using rtid is the correct one.

paganwinter’s picture

Subscribing...

Is this for the D5 ver.?

paganwinter’s picture

Hi all,

I am currently working on a project that needs to go live 5 days back... :P

Is there some hack that I can use in the meanwhile that will alow me to let inviters add invitees as 'friends' (that's the only relationship I am using right now).
I thought of a very basic option of letting the inviter add the invitee as a friend using a link that'll be shown when the invitee joins the site. This link could be placed along with the message that is shown to the user when his invitee joins.
Something like the following:

' () has joined !'
'Add as a friend'

being a link requesting the invitee for a friend relationship.
That is the easier way out.

Instead is there some way I can programatically make the inviter request a friend request to the invitee?

I am right now going through the patch you have submitted. Any help in this regard would be greatly appreciated...
:)

More specifically, is there some way that I can call the menu path (relationship/%user/request) as if the inviter was calling it, upon registration of the invitee?

Or if not this, at least how can I send a mail to the inviter upon joining of the invitee?

jaydub’s picture

StatusFileSize
new2.22 KB

Re-rolled the patch with minor changes.

Use on a freshly updated UR -dev snapshot as the new snapshot has addressed the question of the duplicated function declaration referred to in #23

fred0’s picture

Seems to work as advertised.

mariusooms’s picture

Hi Jaydub, would there be any objections to see if this contrib module could be ported to support friendlist as well? Seems like a lot of good effort has gone into this and would a welcome feature for us as well. Just wanted to ask permission without assuming anything. If so, I will make an update we will support the invite module as well in the issue queue (http://drupal.org/node/372404).

Regards,

Marius

jaydub’s picture

No problem feel free to use for friendlist. We haven't added to the projet yet but what you see is pretty much ready to go

mariusooms’s picture

Sounds good...thanks for the go ahead.

Marius

fred0’s picture

So, can this be added to the next dev release?

alex.k’s picture

Status: Needs review » Reviewed & tested by the community

Seems to be ready to be committed. @jaydub when you have a chance, please add to CVS. Thanks for working on this!

jaydub’s picture

Will do. Still in DC but will be back tomorrow!

jaydub’s picture

Status: Reviewed & tested by the community » Fixed

Added to CVS

alex.k’s picture

Many thanks @jaydub!

Regarding #23 and #33 the function has been removed in CVS for good (was commented out previously).

Status: Fixed » Closed (fixed)

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