Importing d6_user_mail brings across the email templates that are sent to users. The tokens do not get converted.

I have a patch I am working on to address this, using user_update_7017's list of tokens.

Testing notes:

After running this patch you can go to /admin/config/people/accounts and in the email templates you should see tokens like "[site:name]" (desired) which replace the old "!site" style tokens.

Comments

Anonymous’s picture

Ryan Weal created an issue. See original summary.

Anonymous’s picture

Assigned: » Unassigned
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new4.58 KB

This patch adds a process plugin to migrate_drupal that converts tokens using the code from user_update_7017. I confirmed that the tokens listed there seem to be the same as D7.

The patch also updates d6_user_mail.yml to utilize the new plugin.

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch, 2: 2551631-convert-user-mail-tokens-2.patch, failed testing.

quietone’s picture

Assigned: Unassigned » quietone

Since I've been working on the related issue, https://www.drupal.org/node/2353817, I'll have a go at this one.

Anonymous’s picture

At this point it should just need updates to the appropriate tests. Sorry I dropped off on this one, was working on criticals at the sprint in Chicago last weekend and I'm busy with other things now.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new14.54 KB
new13.2 KB

@Ryan Weal, NP. I'm just glad I spotted it. And that I've learned enough to add to your work.

Updated the expected text for the tests.

I didn't see user_mail_user_mail_register_pending_approval_subject and user_mail_user_mail_register_pending_approval_body in D6, so changed them to mail_register_pending_approval_subject and user_mail_register_pending_approval_body which I did see.

Moved the plugin to the user module

Status: Needs review » Needs work

The last submitted patch, 7: 2551631-6.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new15.15 KB
new14.14 KB

Well, messing up Variable.php was bound to happen sooner or later. Fixed that. Note the interdiff is against the patch in #2 because #6 is just plain wrong, not just because of variable.php but also because it includes a diff on a . file.

phenaproxima’s picture

Status: Needs review » Needs work

Nice patch. Makes good sense and is well-tested.

+++ b/core/modules/user/src/Plugin/migrate/process/ConvertTokens.php
+ * ConvertTokens changes tokens to new values.

Can this explanation be a bit more detailed? Maybe something like "This plugin replaces old !token placeholders with proper [tokens]." Paraphrase as desired :)

+++ b/core/modules/user/src/Plugin/migrate/process/ConvertTokens.php
+  /**
+   * {@inheritdoc}
+   *
+   * ConvertTokensenates the strings in the current value.
+   */

I don't think we're supposed to combine {@inheritdoc} with a comment. Let's ditch the comment.

+++ b/core/modules/user/src/Plugin/migrate/process/ConvertTokens.php
+  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
+

Extra line of white space.

+++ b/core/modules/user/src/Plugin/migrate/process/ConvertTokens.php
+    if (!is_array($value)) {
+      return str_replace(array_keys($tokens), $tokens, $value);
+    }
+    else {
+      throw new MigrateException(sprintf('%s is an array', var_export($value, TRUE)));
+    }

I find this error message awkward. Can we change the !is_array() to just is_string(), change the exception to "Value must be a string" or similar, and remove the var_export(), since that will muddy up the exception message and make it difficult to read?

+++ b/core/modules/user/src/Tests/Migrate/d6/MigrateUserConfigsTest.php

Nice assertions -- very thorough. For bonus points, can we also add a test which checks that the plugin will throw an exception if given an array (or other non-string)? It should look something like this (in PHPUnit we would just use @expectedException, but we're not quite there yet):

public function testExceptionFromInvalidArgument() {
  try {
    $plugin->transform($invalid_value);
    $this->fail('Did not catch expected MigrateException when trying to transform invalid value.');
  }
  catch (MigrateException $e) {
    $this->pass('Caught expected MigrateException when trying to transform invalid value.');
  }
}

I have it from @xjm that this is kosher in SimpleTest.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new15.06 KB
new1.15 KB

1. Fixed
2. Fixed
3. Fixed
4. Fixed
5. Thx. No bonus points yet. I've not figure out how to create $plugin, as in your example.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Works for me.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

No longer applies.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new15.06 KB

Simple reroll, not tested locally.
No interdiff, due to changes in Variable.php

quietone’s picture

Status: Needs review » Reviewed & tested by the community

As agreed on IRC, set to RTBC

webchick’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs reroll

Committed and pushed to 8.0.x. Thanks!

  • webchick committed ac15de3 on 8.0.x
    Issue #2551631 by quietone, Ryan Weal, phenaproxima: D6 user_mail tokens...

Status: Fixed » Closed (fixed)

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

quietone’s picture

Assigned: quietone » Unassigned