protected virtual void Published(PublishContentContext context, TPart instance)
 {
 }
 protected virtual void Unpublishing(PublishContentContext context, TPart instance)
 {
 }
 protected override void Unpublished(PublishContentContext context)
 {
     RecordAuditTrailEvent(ContentAuditTrailEventProvider.Unpublished, context.ContentItem);
 }
Пример #4
0
 public override Task UnpublishedAsync(PublishContentContext context)
 {
     return(TriggerContentEvent(ContentEvents.Unpublished, context));
 }
Пример #5
0
 public override Task UnpublishedAsync(PublishContentContext context, AliasPart instance)
 {
     return(_tagCache.RemoveTagAsync($"alias:{instance.Alias}"));
 }
        protected override void Published(PublishContentContext context)
        {
            var previousVersion = context.PreviousItemVersionRecord;

            RecordAuditTrailEvent(ContentAuditTrailEventProvider.Published, context.ContentItem, previousVersion);
        }
Пример #7
0
 public override Task UnpublishedAsync(PublishContentContext context)
 {
     _tagCache.RemoveTag($"contentitemid:{context.ContentItem.ContentItemId}");
     return(Task.CompletedTask);
 }
        private async Task <ContentValidateResult> UpdateContentItemVersionAsync(ContentItem updatingVersion, ContentItem updatedVersion, IEnumerable <ContentItem> evictionVersions = null)
        {
            // Replaces the id to force the current item to be updated
            updatingVersion.Id = updatedVersion.Id;

            var modifiedUtc  = updatedVersion.ModifiedUtc;
            var publishedUtc = updatedVersion.PublishedUtc;

            // Remove previous published or draft items if necesary or they will continue to be listed as published or draft.
            var discardLatest   = false;
            var removePublished = false;

            var importingLatest = updatedVersion.Latest;
            var existingLatest  = updatingVersion.Latest;

            // If latest values do not match and importing latest is true then we must find and evict the previous latest.
            if (importingLatest != existingLatest && importingLatest == true)
            {
                discardLatest = true;
            }

            var importingPublished = updatedVersion.Published;
            var existingPublished  = updatingVersion.Published;

            // If published values do not match and importing published is true then we must find and evict the previous published
            // This is when the existing content item version is not published, but the importing version is set to published.
            // For this to occur there must have been a draft made, and the mutation to published is being made on the draft.
            if (importingPublished != existingPublished && importingPublished == true)
            {
                removePublished = true;
            }

            if (discardLatest && removePublished)
            {
                await RemoveVersionsAsync(updatingVersion, evictionVersions);
            }
            else if (discardLatest)
            {
                await RemoveLatestVersionAsync(updatingVersion, evictionVersions);
            }
            else if (removePublished)
            {
                await RemovePublishedVersionAsync(updatingVersion, evictionVersions);
            }

            updatingVersion.Merge(updatedVersion, UpdateJsonMergeSettings);
            updatingVersion.Latest    = importingLatest;
            updatingVersion.Published = importingPublished;

            await UpdateAsync(updatingVersion);

            var result = await ValidateAsync(updatingVersion);

            // Session is cancelled now so previous updates to versions are cancelled also.
            if (!result.Succeeded)
            {
                return(result);
            }

            if (importingPublished)
            {
                // Invoke published handlers to add information to persistent stores
                var publishContext = new PublishContentContext(updatingVersion, null);

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

                await ReversedHandlers.InvokeAsync((handler, context) => handler.PublishedAsync(context), publishContext, _logger);
            }
            else
            {
                await SaveDraftAsync(updatingVersion);
            }

            // Restore values that may have been altered by handlers.
            if (modifiedUtc.HasValue)
            {
                updatingVersion.ModifiedUtc = modifiedUtc;
            }
            if (publishedUtc.HasValue)
            {
                updatingVersion.PublishedUtc = publishedUtc;
            }

            return(result);
        }
Пример #9
0
 public override void Published(PublishContentContext context)
 {
     _indexingTaskManager.CreateTaskAsync(context.ContentItem, IndexingTaskTypes.Update).Wait();
 }
 public override Task UnpublishedAsync(PublishContentContext context) => AddContextAsync(context);
