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

[4.3] Fix wrong lft and rgt values in assets table #40237

Merged

Conversation

richard67
Copy link
Member

@richard67 richard67 commented Mar 29, 2023

Pull Request for Issue #40208 (comment) .

Summary of Changes

This pull request (PR) corrects the following two mistakes with lft and rgt values for the nested #__assets table for new installations:

  1. There are two assets with IDs 46 and 67 which have the same lft value 74 and rgt value 75.
    https://github.com/joomla/joomla-cms/blob/4.3-dev/installation/sql/mysql/base.sql#L70
    https://github.com/joomla/joomla-cms/blob/4.3-dev/installation/sql/mysql/base.sql#L89
    Both are assets for single modules on level 2 below the 'com_modules' asset.
    This error was introduced with PR Fixing #__assets table #30178 , possibly not with the initial version of that PR but when resolving merge conflicts with the base branch.
    Because the same PR had removed some obsolete assets, we are lucky and the lft and rgt values 78 and 79 are not used, so they are a gap on that level with that parent, which as such is not a problem but helps here to fix the issue. We can change the the lft and rgt values of asset ID 67 and 68 to the previous values plus one, and so that gap is filled, too, and the nested table is correct.
  2. The rgt value of the root asset, which is the parent of all others, has to be equal to the rgt value of it's last child plus one, so currently it should be 177, see these two places for the root item and the last child:
    https://github.com/joomla/joomla-cms/blob/4.3-dev/installation/sql/mysql/base.sql#L28
    https://github.com/joomla/joomla-cms/blob/4.3-dev/installation/sql/mysql/base.sql#L115
    This error was introduced with PR GSoC’22 project: Guided Tours #39902 .
    When the rgt value of the root asset is smaller than the one of the last child, it is not updated to a new value when a new asset is added for something, e.g. by creating a new category or installing a new module and then editing that asset. This can also be seen when reproducing issue [4.3] guided tours - assets table #40199 .

Testing Instructions

Testers need to know and have understood the principles of hierarchical tables using the nested set model as described here:

https://en.wikipedia.org/wiki/Nested_set_model

The #__assets table uses an extended model which saves as redundant information also parent_id and level in addition to lft and rgt for speeding up certain queries.

As the structure of the assets table is only a few levels deep, the nested table can be easily verified in tools like phpMyAdmin or phpPgAdmin.

For this you can either make a new installation with the branch of this PR, or you simply use an empty database and execute the statements to create the assets table and insert the records from the base.sql file of this PR.

Then you select all records from the table and order by the lft column in ascending order. Make sure that really all records are shown.

Then go through the lft and rgt values from top to bottom and lft to rgt, and when at the end of a child level from the last rgt value on that level back to the rgt value of the parent further above. So just follow the lft and rgt values as described on this Wikipedia page about the nested model. Check that the sequence of lft and rgt values is according to that model and that the parent ID and the level are correct, too.

Check that the changes of this PR are correct.

For issue 2. you can also add a new asset e.g. by adding a new category or by reproducing issue #40199 . Make sure that the rgt value of the root asset is updated, too, when the new asset is added.

Actual result BEFORE applying this Pull Request

  1. There are 2 assets with the same lft and rgt values 74 and 75: Asset ID 46 and asset ID 67. There is no asset with lft and rgt values 78 and 79.
  2. The rgt value 175 of the root asset is smaller than the rgt value 176 of its last child, which is asset ID 95. So when a new assets is created, the rgt value of the root item is not updated.

Expected result AFTER applying this Pull Request

  1. There are no assets with the same lft and rgt values as other assets have. All lft and rgt combinations are unique and follow the nested set model, and there is no gap, at least not within the modules assets.
  2. The rgt value 177 of the root asset is equal to one plus the rgt value 176 of its last child, which is asset ID 95. So when a new assets is created, the rgt value of the root item is updated.

Link to documentations

Please select:

  • No documentation changes for docs.joomla.org needed

  • No documentation changes for manual.joomla.org needed

@richard67 richard67 changed the title [4.3] [WiP] Fix wrong lft and rgt values in assets table [4.3] Fix wrong lft and rgt values in assets table Mar 29, 2023
@richard67 richard67 marked this pull request as ready for review March 29, 2023 17:48
@khu5h1
Copy link
Contributor

khu5h1 commented Mar 29, 2023

I have tested this item ✅ successfully on cd26415


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/40237.

1 similar comment
@obuisard
Copy link
Contributor

I have tested this item ✅ successfully on cd26415


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/40237.

@richard67
Copy link
Member Author

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/40237.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Mar 30, 2023
@obuisard obuisard added this to the Joomla! 4.3.0 milestone Mar 30, 2023
@obuisard obuisard merged commit e65d284 into joomla:4.3-dev Mar 30, 2023
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Mar 30, 2023
@obuisard
Copy link
Contributor

Thanks for the PR Richard @richard67. Great instructions as well, worth keeping.

@richard67 richard67 deleted the 4.3-dev-fix-asset-table-root-item-rgt branch March 30, 2023 15:58
Denitz pushed a commit to Denitz/joomla-cms that referenced this pull request Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants