Closed (cannot reproduce)
Project:
User Relationships
Version:
6.x-1.x-dev
Component:
Mailer
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
15 Sep 2009 at 19:47 UTC
Updated:
18 Apr 2012 at 21:24 UTC
Would it be possible to pull the note given in elaborations when creating a relationship to be sent in the request or pre-approval email?
Comments
Comment #1
alex.k commentedIt should be possible to for UR-Elaborations inject the additional token, I'm not 100% sure. If you can look at the code that gathers available tokens that'd be great.
Comment #2
scalp commentedThank you for the incredibly fast reply. Unfortunately, my php is not real strong. Here's what I think is creating the available tokens list for the token module:
function token_get_values($type = 'global', $object = NULL, $flush = FALSE, $options = array()) {
static $tokens;
static $running;
// Flush the static token cache. Useful for processes that need to slog through
// huge numbers of tokens in a single execution cycle. Flushing it will keep
// them from burning through memory.
if ($flush || !isset($tokens)) {
$tokens = array();
}
// Since objects in PHP5 are always passed by reference, we ensure we're
// working on a copy of the object.
if (is_object($object)) {
$object = drupal_clone($object);
}
// Simple recursion check. This is to avoid content_view()'s potential
// for endless looping when a filter uses tokens, which load the content
// view, which calls the filter, which uses tokens, which...
if ($running) {
// We'll allow things to get two levels deep, but bail out after that
// without performing any substitutions.
$result = new stdClass();
$result->tokens = array();
$result->values = array();
return $result;
}
$running = TRUE;
token_include();
$id = _token_get_id($type, $object);
if (isset($tokens[$type][$id])) {
$tmp_tokens = $tokens[$type][$id];
}
else {
$tmp_tokens = module_invoke_all('token_values', $type, $object, $options);
$tokens[$type][$id] = $tmp_tokens;
}
// Special-case global tokens, as we always want to be able to process
// those substitutions.
if (!isset($tokens['global']['default'])) {
$tokens['global']['default'] = module_invoke_all('token_values', 'global');
}
$all = array_merge($tokens['global']['default'], $tokens[$type][$id]);
$result = new stdClass();
$result->tokens = array_keys($all);
$result->values = array_values($all);
$running = FALSE;
return $result;
}
Not sure what would be needed to make this work. Sorry for not being able to be more helpful.
Comment #3
scalp commentedCouldn't something just be added to the user_relationship_mailer.module file to include an elaboration if it's included? Seems like the elaboration should be presented to the recipient on first contact which would be the email.
Comment #4
scalp commentedDoes anyone know how this could be done?
Comment #5
scalp commentedI'm still trying to get this done. I'm kind of surprised that there hasn't been more interest in this. It seems to me that sending the elaboration with the email would be important especially if usernames are being used. How else will the recipient know where they know the sender from?
Here's what I've tried so far. I've added the following to the function user_relationship_mailer_replacements in /user_relationship_mailer/user_relationship_mailer_defaults.inc:
'@elaboration' => user_relationships_get_elaboration ($relationship->rid),
This adds @elaboration as a replacement token, but returns nothing. I've replaced the parameter with '32' which returns the elaboration for rid 32 into the emails so I know the function is being called properly into the email. I can't find a function that returns the rid, yet I see rid being used throughout the user relationship module. Do I need to write a new function that will retrieve the rid or is there already something in place that I could use to insert the appropriate rid into the parameter?
Comment #6
alex.k commentedYour code looks correct, and judging by the rest of the function user_relationship_mailer_replacements(), $relationship->rid should be available. You could test this by trying out
'@elaboration' => $relationship->rid,and checking if you see it in the email. If you do, then it could be that the order of hooks firing is such that the email is sent before the elaboration record is saved. If you insert an exit() call into the function, Drupal will abort at that point, and you will be able to inspect the database to see if the elaboration record for the newly created relationship is actually there.Also, dumb question... is the elaboration not already available in $relationship? Appreciate you working to resolve this.
Comment #7
scalp commentedI'm glad to help on resolving this. Hopefully we can get it working. I know the elaborations are being saved. As I mentioned, I can get it to pull an old one from the db by choosing an old rid to pass as a parameter. I did try using the following:
'@elaboration' => $relationship->elaboration,
but it didn't work so I'm guessing that its not in the array by default. I looked around and couldn't find anything to contradict this.
Using
It does return the correct rid. You kind of lost me on the what to do if that happened part though. Where would I need to insert the exit?
Comment #8
alex.k commentedNo problem. What I was trying to say is that at the moment the email is sent, the elaboration record is not yet in the database. The flow in that case would be something like:
User hits submit --> .... --> save relationship --> ..... --> send email --> ..... --> save elaboration note --> ..... --> done
The way to debug this is to insert exit() anywhere in the user_relationship_mailer_replacements() function. When you request a new relationship, it will reach this point and abort. You then can look at the user_relationship_elaborations table and see if the new elaboration note is there. If not, the module needs to be edited to use the correct hook so that the record is inserted earlier in the process.
Comment #9
scalp commentedGot it. Inserting the exit () into the function does indeed stop the elaboration from being saved. It also does not send an email. It just returns a blank empty page when a request is sent. It does create a new rid in the user relationships table though. Just nothing in the elaborations table.
Comment #10
alex.k commentedThank you for debugging the issue.
It's a bad design in the way the relationship is saved and the order of hooks firing. Basically, if this had been done right, $relationship->elaboration would not have been empty. There was a pretty helpful explanation in #526356: Improve extendability of API hooks on the underlying problem. That's the reason the elaboration is saved after mailer and possibly other modules have done their work. Would love to fix the issue (and the elaborations module in general could use a few cleanups), but really a stable release is a bigger priority at the moment.
Comment #11
scalp commentedNo problem. Do you have any ideas on a work around for this in the meantime? Would there be some way to effectively pause the email being sent until the end of the process?
Comment #12
alex.k commentedCommitted an implementation that allows @elaboration to appear in email replacements, http://drupal.org/cvs?commit=285890. Major cobwebs and less than stellar design there :)
Please test this as well as that the request process has not been affected.
Comment #13
scalp commentedExcellent. I will definitely start testing this out. Is this included in the newest dev version or should I just apply the patches listed in the CVS?
Comment #14
alex.k commentedNope, it's already in CVS and the -dev release.
Comment #15
scalp commentedA couple of things I've found so far. The elaborations are included in the email (thank you for doing this), but special characters are broken down to their html counterparts. Also, the view I had set up for seeing posts created by "friends" is now not working. It's been a while since I've messed with this, but I'm pretty sure it was working properly before. Could something have been changed that would now have the view returning JUST the logged in user's posts?
Comment #16
scalp commentedGot the views working again. Had to change the argument "requester user" to "requestEE user".
Comment #17
alex.k commentedFor me the apostrophe gets converted to ' because @elaborations is run through check_plain. I think there should be no XSS risk in changing @elaboration to !elaboration to pass it unescaped, because the text will be sent via email and not displayed on the screen.
Comment #18
scalp commentedUnfortunately, I don't know enough to be able to offer an opinion on this.
Comment #19
alex.k commentedComment #20
scalp commentedAs mentioned I was able to get the 2 way relationship to work again, by flip flopping the argument. I cannot get the view for the one way to work again though. I can get a view that shows nodes from people that are following me, but no matter what I try I can't get a view to show nodes from people I'm following. Pretty sure this was working before the upgrade to dev.
Comment #21
mrf commentedMoving this to a bug report since alex re-opened this issue and it sounds like the code for the feature was already in the dev branch.
Comment #22
mrf commentedComment #23
mrf commentedComment #24
mrf commentedIf there are any remaining issues here I'm not seeing them, special characters were coming through fine for me.