Problem/Motivation
When adding a new unpublished content entity in a workspace, the workspace revision metadata field on the entity is not set, resulting in the content being attributed to 'Live'. The content is still attached to the workspace in a workspace_association table row.
As things stand if a user is in a workspace and creates a piece of content it does not appear in that workspace when using views that filter by workspace.
SELECT * FROM node_revision WHERE nid = 1; SELECT * FROM workspace_association WHERE target_entity_id = 1;
nid vid langcode revision_uid revision_timestamp revision_log revision_default workspace
---------- ---------- ---------- ------------ ------------------ ------------ ---------------- ----------
1 1 en 1 1587501174 1
workspace target_entity_type_id target_entity_id target_entity_revision_id
---------- --------------------- ---------------- -------------------------
stage node 1 1
This workspace field is set when
- A new revision is created on an existing entity
- A new published entity is created
Proposed resolution
Track the initial revisions created in a workspace, for both published and unpublished entities.
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | interdiff-23.txt | 1.89 KB | amateescu |
| #23 | 3129762-23.patch | 24.68 KB | amateescu |
| #23 | interdiff-for-test-only-patch.txt | 1022 bytes | amateescu |
| #23 | 3129762-23-test-only.patch | 6.37 KB | amateescu |
| #20 | interdiff-20.txt | 12.72 KB | amateescu |
Comments
Comment #2
alexj12 commentedComment #4
msutharsComment #5
alexj12 commentedThis failing test appears to indicate the revisions are not expected to be associated with the workspace. This seems somewhat illogical, if you create a new piece of content in a workspace you would expect at least one revision to be within the workspace even if it is unnpublished.
There is also a mismatch with this functionality, the workspace association suggests the revision is in the workspace but the workspace field does not.
Just need some steer as to what the preferred functionality should be.
Comment #6
msuthars@Alexj12 Yes because of this functionality when nodes are created as unpublished then it is not creating any revision in the live for those nodes.
Comment #7
msutharsI just remove the assetCount for live revision, because after adding this functionality there will no live revision will created.
Comment #8
msutharsComment #14
amateescu commentedThis problem was also discovered in #3092247: Prevent content from being deleted when there is an active workspace. I will bring over the relevant changes from that issue to this one because the fix is a bit more involved than the current patch.
Comment #15
amateescu commentedLet's start with explicit test coverage for this bug, and the fixes required for it.
The second patch will fail _other_ tests because we need to update that test coverage to account for the change we're introducing: when creating a new entity in a workspace, either published or unpublished, the initial revision will now be considered as part of the workspace.
Leaving at needs work for now, will followup with the complete patch.
Comment #16
adriancidI had these errors while testing the patch, so I added a validation to check for the existence of the element in the array:
Comment #17
adriancidFixing a problem with undefined $workspace_candidates.
Comment #18
amateescu commentedThe test-only patch from #15 was flawed, it didn't take into account editing an existing entity in a workspace. Reworked the test coverage to cover all cases, and this shows that we can't check for "initial revisions" (of the entities that are created in a workspace) at the moment.
Comment #19
amateescu commentedThese are the fixes needed for the test-only patch from #18. As mentioned in #15, some other tests will fail because workspaces are now tracking initial default revisions, and I will follow up with a complete patch.
Comment #20
amateescu commentedHere are the changes needed to fix the existing test coverage. This is fully ready for reviews now.
Comment #21
adriancidWe are using this patch in a production site and is working as expected. I know usually it needs some screenshots but I can confirm is working.
Comment #22
larowlanThere's some API changes here (new arguments to plugin constructors, new methods).
Whilst we don't have to provide a BC layer, it would be nice to add a change notice, so tagged for that.
We've not had a test-run that shows the new tests fail yet (they didn't pass the custom checks so tests didn't run) - so can we get a red/green set of patches - ie one with just the tests, and one with tests and fixes.
Couple of minor observations
Can we get typehints here for new code
should we try to do this in bulk outside the foreach loop?
Comment #23
amateescu commentedGood point about the CR, wrote one here: https://www.drupal.org/node/3352703
Attaching the test-only patch from #18 with the custom checks fixed, as well as the complete one from #20 with the point from #22.1 fixed.
I thought a lot about #22.2 while working on this patch and eventually settled on the argument that this is "just" cleanup code that usually runs on cron, and that it's better to be correct and easy to read rather than fast. Loading multiple default revisions would only save a few cache gets anyway :)
Comment #26
catchThis is tricky but the changes look solid and agreed the CR is plenty for the changes.
Committed/pushed to 10.1.x, thanks!
Comment #27
quietone commentedI published the change record