Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Episerver: Update Modified Date for Usages of specific PageType
var contentRepo = ServiceLocator.Current.GetInstance<IContentRepository>();
var contentTypeRepo = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
var contentType = contentTypeRepo.Load(typeof (PageData));
var usageRepo =
ServiceLocator.Current.GetInstance<IContentModelUsage>()
.ListContentOfContentType(contentType)
.Select(x => x.ContentLink.ToReferenceWithoutVersion()).Distinct()
.ToList();
foreach (var page in usageRepo.Select(usage => contentRepo.Get<PageData>(usage)).Where(page => !page.IsDeleted))
{
try
{
EPiServer.Framework.ContextCache.Current[EPiServer.DataAccess.ContentSaveDB.UseIChangeTrackingSavedKey] = new object();
var clone = page.CreateWritableClone();
clone.Saved = clone.StartPublish;
clone.Changed = clone.StartPublish;
clone.SetChangedOnPublish = true;
DataFactory.Instance.Save(clone, SaveAction.Publish | SaveAction.ForceCurrentVersion);
//contentRepo.Save(clone, SaveAction.Publish, AccessLevel.Publish);
}
catch (Exception ex)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.