Problem/Motivation
While migrating a large (active) site with important revision history from D7 to D9, the revision IDs would be out of order as they came in, leading to a broken interface from a user perspective. Considering that the revision ID isn't really the important part from an admin user perspective (and isn't displayed in the admin interface anywhere), changing the sort to timestamp (which is the text to the revision link already) seems reasonable.
Steps to reproduce
(Simplest)
1. View a node with multiple revisions.
2. Change one of the revisions in the `node_revision` table - either swap the IDs or swap the timestamps. (Also easier to see the difference if the timestamps are >1 minute apart).
3. Note that the ordering on the `Revisions` (version-history) tab of the node is out-of-order by date.
Proposed resolution
Add an initial sort on getRevisionMetadataKey('revision_created') and use getKey('revision') as the secondary sort.
Remaining tasks
Add timestamp as primary sortGet all existing tests passing- Add new test coverage?
- Reviews / refinements
- RTBC
- Commit
User interface changes
The revisions tab will be sorted by timestamp instead of revision ID.
API changes
N/A
Data model changes
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 3276716-15-sort-by-revision-timestamp-8.x-1.1.patch | 2.47 KB | gdeguzman |
| #14 | 3276716-14.patch | 2.47 KB | dww |
Issue fork diff-3276716
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
Comment #2
dwwIn principle, this makes total sense to me.
I wonder if there's a more generic way we should determine what
revision_timestampreally is, or if we can just hard code it. The existing code does seem a little bit pointless generalization, if we're only doing this on nodes. ;) But if we're trying to be generic, perhaps something like$node->getEntityType()->getRevisionMetadataKey('revision_created')...Comment #4
gdeguzman commentedThis patch keeps the revision ID as a fallback after sorting by timestamp - particularly useful with tests, which may generate revisions very quickly.
Comment #5
gdeguzman commentedDue to changing the sorting, a test was failing because it was looking for the `Current Revision` in the second row versus the first row.
Comment #6
gdeguzman commentedThis patch adjusts how the revision is obtained as suggested in #2, and fixes tests for Drupal 9.4.
Test changes for 9.4:
Comment #7
dwwThanks for getting the tests passing again! Back to NR. This seems normal, not minor. 😉
Comment #8
dwwUpdating the summary to reflect what the code is now doing, and to update remaining tasks.
I don't think we need a config knob for this behavior. I'm in favor of making this the new default hard-coded sort. However, I'm torn, since flexibility is so important to so many folks around here. 😉 I wonder if there's a clean way to make this query more easily alterable when needed. Probably that part is better as a followup, but worth considering here as we change the default...
Thanks,
-Derek
Comment #9
gdeguzman commentedUpdating the patch to set the `Revert` and `Set to current revision` labels according to the revision timestamp and then the ID, similarly to how the sort is handled.
Comment #10
dwwThe combined patch doesn't apply to the
8.x-1.xbranch, but the approach sounds good.1 minor code style nit:
Seems like there should be a more simple way to write this code, but nothing immediately springs to mind. 😅
Thanks!
-Derek
Comment #13
rpayanmComment #14
dwwThanks for opening the MR and fixing the else, @rpayanm!
Sadly, this shows that the changes here are breaking some existing tests, so needs work for that.
Meanwhile, here's a version of the MR diff as a patch that applies cleanly to 8.x-1.0 for anyone who needs it.
Comment #15
gdeguzman commentedRerolling patch for 8.x-1.1!
Comment #16
agentrickardComment #17
agentrickardWe hit something like this as well, but I want to question the premise of the original report.
Why would a revision id that is higher than another revision have a timestamp that is earlier?
Since revision_id auto increments, there is no reason for this to be the case under normal operations.
This seems like a bug in the way migrations may be handled rather than something that needs to be addressed here.
Comment #18
agentrickardPreferable change -- actually print the revision ID next to the timestamp. (This is part of #3269933: Inconsistent moderation state for translated content) and could be applied here.
Comment #20
heddn+1 on #17/18.
Comment #21
acbramley commentedI agree, core's Node and generic entity revision ui both just sort on revision id. I would like to keep Diff the same.