Skip to content

Instantly share code, notes, and snippets.

@jstemerdink
Created August 2, 2022 09:20
Show Gist options
  • Save jstemerdink/654cbf8ac836d72981c0609a4b6d079c to your computer and use it in GitHub Desktop.
Save jstemerdink/654cbf8ac836d72981c0609a4b6d079c to your computer and use it in GitHub Desktop.

Temporarily disable the catalog item change manager

Read my blog here

public class CustomCatalogItemChangeManager : CatalogItemChangeManager
{
private readonly IScheduledJobRepository scheduledJobRepository;
public CustomCatalogItemChangeManager(
IChangeNotificationManager changeNotificationManager,
EntryIdentityResolver entryIdentityResolver,
IScheduledJobRepository scheduledJobRepository)
: base(changeNotificationManager: changeNotificationManager, entryIdentityResolver: entryIdentityResolver)
{
this.scheduledJobRepository = scheduledJobRepository;
}
public override void InsertChanges(IEnumerable<int> entryIds)
{
ScheduledJob job = this.scheduledJobRepository.Get(new Guid("guid-of-import-job"));
if (job != null && job.IsRunning)
{
return;
}
base.InsertChanges(entryIds: entryIds);
}
}
using System.Collections.Generic;
using EPiServer.Events.ChangeNotification;
using Mediachase.Commerce;
using Mediachase.Commerce.Catalog;
public class CustomCatalogItemChangeManager : CatalogItemChangeManager
{
public CustomCatalogItemChangeManager(
IChangeNotificationManager changeNotificationManager,
EntryIdentityResolver entryIdentityResolver)
: base(changeNotificationManager: changeNotificationManager, entryIdentityResolver: entryIdentityResolver)
{
this.SavingChangesEnabled = true;
}
public bool SavingChangesEnabled { get; set; }
public override void InsertChanges(IEnumerable<int> entryIds)
{
if (!this.SavingChangesEnabled)
{
return;
}
base.InsertChanges(entryIds: entryIds);
}
}
container.Configure(x => x.For<CatalogItemChangeHandlerBase>().Use<CustomCatalogItemChangeManager>());
container.Configure(x => x.For<CatalogItemChangeManager>().Use<CustomCatalogItemChangeManager>());
public override string Execute()
{
CustomCatalogItemChangeManager customCatalogItemChangeManager = null;
try
{
customCatalogItemChangeManager = this.catalogItemChangeHandler as CustomCatalogItemChangeManager;
if (customCatalogItemChangeManager != null)
{
customCatalogItemChangeManager.SavingChangesEnabled = false;
}
// Do your magic
}
finally
{
if (customCatalogItemChangeManager != null)
{
customCatalogItemChangeManager.SavingChangesEnabled = true;
}
}
return "Job done"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment