Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add events before and after handling bulk imports #11532

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OrchardCore.ContentManagement.Handlers
Expand Down Expand Up @@ -146,5 +147,15 @@ public virtual Task GetContentItemAspectAsync(ContentItemAspectContext context)
{
return Task.CompletedTask;
}

public Task BeforeImportAsync(IEnumerable<ImportContentContext> contentItems)
Piedone marked this conversation as resolved.
Show resolved Hide resolved
{
return Task.CompletedTask;
}

public Task AfterImportAsync(IEnumerable<ImportContentContext> contentItems)
{
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OrchardCore.ContentManagement.Handlers
Expand All @@ -13,7 +14,9 @@ public interface IContentHandler
Task LoadingAsync(LoadContentContext context);
Task LoadedAsync(LoadContentContext context);
Task ImportingAsync(ImportContentContext context);
Task BeforeImportAsync(IEnumerable<ImportContentContext> contentItems);
Task ImportedAsync(ImportContentContext context);
Task AfterImportAsync(IEnumerable<ImportContentContext> contentItems);
Piedone marked this conversation as resolved.
Show resolved Hide resolved
Task UpdatingAsync(UpdateContentContext context);
Task UpdatedAsync(UpdateContentContext context);
Task ValidatingAsync(ValidateContentContext context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ public Task<ContentValidateResult> UpdateContentItemVersionAsync(ContentItem upd

public async Task ImportAsync(IEnumerable<ContentItem> contentItems)
{
var contentList = contentItems.Select(x => new ImportContentContext(x)).ToList();
await ReversedHandlers.InvokeAsync((handler, list) => handler.BeforeImportAsync(list), contentList, _logger);

var skip = 0;

var importedVersionIds = new HashSet<string>();
Expand Down Expand Up @@ -599,6 +602,10 @@ public async Task ImportAsync(IEnumerable<ContentItem> contentItems)
skip += ImportBatchSize;
batchedContentItems = contentItems.Skip(skip).Take(ImportBatchSize);
}

await ReversedHandlers.InvokeAsync((handler, list) => handler.AfterImportAsync(list), contentList, _logger);


}

public async Task UpdateAsync(ContentItem contentItem)
Expand Down