Пример #11
0
 public virtual void Unpublished(PublishContentContext context)
 {
 }
Пример #12
0
 public virtual void Publishing(PublishContentContext context)
 {
 }
Пример #13
0
 private void UpdateTemplateClients(PublishContentContext context, LayoutPart part)
 {
     UpdateTemplateClients(part);
 }
 public virtual void Publishing(PublishContentContext context) {}
Пример #15
0
 public override Task PublishedAsync(PublishContentContext context)
 {
     return(_indexingTaskManager.CreateTaskAsync(context.ContentItem, IndexingTaskTypes.Update));
 }
 public virtual void Unpublished(PublishContentContext context) {}
Пример #17
0
        private async Task <ContentValidateResult> CreateContentItemVersionAsync(ContentItem contentItem, IEnumerable <ContentItem> evictionVersions = null)
        {
            if (String.IsNullOrEmpty(contentItem.ContentItemId))
            {
                // NewAsync should be used to create new content items.
                throw new ArgumentNullException(nameof(ContentItem.ContentItemId));
            }

            // Initializes the Id as it could be interpreted as an updated object when added back to YesSql
            contentItem.Id = 0;

            // Maintain modified and published dates as these will be reset by the Create Handlers
            var modifiedUtc  = contentItem.ModifiedUtc;
            var publishedUtc = contentItem.PublishedUtc;
            var owner        = contentItem.Owner;
            var author       = contentItem.Author;

            if (String.IsNullOrEmpty(contentItem.ContentItemVersionId))
            {
                contentItem.ContentItemVersionId = _idGenerator.GenerateUniqueId(contentItem);
            }

            // Remove previous latest item or they will continue to be listed as latest.
            // When importing a new draft the existing latest must be set to false. The creating version wins.
            if (contentItem.Latest && !contentItem.Published)
            {
                await RemoveLatestVersionAsync(contentItem, evictionVersions);
            }
            else if (contentItem.Published)
            {
                // When importing a published item existing drafts and existing published must be removed.
                // Otherwise an existing draft would become an orphan and if published would overwrite
                // the imported (which we assume is the version that wins) content.
                await RemoveVersionsAsync(contentItem, evictionVersions);
            }
            // When neither published or latest the operation will create a database record
            // which will be part of the content item archive.

            // Invoked create handlers.
            var context = new CreateContentContext(contentItem);
            await Handlers.InvokeAsync((handler, context) => handler.CreatingAsync(context), context, _logger);

            // The content item should be placed in the session store so that further calls
            // to ContentManager.Get by a scoped index provider will resolve the imported item correctly.
            _session.Save(contentItem);
            _contentManagerSession.Store(contentItem);

            await ReversedHandlers.InvokeAsync((handler, context) => handler.CreatedAsync(context), context, _logger);

            await UpdateAsync(contentItem);

            var result = await ValidateAsync(contentItem);

            if (!result.Succeeded)
            {
                return(result);
            }

            if (contentItem.Published)
            {
                // Invoke published handlers to add information to persistent stores
                var publishContext = new PublishContentContext(contentItem, null);

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

                await ReversedHandlers.InvokeAsync((handler, context) => handler.PublishedAsync(context), publishContext, _logger);
            }
            else
            {
                await SaveDraftAsync(contentItem);
            }

            // Restore values that may have been altered by handlers.
            if (modifiedUtc.HasValue)
            {
                contentItem.ModifiedUtc = modifiedUtc;
            }
            if (publishedUtc.HasValue)
            {
                contentItem.PublishedUtc = publishedUtc;
            }

            // There is a risk here that the owner or author does not exist in the importing system.
            // We check that at least a value has been supplied, if not the owner property and author
            // property would be left as the user who has run this import.
            if (!String.IsNullOrEmpty(owner))
            {
                contentItem.Owner = owner;
            }
            if (!String.IsNullOrEmpty(author))
            {
                contentItem.Author = author;
            }

            return(result);
        }