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" | |
} |