Problem/Motivation
This issue is a follow-up issue to create a hook_update to remove duplicated entries in the password_policy_history table.
The problem was fixed in #3095980: Password history policy inserts password twice in password_policy_history table but it was not created the hook_update there.
Steps to reproduce
This issue exists for sites those who already have the module installed or those not using the latest dev.
- Install version composer require 'drupal/password_policy:^3.1' (Current Release) as of 06/07/2022
- Configure the module to have a site policy
- Create a new user or edit password of the existing user
- Check the password_policy_history table there will be duplicate entries of the same user request

- Note: this issue has been fixed https://www.drupal.org/project/password_policy/issues/3095980 and is avaliable in latest dev 'drupal/password_policy:3.x-dev@dev'
- But it does not handle the already existing entries made before the fixed
- Apply the patch from below MR
- The duplicate entries will be removed.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | queries-output.png | 82.55 KB | lucassc |
| #12 | drush-updb-output.png | 50.91 KB | lucassc |
| #5 | Screenshot 2022-07-01 at 15.23.11.png | 109.48 KB | the_g_bomb |
Issue fork password_policy-3266140
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
lamp5Hi @paulocs, please correct me if I am wrong but after update from #3095980: Password history policy inserts password twice in password_policy_history table,
isSubmited() is always false so there is no way to update your password policy fields value during user update. Could you reopen #3095980: Password history policy inserts password twice in password_policy_history table to check this problem?
Comment #5
the_g_bomb commentedHi @lamp5,
I think because the submit handler has been replaced with a validation handler then the submit functions still trigger as normal.
As can be seen from my screenshots in https://www.drupal.org/project/password_policy/issues/3269065#comment-14...
and I have checked in the password_policy_history table as well, the passwords do seem to add entries as expected.
Comment #6
joshua1234511Tested the MR
- Result : Duplicate entires are removed.
Steps followed
- Installed version composer require 'drupal/password_policy:^3.1' (Current Release) as of 06/07/2022
- Configure the module to have a site policy
- Created a new user/existing and updated the password of the existing user (Did this for at least 3 different users)
- Checked the password_policy_history table and found duplicate entries of the same user request
- Note: this issue has been fixed https://www.drupal.org/project/password_policy/issues/3095980 and is avaliable in latest dev 'drupal/password_policy:3.x-dev@dev'
- Applied the patch from the above issue.
- The duplicate entries are removed.
Making this as RTBC
Comment #7
kristen polThanks @joshua1234511. Did you review the code? Moving back for now.
Comment #8
paulocsActually the fields are properly updated @lamp5.
If you submit the form, the validation handler is called and
$form_state->isSubmitted()returnsTRUE.Comment #9
paulocsI have done a review but the hook_update should be changed:
1)
database()->delete()does not support join statements so a static query should be created2) We should check if the password_policy_history module is enabled before running the query
I'm removing @joshua1234511 credit as it seems he did not run the update hook as it would fail with the code as it is.
Comment #10
paulocsComment #11
lucasscComment #12
lucasscHi!
I had some trouble setting my environment. Here's the steps I used to reproduce it:
2) check out branch 8.x-3.x
3) install password_policy and ctools
4) install password_policy_history
5) duplicate entries in database
6) check out 3266140-create-hookupdate-to
7) run
drush updbAttaching screenshots of results from
drush updband its effects on the database.Marked as RTBC.
Comment #14
paulocsThank you!
Comment #16
andypostthis hook is mysql specific and fails of sqlite
Comment #17
andypostThere's docs for it https://www.drupal.org/docs/7/guidelines-for-sql/writing-code-compliant-...
Comment #18
the_g_bomb commentedGood catch @andypost. I suspect a new ticket will need to be opened to address that.
In the meantime altering the code to read
may probably work.
I can create a new MR if a new ticket is created.
Comment #19
guardiola86 commentedThis seems to be related? https://www.drupal.org/project/password_policy/issues/3325587