#88696DataHandler getSortNumber use of increaseSortingOfFollowing wrong
Description
Bug description
After copying a page, a single content element is sorted at the very top instead of where it was previously.
Inspecting the sorting column in the List module reveals a sorting value of 0 for this one content element.
Impact
AFAICS the bug was introduced by https://review.typo3.org/c/Packages/TYPO3.CMS/+/57218/ in August 2018, so
all versions of TYPO3 since 9.4.0 are affected.
Repro setup:
- Create a page with 11 content elements, for example 11 headers with numbers 1-11.
- Check that the sorting is correct in the list module.
(see first screenshot) - Copy the page into the clipboard
- Paste the page anywhere, paste mode is not important
- Check the sorting of the content elements in the new page
- See that heading “2” has been sorted at the very top with sorting 0
(see second screenshot)
Source of the bug
The method getSortNumber of class DataHandler checks for the minimum sorting value in a table
when inserting a new record and halves the value for the new record. When copying a page, the first
record gets the value 256, thus after 10 records we are at sorting value 0.
The 11th record then triggers a re-sorting via the method increaseSortingOfFollowing:
but crucially the value 0 is passed for the sortingValue, and that method:
> Increases sorting field value of all records with sorting higher than $sortingNumber
(Aside: the parameter variable name should be $sortingValue here.)
Fix
getSortNumber should use -1 as the sortingValue passed to increaseSortingOfFollowingRecords.
This way all records in the new page get re-sorted, not just the ones with a sorting value > 0.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.