From dc75725b71c477ee04dc2fb5233da7621c08c32c Mon Sep 17 00:00:00 2001 From: webchick Date: Wed, 1 Jun 2011 09:51:06 -0700 Subject: [PATCH] Issue #1014262 by Eric_A, asimmonds: Fixed user_update_7011() completely broken (User email template tokens not upgraded). --- modules/simpletest/simpletest.info | 1 + ...upal-6.user-no-password-token.database.php | 10 +++ .../drupal-6.user-password-token.database.php | 10 +++ .../tests/upgrade/upgrade.user.test | 60 +++++++++++++ modules/user/user.install | 88 +++++++++++-------- 5 files changed, 132 insertions(+), 37 deletions(-) create mode 100644 modules/simpletest/tests/upgrade/drupal-6.user-no-password-token.database.php create mode 100644 modules/simpletest/tests/upgrade/drupal-6.user-password-token.database.php create mode 100644 modules/simpletest/tests/upgrade/upgrade.user.test diff --git a/modules/simpletest/simpletest.info b/modules/simpletest/simpletest.info index 015542208a81..f51804c90cc7 100644 --- a/modules/simpletest/simpletest.info +++ b/modules/simpletest/simpletest.info @@ -46,3 +46,4 @@ files[] = tests/upgrade/upgrade.menu.test files[] = tests/upgrade/upgrade.node.test files[] = tests/upgrade/upgrade.taxonomy.test files[] = tests/upgrade/upgrade.upload.test +files[] = tests/upgrade/upgrade.user.test diff --git a/modules/simpletest/tests/upgrade/drupal-6.user-no-password-token.database.php b/modules/simpletest/tests/upgrade/drupal-6.user-no-password-token.database.php new file mode 100644 index 000000000000..646319462f70 --- /dev/null +++ b/modules/simpletest/tests/upgrade/drupal-6.user-no-password-token.database.php @@ -0,0 +1,10 @@ +fields(array( + 'name', + 'value', +)) +->values(array( + 'name' => 'user_mail_register_no_approval_required_body', + 'value' => 's:86:"!username, !site, !uri, !uri_brief, !mailto, !date, !login_uri, !edit_uri, !login_url.";', +)) +->execute(); diff --git a/modules/simpletest/tests/upgrade/drupal-6.user-password-token.database.php b/modules/simpletest/tests/upgrade/drupal-6.user-password-token.database.php new file mode 100644 index 000000000000..367c70481d88 --- /dev/null +++ b/modules/simpletest/tests/upgrade/drupal-6.user-password-token.database.php @@ -0,0 +1,10 @@ +fields(array( + 'name', + 'value', +)) +->values(array( + 'name' => 'user_mail_register_no_approval_required_body', + 'value' => 's:97:"!password, !username, !site, !uri, !uri_brief, !mailto, !date, !login_uri, !edit_uri, !login_url.";', +)) +->execute(); diff --git a/modules/simpletest/tests/upgrade/upgrade.user.test b/modules/simpletest/tests/upgrade/upgrade.user.test new file mode 100644 index 000000000000..6c669219a6f6 --- /dev/null +++ b/modules/simpletest/tests/upgrade/upgrade.user.test @@ -0,0 +1,60 @@ + 'User upgrade path (password token involved)', + 'description' => 'User upgrade path tests (password token involved).', + 'group' => 'Upgrade path', + ); + } + + public function setUp() { + // Path to the database dump files. + $this->databaseDumpFiles = array( + drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.bare.database.php', + drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.user-password-token.database.php', + ); + parent::setUp(); + } + + /** + * Test a successful upgrade. + */ + public function testUserUpgrade() { + $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); + $this->assertEqual(variable_get('user_mail_register_no_approval_required_body'), ', [user:name], [site:name], [site:url], [site:url-brief], [user:mail], [date:medium], [site:login-url], [user:edit-url], [user:one-time-login-url].', 'Existing email templates have been modified (password token involved).'); + } +} + +/** + * Upgrade test for user.module (password token not involved). + */ +class UserUpgradePathNoPasswordTokenTestCase extends UpgradePathTestCase { + public static function getInfo() { + return array( + 'name' => 'User upgrade path (password token not involved)', + 'description' => 'User upgrade path tests (password token not involved).', + 'group' => 'Upgrade path', + ); + } + + public function setUp() { + // Path to the database dump files. + $this->databaseDumpFiles = array( + drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.bare.database.php', + drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.user-no-password-token.database.php', + ); + parent::setUp(); + } + + /** + * Test a successful upgrade. + */ + public function testUserUpgrade() { + $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); + $this->assertEqual(variable_get('user_mail_register_no_approval_required_body'), '[user:name], [site:name], [site:url], [site:url-brief], [user:mail], [date:medium], [site:login-url], [user:edit-url], [user:one-time-login-url].', 'Existing email templates have been modified (password token not involved).'); + } +} diff --git a/modules/user/user.install b/modules/user/user.install index df94ad537002..75fca659014f 100644 --- a/modules/user/user.install +++ b/modules/user/user.install @@ -683,46 +683,13 @@ function user_update_7010() { } /** - * Updates email templates to use new tokens. + * Placeholder function. * - * 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. + * As a fix for user_update_7011() not updating email templates to use the new + * tokens, user_update_7017() now targets email templates of Drupal 6 sites and + * already upgraded sites. */ function user_update_7011() { - $message = ''; - - $tokens = array( - '!site-name-token' => '[site:name]', - '!site-url-token' => '[site:url]', - '!user-name-token' => '[user:name]', - '!user-mail-token' => '[user:mail]', - '!site-login-url-token' => '[site:login-url]', - '!site-url-brief-token' => '[site:url-brief]', - '!user-edit-url-token' => '[user:edit-url]', - '!user-one-time-login-url-token' => '[user:one-time-login-url]', - '!user-cancel-url-token' => '[user:cancel-url]', - '!password' => '', - ); - - $result = db_select('variable', 'v') - ->fields('v', array('name', 'value')) - ->condition('value', db_like('user_mail_') . '%', 'LIKE') - ->execute(); - - foreach ($result as $row) { - if (empty($message) && (strpos($row->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 review these templates to make sure they read properly.', array('@template-url' => url('admin/config/people/accounts'))); - } - - variable_set($row->name, str_replace(array_keys($tokens), $tokens, $row->value)); - } - - return $message; } /** @@ -866,6 +833,53 @@ function user_update_7016() { )); } +/** + * 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. + */ +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 review these templates 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; +} + /** * @} End of "addtogroup updates-6.x-to-7.x" */