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
Duplicate entry
- 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.

Command icon 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

paulocs created an issue. See original summary.

the_g_bomb made their first commit to this issue’s fork.

lamp5’s picture

Hi @paulocs, please correct me if I am wrong but after update from #3095980: Password history policy inserts password twice in password_policy_history table,

if (!$form_state->isSubmitted()) {
    return;
  }

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?

the_g_bomb’s picture

Status: Active » Needs review
StatusFileSize
new109.48 KB

Hi @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.

Screenshot of the password_policy_history database table

joshua1234511’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new26.78 KB

Tested 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

kristen pol’s picture

Status: Reviewed & tested by the community » Needs review

Thanks @joshua1234511. Did you review the code? Moving back for now.

paulocs’s picture

Actually the fields are properly updated @lamp5.
If you submit the form, the validation handler is called and $form_state->isSubmitted() returns TRUE.

paulocs’s picture

I 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 created
2) 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.

paulocs’s picture

lucassc’s picture

Assigned: Unassigned » lucassc
lucassc’s picture

Assigned: lucassc » Unassigned
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new50.91 KB
new82.55 KB

Hi!

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 updb

Attaching screenshots of results from drush updb and its effects on the database.

Marked as RTBC.

  • paulocs committed 6d8fcd6 on 8.x-3.x authored by the_g_bomb
    Issue #3266140 by the_g_bomb, paulocs, lucassc, joshua1234511: Create...
paulocs’s picture

Status: Reviewed & tested by the community » Fixed

Thank you!

Status: Fixed » Closed (fixed)

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

andypost’s picture

this hook is mysql specific and fails of sqlite

andypost’s picture

the_g_bomb’s picture

Good catch @andypost. I suspect a new ticket will need to be opened to address that.
In the meantime altering the code to read

$query = \Drupal::database()->query('DELETE t1 FROM {' . $table_name . '} AS t1 USING {' . $table_name . '} AS t2 WHERE t1.id < t2.id AND t1.pass_hash = t2.pass_hash AND t1.timestamp = t2.timestamp');

may probably work.
I can create a new MR if a new ticket is created.

guardiola86’s picture