Followup issue from #328647: Purge "event" from the UI (and code) unless we're talking about event.module. One of the few remaining spots in the code and UI that mention "event" are the "%event" and "%eventurl" tokens you can put in the email templates. I didn't want to mess with those in #328647 since it'd require a DB update, but I think it's worth doing before the 5.x-2.6 release and the D6 porting. While we're at it, I figured I should take the time to rename the others, too:

$replacements = array(
  '%event' => '%node_title',
  '%eventurl' => '%node_url',
  '%time' => '%node_time',
  '%username' => '%user_name',
  '%useremail' => '%user_email',
  '%info' => '%user_info',
);

I've implemented and lightly tested two different approaches for the DB update now. Stay tuned for the patches...

Comments

dww’s picture

Status: Active » Needs review
StatusFileSize
new9.94 KB
new10.08 KB

Two approaches:

"php": queries for all records in {signup}, converts the two email template fields via PHP, and if the new versions are different than what's in the DB for each record, does a separate query to update each record.

"sql": makes one crazy query that does all the conversion all at once on all rows using some nested REPLACE() string manipulation functions as part of the query.

I suspect the SQL one is better, especially for sites with a really big {signup} table, but I'm really not sure. Also, according to the docs, REPLACE() works the same on both pgsql and mysql, but I haven't tested that.

dww’s picture

dww’s picture

I realized that with both patches, we need to replace %eventurl before we replace %event, or you end up with %node_titleurl. ;)

If we go with the PHP version, it probably needs work to convert it to the update.php "batch" functionality (such as it is). However, I suspect the SQL version is good enough, and certainly the less complicated approach.

dww’s picture

Status: Needs review » Needs work

I got davidstrauss's opinions on this in IRC, and the nested REPLACE() is the clear winner. For the record, a few technical details about why:


davidstrauss: dww: the best approach would be nested REPLACE() done in batches of 1000 rows at a time
davidstrauss: nested REPLACE() is going to be far faster than the php+sql version
davidstrauss: just make sure it won't take too long on large datasets
dww: davidstrauss: greggles said he'd do it as separate queries instead of the nested one -- is that just superstition? ;)
davidstrauss: dww: far faster to nest
davidstrauss: dww: it's simply an issue of temporal locality
davidstrauss: dww: if you iterate over the entire set X times, you won't have good caches
davidstrauss: dww: if you iterate once over the set and perform X operations per item, then you only read/write once
davidstrauss: and the other operations happen in memory
davidstrauss: and, most likely, in high-speed caches

So, there you have it, nested REPLACE() is the clear win. Now I just need to batch-ify it anyway, to make sure I only do 1000 rows at a time.

dww’s picture

Status: Needs work » Needs review
StatusFileSize
new12.63 KB

This does it in batches of at most 2000 nids at a time. Since we don't know how many rows in the {signup} table each 2000 nids will be (probably much less than 2000), and since there's no easy cross-db way to know what's the last nid we updated if we just do a LIMIT/OFFSET query, this seems like the most fool-proof approach, even if it means we end up doing lots of small queries we might not need. It's what davidstrauss told me to do, at least, and that's gotta count for something. ;)

Also, at his suggestion, using %user_mail instead of %user_email, to be a little more consistent with core (it's {user}.mail for example).

dww’s picture

StatusFileSize
new12.79 KB

New patch using the following:

$replacements = array(
  '%eventurl' => '%node_url',
  '%event' => '%node_title',
  '%time' => '%node_start_time',
  '%username' => '%user_name',
  '%useremail' => '%user_mail',
  '%info' => '%user_signup_info',
);

%node_start_time and %user_signup_info seem less ambiguous than %node_time and %user_info...

adrinux’s picture

Patch applied cleanly (with offsets) to DRUPAL-5--2 branch. Upgrade went smoothly, but signup table on this site is only 45 rows.

I was surprised it didn't update the tokens in use within the default confirmation and reminder e-mail fields, but then I suppose we don't normally mess with added content :) I assume upgrade notes about these token changes will accompany any release.

I find the new token names a lot less useable, but then I'm using event :) Using drupal jargon (node) seems particularly nasty.

'%eventurl' => '%url',
'%event' => '%title',
'%time' => '%start_time',

with additional details in the help text may be less confusing to 'end users' than prefixing everything with 'node-'.

I suppose ideally we'd want a substitution like:
$content_type . '_' . $title
so that whatever the signed up content is was used as the token (event_title, concert_title etc) but I don't know how workable that is in practice.

dww’s picture

Thanks for the testing....

I was surprised it didn't update the tokens in use within the default confirmation and reminder e-mail fields, but then I suppose we don't normally mess with added content :)

Huh? That's exactly what this update is supposed to be doing... What do you mean "it didn't update the tokens in use within the default confirmation and reminder e-mails fields"? Can you post an example of an email template from after the upgrade that still contains the old tokens? This is very worrisome. :(

