Event System Handler Code:
[TcmExtension("My Handler")] public sealed class EventSystem : TcmExtension { public EventSystem() { EventSystem.Subscribe<Page, PublishEventArgs>((page, e, phases) => { if (shouldTerminatePublishing(page)) { throw new Exception(ex, page); } }, EventPhases.Initiated, EventSubscriptionOrder.Normal); } }
With the above code, when multiple pages are published, and the event system is only going to block one of them (by throwing an exception), then all pages cannot be published either. The Ignore crashes when creating published content option does not affect this behavior.
How to prevent the publication of any page, but still allow the publication of everything else?
EDIT
Updated code according to Quirijn proposal:
public class MyResolver: IResolver { public void Resolve( IdentifiableObject item, ResolveInstruction instruction, PublishContext context, ISet<ResolvedItem> resolvedItems) { var page = item as Page; if (null != page && instruction.Purpose == ResolvePurpose.Publish) { try {
Some objections (or rather, subsequent questions):
- There is no reasonable way to provide explicit feedback to the user when an item is excluded (except for recommendations on checking the "Show items for publication" option), is there?
- A custom resolver must explicitly consider all types of elements, that is, not only for the "page", but also for "StructureGroup" and "Publication", right?
- Given that evaluation code can be expensive (calling a web service), is there a way to cache it, at least between preparing the Show Items For Publish list and the actual publication? (In this case, the assessment occurs at least two times).
EDIT 2
Studying the implementation of standard solutions:
- Is it necessary / desirable to implement IBulkResolver ?
esteewhy
source share