Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the 'uniquePerSite' is set recalculate unique_fields key values #30281

Closed
Tracked by #29459
freddyDOTCMS opened this issue Oct 7, 2024 · 3 comments · Fixed by #30693 or #30730
Closed
Tracked by #29459

When the 'uniquePerSite' is set recalculate unique_fields key values #30281

freddyDOTCMS opened this issue Oct 7, 2024 · 3 comments · Fixed by #30693 or #30730

Comments

@freddyDOTCMS
Copy link
Contributor

freddyDOTCMS commented Oct 7, 2024

Parent Issue

#29459

User Story

If in a unique fields the uniquePerSite field variable is changed then be need recalculated the unique_key hash values for the unique_table, to include or exclude the host id according to the new value.

We need to create a API/Factory methods to do this.

Acceptance Criteria

  • Recalculate all the hash after the uniquePerSite field variable is changed

Proposed Objective

Core Features

Proposed Priority

Priority 2 - Important

External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

No response

Assumptions & Initiation Needs

No response

Quality Assurance Notes & Workarounds

Steps to Reproduce:

  • Start up dotCMS with the following env var:
DOT_FEATURE_FLAG_DB_UNIQUE_FIELD_VALIDATION: 'true'
  • Make sure the unique_field table exists. So, run a CURL like this one:
curl --location 'http://localhost:8080/api/v1/upgradetask' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic YWRtaW5AZG90Y21zLmNvbTphZG1pbg==' \
--header 'Cookie: JSESSIONID=CF31A5750F5C83785EBC8EA3B8D8CF85; rme=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0NjE3NmUxMi02YzJkLTQwNmMtYjcyNC00ZGZhYzQ1NjI1MTciLCJ4bW9kIjoxNzMyMTM2NTY5MzQyLCJzdWIiOiJkb3RjbXMub3JnLjEiLCJpYXQiOjE3MzIxMzY1NjksImlzcyI6IjM1NGNkOTg4NDQiLCJleHAiOjE3MzIyMjI5Njl9.A6rfTdWfSo-Sok7XcifcZAnJ6UMs6wtslLvuejeTfX0' \
--data '{
    "upgradeTaskClass": "com.dotmarketing.startup.runonce.Task241007CreateUniqueFieldsTable"
}'
  • Create a test Content Type named My CT with two fields:
    • Site or Folder, named Site
    • Text, named Title, and marked as Unique, and add a Field Variable named uniquePerSite with the value of true.
  • Create an empty Site named www.empty.com.
  • Create two Contentlets of type My CT, with THE SAME VALUE for the unique field, but one living under demo.dotcms.com and the other one living under www.empty.com. They must be created without problem.
  • Now, go to the definition of the Title field, and delete the uniquePerSite Field Variable.
  • You'll see an error message and notifications indicating that the unique field cannot be recalculated, which is expected. This happens because both Contentlets you created have the same unique value.

No response

Sub-Tasks & Estimates

No response

@jcastro-dotcms jcastro-dotcms moved this from In Progress to In Review in dotCMS - Product Planning Nov 18, 2024
github-merge-queue bot pushed a commit that referenced this issue Nov 20, 2024
…able is set, recalculate key values in the `unique_fields` table (#30693)

### Proposed Changes
* When the 'uniquePerSite' Field Variable is added, updated, or deleted,
recalculate key values in the `unique_fields` table.
* After discussion with Freddy R, the hash calculation has been moved
from Java code to PostgreSQL code.
* UI Notifications/ Toasts are being added when the new hash is being
calculated, and when it finishes.
* Added new and formatted existing Javadoc.
@github-project-automation github-project-automation bot moved this from In Review to Internal QA in dotCMS - Product Planning Nov 20, 2024
@jcastro-dotcms jcastro-dotcms removed their assignment Nov 20, 2024
@github-project-automation github-project-automation bot moved this from Internal QA to Current Sprint Backlog in dotCMS - Product Planning Nov 20, 2024
@jcastro-dotcms jcastro-dotcms moved this from Current Sprint Backlog to Internal QA in dotCMS - Product Planning Nov 20, 2024
@jcastro-dotcms jcastro-dotcms moved this from Internal QA to In Progress in dotCMS - Product Planning Nov 20, 2024
@jcastro-dotcms jcastro-dotcms self-assigned this Nov 20, 2024
jcastro-dotcms added a commit that referenced this issue Nov 21, 2024
@jcastro-dotcms jcastro-dotcms moved this from In Progress to In Review in dotCMS - Product Planning Nov 21, 2024
github-merge-queue bot pushed a commit that referenced this issue Nov 21, 2024
… field recalculation (#30730)

### Proposed Changes
* Improving the way errors are reported for unique validation
recalculation.
@victoralfaro-dotcms
Copy link
Contributor

victoralfaro-dotcms commented Nov 26, 2024

Tested in dotcms/dotcms:trunk_e9c8559
After run curl command:

{"entity":"Ran the upgrade task: com.dotmarketing.startup.runonce.Task241007CreateUniqueFieldsTable","errors":[],"i18nMessagesMap":{},"messages":[],"pagination":null,"permissions":[]}

Logs:

dotcms-app-1  | 21:32:08.615  INFO  system.UpgradeTaskResource - Running the upgrade task: com.dotmarketing.startup.runonce.Task241007CreateUniqueFieldsTable
dotcms-app-1  | 21:32:08.703  INFO  system.UpgradeTaskResource - Ran the upgrade task: com.dotmarketing.startup.runonce.Task241007CreateUniqueFieldsTable

A Content Type was created with two fields: Title and Site. For the Title field we defined a field variable called uniquePerSite and it was set to true.
Created a new site.
Created two contents (of the recent created Content Type) one the demo.dotcms.com site and the other in the new site.
Went to edit the Content Type and tried to delete uniquePerSite field variable.
Error message when trying to delete the uniquePerSite field variable when there was already a content with the same unique field in a different site.
image

SHA before changes: d5c4e3130c61fd48ef51f5ac666d590d6186b77e24bbf76667960a2aee4694ae
After manually removing the record holding the same unique field the deletion of the field variable was allowed and therefore the hash was recalculated.
SHA after changes: 8db02dab81f332cf6bb24babbb39253063ce6569db7e32c3ced5758b9789d9ec

JSON after changes
image

@victoralfaro-dotcms victoralfaro-dotcms moved this from Internal QA to QA - Backlog in dotCMS - Product Planning Nov 26, 2024
@victoralfaro-dotcms victoralfaro-dotcms removed their assignment Nov 26, 2024
@josemejias11 josemejias11 moved this from QA - Backlog to QA - In Progress in dotCMS - Product Planning Nov 26, 2024
@josemejias11
Copy link
Contributor

Approved: Tested on trunk_e15f58e, Docker, macOS 14.5, FF v126.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment