Add Cancel to CreateContentContext
I came up with a scenario where I must cancel creating a content item if something goes wrong. Today, PublishContentContext already has Cancel property, which is good
I can submit a PR if there's no objection
/cc @MikeAlhayek @gvkries
I am not sure it's needed. Create saves the content item in the session (but does not commit the changes). So if you want to cancel the request, you can call _session.CancelAsync() which will cancel the request.
For example you can do this
// Stage the content item to be created
await _contentManager.CreateAsync(contentItem, VersionOptions.Draft);
// this will cancel the creation.
await _session.CancelAsync();
I wrote my code in the ContentHandler, I don't want to publish or make the content type as draft
_session.CancelAsync() will work anywhere, also in a handler. But I don't think it's too nice to cancel the transaction if we can better.
However, what's the scenario that this would solve that PublishContentContext.Cancel doesn't?
_session.CancelAsync()
I did it as my last attempt, but I ended up with Page is not found
However, what's the scenario that this would solve that PublishContentContext.Cancel doesn't?
If I have such a Cancel property, I could easily revert the item creation
Yeah, but what's the full scenario? What's the user need you can't address now? But additionally, why do you want to cancel the creation as opposed to the publishing, what happens during creation that you want to avoid?
I have a manager who adds employees. Once the employee is created, a user is created behind the scenes. Sometimes a user is not created for some reason, for example email is already in use. What I want is to go to the edit page and show an alert when something goes wrong, but now the employee is created even the user is not
That user creation should rather happen after publishing, in PublishedAsync. Create is too early and at that point it's by far not certain that the content item will be saved.
The problem is when I cancel on publishing, the item will moved into a draft which is not expected
I see, and yes, now I see why such a cancel would be useful.
I will submit a PR for this
We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).
This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.