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 14 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
@@ -0,0 +1,10 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OrchardCore.ContentManagement.Handlers;

public interface IBulkContentEventHandler
{
Task ImportingAsync(IEnumerable<ImportContentContext> contexts);
Task ImportedAsync(IEnumerable<ImportContentContext> contexts);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@ public class DefaultContentManager : IContentManager
public DefaultContentManager(
IContentDefinitionManager contentDefinitionManager,
IContentManagerSession contentManagerSession,
IEnumerable<IContentHandler> handlers,
IEnumerable<IContentHandler> handlers,
IEnumerable<IBulkContentEventHandler> bulkContentEventHandlers,
ISession session,
IContentItemIdGenerator idGenerator,
ILogger<DefaultContentManager> logger,
IClock clock)
{
_contentDefinitionManager = contentDefinitionManager;
Handlers = handlers;
BulkContentHandlers = bulkContentEventHandlers;
_session = session;
_idGenerator = idGenerator;
_contentManagerSession = contentManagerSession;
_logger = logger;
_clock = clock;
}

public IEnumerable<IBulkContentEventHandler> BulkContentHandlers { get; private set; }
hyzx86 marked this conversation as resolved.
Show resolved Hide resolved
public IEnumerable<IContentHandler> Handlers { get; private set; }

public IEnumerable<IContentHandler> _reversedHandlers;
Expand Down Expand Up @@ -609,6 +612,9 @@ public async Task ImportAsync(IEnumerable<ContentItem> contentItems)
{
ArgumentNullException.ThrowIfNull(contentItems);

var contentList = contentItems.Select(x => new ImportContentContext(x)).ToList();
await BulkContentHandlers.InvokeAsync((handler, list) => handler.ImportingAsync(list), contentList, _logger);

var skip = 0;

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

await BulkContentHandlers.InvokeAsync((handler, list) => handler.ImportedAsync(list), contentList, _logger);
}

public async Task UpdateAsync(ContentItem contentItem)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OrchardCore.ContentManagement.Handlers;
public class DefaultBulkContentEventHandlerBase : IBulkContentEventHandler
hyzx86 marked this conversation as resolved.
Show resolved Hide resolved
{
public virtual Task ImportingAsync(IEnumerable<ImportContentContext> contexts) => Task.CompletedTask;
public virtual Task ImportedAsync(IEnumerable<ImportContentContext> contexts) => Task.CompletedTask;
}
2 changes: 2 additions & 0 deletions src/docs/releases/2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ Additionally, the `GetContentItemByHandleAsync(string handle, bool latest = fals

Lastly, we dropped support for AllVersions option in `VersionOptions`. Instead, you can use the new `GetAllVersionsAsync(string contentItemId)` method on `IContentManager`.

We added `IBulkContentEventHandler` , which contains two handlers, `ImportingAsync` and `ImportedAsync` , that allow developers to get a collection of all the imported items at once during the import process and add custom processing logic.
hyzx86 marked this conversation as resolved.
Show resolved Hide resolved

### Media Indexing

Previously, `.pdf` files were automatically indexed in the search providers (Elasticsearch, Lucene or Azure AI Search). Now, if you want to continue to index `.PDF` file you'll need to enable the `OrchardCore.Media.Indexing.Pdf` feature.
Expand Down