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 all 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 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;

Check failure on line 45 in src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

The name 'BulkContentHandlers' does not exist in the current context

Check failure on line 45 in src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

The name 'BulkContentHandlers' does not exist in the current context

Check failure on line 45 in src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

The name 'BulkContentHandlers' does not exist in the current context

Check failure on line 45 in src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

The name 'BulkContentHandlers' does not exist in the current context
_session = session;
_idGenerator = idGenerator;
_contentManagerSession = contentManagerSession;
_logger = logger;
_clock = clock;
}

public IEnumerable<IBulkContentEventHandler> BulkContentEventHandlers { get; private set; }
public IEnumerable<IContentHandler> Handlers { get; private set; }

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

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

Check failure on line 613 in src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

The name 'BulkContentHandlers' does not exist in the current context

Check failure on line 613 in src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

The name 'BulkContentHandlers' does not exist in the current context

Check failure on line 613 in src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

The name 'BulkContentHandlers' does not exist in the current context

Check failure on line 613 in src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

The name 'BulkContentHandlers' does not exist in the current context

var skip = 0;

var importedVersionIds = new HashSet<string>();
Expand Down Expand Up @@ -734,6 +740,8 @@
skip += _importBatchSize;
batchedContentItems = contentItems.Skip(skip).Take(_importBatchSize);
}

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

Check failure on line 744 in src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

The name 'BulkContentHandlers' does not exist in the current context

Check failure on line 744 in src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

The name 'BulkContentHandlers' does not exist in the current context

Check failure on line 744 in src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

The name 'BulkContentHandlers' does not exist in the current context

Check failure on line 744 in src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

The name 'BulkContentHandlers' does not exist in the current context
}

public async Task UpdateAsync(ContentItem contentItem)
Expand Down
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 class DefaultBulkContentEventHandlerBase : IBulkContentEventHandler
{
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 @@ -252,6 +252,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.

### 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
Loading