public override async Task DraftSavedAsync(SaveDraftContentContext context)
        {
            if (context.ContentItem.ContentType == "Page" && Convert.ToBoolean(context.ContentItem.Content.PageLocationPart.DefaultPageForLocation.Value))
            {
                IContentManager contentManager = _serviceProvider.GetRequiredService <IContentManager>();

                //TODO : find out how to query for only pages marked as default - probably need to make a new index
                var pages = await _session.Query <ContentItem, PageLocationPartIndex>(x => x.ContentItemId != context.ContentItem.ContentItemId).ListAsync();

                foreach (var page in pages.Where(x => x.Content.Page.PageLocations.TermContentItemIds[0] == context.ContentItem.Content.Page.PageLocations.TermContentItemIds[0]))
                {
                    var latestPreview = await _previewContentItemVersion.GetContentItem(contentManager, page.ContentItemId);

                    if (latestPreview != null && Convert.ToBoolean(latestPreview.Content.PageLocationPart.DefaultPageForLocation.Value))
                    {
                        latestPreview !.Content.PageLocationPart.DefaultPageForLocation.Value = false;

                        await contentManager.SaveDraftAsync(latestPreview);

                        if (latestPreview.Published)
                        {
                            await SyncToPreviewGraph(latestPreview);
                        }
                    }
                }
            }
        }
Example #2
0
        public async Task SaveDraftAsync(ContentItem contentItem)
        {
            if (!contentItem.Latest || contentItem.Published)
            {
                return;
            }

            var context = new SaveDraftContentContext(contentItem);

            await Handlers.InvokeAsync((handler, context) => handler.DraftSavingAsync(context), context, _logger);

            _session.Save(contentItem, checkConcurrency: true);

            await ReversedHandlers.InvokeAsync((handler, context) => handler.DraftSavedAsync(context), context, _logger);
        }
Example #3
0
 //todo: there's no DraftSavingAsync (either add it to oc, or raise an issue)
 public override async Task DraftSavedAsync(SaveDraftContentContext context)
 {
     try
     {
         if (!await _syncOrchestrator.SaveDraft(context.ContentItem))
         {
             // sad paths have already been notified to the user and logged
             Cancel(context);
         }
     }
     catch (Exception ex)
     {
         // we log the exception, even though some exceptions will have already been logged,
         // as there might have been an 'unexpected' exception thrown
         _logger.LogError(ex, "Exception saving draft.");
         Cancel(context);
     }
 }
 public override Task DraftSavedAsync(SaveDraftContentContext context)
 => RecordAuditTrailEventAsync(ContentAuditTrailEventConfiguration.Saved, context.ContentItem);
Example #5
0
 public override Task DraftSavedAsync(SaveDraftContentContext context)
 {
     return(TriggerWorkflowEventAsync(nameof(ContentDraftSavedEvent), context.ContentItem));
 }