I find the new token names a lot less useable, but then I'm using event :)

Heh. ;)

Using drupal jargon (node) seems particularly nasty.

Well, I was trying to make these generic, unambiguous, and self-documenting... I know "node" is considered uncool in the UI, but it's still all over the place in Drupal. I don't know how to "un-node" Drupal.

'%eventurl' => '%url',

URL of what? The node? The user?

'%event' => '%title',

That's probably safe.

'%time' => '%start_time',

Again, probably safe, but still potentially a bit ambiguous.

I suppose ideally we'd want a substitution like:
$content_type . '_' . $title
so that whatever the signed up content is was used as the token (event_title, concert_title etc) but I don't know how workable that is in practice.

Yeah, that could be cool. Sadly, it's not really workable at all. :( Think about the site-wide global settings for this at admin/settings/signup. There's no node there, so there's no way to know what node type to use to replace the tokens with. It also makes the DB update much more treacherous...

Anyway, I'm still open to finalizing a better name for these tokens. But, I'm most worried that you didn't see everything replaced during the upgrade. Evil. Can you post more details about that?

Thanks!
-Derek

adrinux’s picture

I'd reverted the changes so I'm re-installing signup 2.x (cvs DRUPAL-5--2) and re-running update.php this morning.

First up, the db update appears to execute without error:

Update #5204
Replaced %event, %eventurl, %time, %username, %useremail, and %info tokens with %node_title, %node_url, %node_start_time, %user_name, %user_mail, and %user_signup_info in the reminder and confirmation email templates.

Next visit http://example.com/admin/settings/signup and check the default confirmation and reminder emails – in my case these have been modified from the signup originals, but obviously it should still update.
Attached is an image of combined screenshots, before update on the left and after on the right, note that the help text is updated, the email text is untouched.

Today I remembered to check the per node email text for existing events and that has been updated, so it would appear it's just the defaults that are left untouched, of course newly created events also get the untouched email text as a result.

> new token names
All valid points :)

dww’s picture

StatusFileSize
new12.94 KB

Bah, I'm an idiot. My update code was starting from 0 and going up, but I forgot that we use nid 0 to store the global defaults...
Try this one. ;)

adrinux’s picture

Yep, that's sorted the defaults too. Aside from someone with a bigger data set testing I think this is RTBC.

jrbeeman’s picture

StatusFileSize
new1.21 KB

The update in the attached patch works well on a site with 4400+ records in the signup table (applies quite quickly, in fact). The test was run on my dev laptop (OS X 10.5.x running latest MAMP).

The only problem I encountered was in applying the patch, which reported back the following:

$ patch -p0 < ~/tmp/328840_signup_rename_tokens_sql.10.patch
patching file signup.install
patching file signup.module
Hunk #2 succeeded at 1774 (offset 3 lines).
Hunk #3 succeeded at 1796 (offset 3 lines).
Hunk #4 succeeded at 1806 (offset 3 lines).
Hunk #5 succeeded at 2153 (offset 3 lines).
Hunk #6 succeeded at 2263 (offset 3 lines).
Hunk #7 succeeded at 2427 (offset 3 lines).
Hunk #8 succeeded at 2493 (offset 3 lines).
Hunk #9 succeeded at 2534 (offset 3 lines).
Hunk #10 succeeded at 2698 (offset 3 lines).
Hunk #11 FAILED at 2715.
1 out of 11 hunks FAILED -- saving rejects to file signup.module.rej

See the attached signup.module.rej for details. This patch was applied against a freshly updated CVS checkout of the DRUPAL-5--2 branch, so the conflict could have resided in some recent commit. I don't believe this affects the update script, though.

dww’s picture

StatusFileSize
new12.93 KB

Yeah, that's caused by http://drupal.org/cvs?commit=151782. This one applies cleanly.

Any final thoughts on the new proposed names before I commit this?

Thanks!
-Derek

dww’s picture

StatusFileSize
new12.43 KB

And here's a version of the same patch that applies against HEAD for the D6 port.

dww’s picture

Status: Needs review » Fixed

Committed to HEAD and DRUPAL-5--2. Yay. ;)

dww’s picture

Status: Fixed » Needs review
StatusFileSize
new1.8 KB

EVIL... I was testing this on D6 and noticing that it never seemed to work. Much interesting debugging later, and I realized we were getting nailed there since in D6, db_query() now supports a '%n' placeholder, and all those '%node_title' etc tokens were confusing everything. Yikes. To be safe, all of our '%' in our token string literals should really be '%%' so that db_query doesn't mess with them.

dww’s picture

Status: Needs review » Fixed

Committed that to HEAD and DRUPAL-5--2. Phew.

Status: Fixed » Closed (fixed)

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