//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 async Task <bool> UpdatedAsync(ContentItem term, ContentItem taxonomy) { if (term.ContentType != ContentTypes.PageLocation) { return(true); } List <ContentItem> allPages = await _contentItemsService.GetActive(ContentTypes.Page); List <ContentItem> associatedPages = allPages.Where(x => x.Content.Page.PageLocations.TermContentItemIds[0] == term.ContentItemId).ToList(); var groups = associatedPages.GroupBy(x => x.ContentItemId); foreach (var group in groups) { var pages = group.ToList(); foreach (var page in pages) { //rebuild the Full URL to ensure it matches the current state of the term var pageUrlName = page.As <PageLocationPart>().UrlName; var termUrl = _taxonomyHelper.BuildTermUrl(JObject.FromObject(term), JObject.FromObject(taxonomy)); var fullUrl = string.IsNullOrWhiteSpace(termUrl) ? $"/{pageUrlName}" : $"/{termUrl}/{pageUrlName}"; page.Alter <PageLocationPart>(part => part.FullUrl = fullUrl); _session.Save(page); } try { if (pages.Count > 1) { var publishedPage = pages.Single(x => x.Published); var draftPage = pages.Single(x => x.Latest); if (!await _syncOrchestrator.Update(publishedPage, draftPage)) { _session.Cancel(); } } else { var page = pages.Single(); if (page.Published && !await _syncOrchestrator.Publish(page)) { _session.Cancel(); } else if (!page.Published && !await _syncOrchestrator.SaveDraft(page)) { _session.Cancel(); } } } catch (Exception) { _session.Cancel(); return(false); } } return(true); }