Issue Bug Closed

#88696DataHandler getSortNumber use of increaseSortingOfFollowing wrong

F Altrock 07/05/19, 16:49 updated 07/23/19, 11:03

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:

https://github.com/TYPO3-CMS/core/blob/36060d9992e72a43ef398b6b33e9099a216a686d/Classes/DataHandling/DataHandler.php#L6845

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

https://github.com/TYPO3-CMS/core/blob/36060d9992e72a43ef398b6b33e9099a216a686d/Classes/DataHandling/DataHandler.php#L6941

(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.