Problem/Motivation
This was proposed by @FabianX in #2784921-151: Add Workspaces experimental module.10:
+++ b/core/modules/workspace/src/Plugin/RepositoryHandler/LiveRepositoryHandler.php @@ -0,0 +1,196 @@ + // Get the latest revision IDs for all the entities that are tracked by + // the source workspace. + $query = $this->entityTypeManager + ->getStorage($entity_type_id) + ->getQuery() + ->condition($entity_type->getKey('id'), $tracked_revisions, 'IN') + ->latestRevision();
While this current is not a problem, if we ever wanted to also act on latestRevision() (I get that comment now), we should explicitly specify to override the currently active workspace, so that we compare with whatever workspace we want to compare against (currently default / live):
e.g.
In cps we have:
cps_override_changeset('published');
// ...
cps_override_changeset(NULL);
---
For better code flow I would suggest to use a closure:
$this->workspaceManager->executeInWorkspace(::DEFAULT_WORKSPACE, function() { // Do queries and entity operations against the live site. });
We tried to avoid that in CPS at first, but it ended up to be necessary and useful.
Proposed resolution
Add a executeInWorkspace()
method to the workspace manager which receives two arguments, a workspace ID and a closure.
Remaining tasks
TBD.
User interface changes
Nope.
API changes
Nope.
Data model changes
Nope.
Comment | File | Size | Author |
---|---|---|---|
#22 | interdiff-22.txt | 3.75 KB | amateescu |
#22 | 2968452-22.patch | 6.88 KB | amateescu |
#17 | interdiff-17.txt | 1.17 KB | amateescu |
#17 | 2968452-17.patch | 7.02 KB | amateescu |
#12 | interdiff-12.txt | 1.23 KB | amateescu |
Comments
Comment #2
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedComment #3
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@FabianX, is this what you had in mind?
Comment #4
timmillwoodI think this should use the
getActiveWorkspace()
andsetActiveWorkspace()
methods, then we can remove the duplicate access check too.Comment #5
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI did not use those methods on purpose because they're doing quite some additional work. For example,
WorkspaceManager::setActiveWorkspace()
also callssetActiveWorkspace()
on the negotiators in order to persist that workspace, and we don't really want do to that.Comment #6
timmillwoodWouldn't we want it to persist until we switch it back :)
Comment #7
Fabianx CreditAttribution: Fabianx as a volunteer commentedYes, that is what I had in mind:
We absolutely need to use something like setActiveWorkspace though, because we for example need to clear the (in-memory) entity cache before switching.
See:
cps_override_changeset()
I however don't think we should inform negotiators of a changed workspace - as that really should not persist - even if the operation inside errors out (unexpected to the user).
Comment #9
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedFix component following module rename.
Comment #10
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedAdded a way to not persist the workspace in
setActiveWorkspace()
and test coverage. We should good to go here :)Comment #11
jeqqShouldn't it return here what $function() returns?
Comment #12
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedVery good point! Let's do that.
Comment #13
jeqqLooks good.
Comment #15
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThis would have been a neat area that #2982949: Introduce CallableResolver to help standardise the DX and error handling for callbacks across various subsystems could have helped provide some utility. Vanilla callables need bridges to container injected classes to be unit testable. That's stalled for now though, so this issue is fine as it is.
Comment #16
larowlancan we use
$(live|stage)_node->(revisionId|id)()
here to avoid fragility in the test and make it explicit what these integers represent?Comment #17
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedSure thing! Moving back to RTBC because it's a very simple change :)
Comment #18
alexpottAre we sure that we want to expose the persist option as API? I think that might lead to errors.
Comment #19
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI don't see why not, it could be actually useful IMO. A theoretical use case could be a custom workspace negotiator or link used in an email that only allows a user to see a single page in the context of a given workspace, without persisting it if the user navigates away from that page.
Comment #20
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThis is currently blocking #2998414: Workspaces fails to deploy content in fields that required dedicated table storage.
Comment #21
larowlanI'm with alexpott on this. Let's not make persist part of the public API until we have a need for it.
We can make the elements of setActiveWorkspace that do the switching (but not the persisting) a separate protected function (such as doSwitchWorkspace) and then call that from executeInWorkspace, that way we keep the surface smaller
Comment #22
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedOkay :)
Comment #23
larowlanCommitted bc3348b and pushed to 8.7.x. Thanks!
Comment #25
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedSince Workspaces is experimental, I think this can be backported to 8.6.x, even more since it blocks a bug fix. #2998414: Workspaces fails to deploy content in fields that required dedicated table storage
Comment #26
alexpottYeah as an experimental module we should backport this.