You are here

function user_update_7017 in Drupal 7

Update email templates to use new tokens.

This function upgrades customized email templates from the old !token format to the new core tokens format. Additionally, in Drupal 7 we no longer e-mail plain text passwords to users, and there is no token for a plain text password in the new token system. Therefore, it also modifies any saved templates using the old '!password' token such that the token is removed, and displays a warning to users that they may need to go and modify the wording of their templates.

Related topics

File

modules/user/user.install, line 871
Install, update and uninstall functions for the user module.

Code

function user_update_7017() {
  $message = '';
  $tokens = array(
    '!site' => '[site:name]',
    '!username' => '[user:name]',
    '!mailto' => '[user:mail]',
    '!login_uri' => '[site:login-url]',
    '!uri_brief' => '[site:url-brief]',
    '!edit_uri' => '[user:edit-url]',
    '!login_url' => '[user:one-time-login-url]',
    '!uri' => '[site:url]',
    '!date' => '[date:medium]',
    '!password' => '',
  );
  $result = db_select('variable', 'v')
    ->fields('v', array(
    'name',
  ))
    ->condition('name', db_like('user_mail_') . '%', 'LIKE')
    ->execute();
  foreach ($result as $row) {

    // Use variable_get() to get the unserialized value for free.
    if ($value = variable_get($row->name, FALSE)) {
      if (empty($message) && strpos($value, '!password') !== FALSE) {
        $message = t('The ability to send users their passwords in plain text has been removed in Drupal 7. Your existing email templates have been modified to remove it. You should <a href="@template-url">review these templates</a> to make sure they read properly.', array(
          '@template-url' => url('admin/config/people/accounts'),
        ));
      }
      variable_set($row->name, str_replace(array_keys($tokens), $tokens, $value));
    }
  }
  return $message;
}