Skip to content

Instantly share code, notes, and snippets.

@dcouto
Created May 1, 2018 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcouto/214a03aaa9de65551f303f990945b584 to your computer and use it in GitHub Desktop.
Save dcouto/214a03aaa9de65551f303f990945b584 to your computer and use it in GitHub Desktop.
using Sitecore;
using Sitecore.Data.Items;
using Sitecore.Jobs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace SitecoreCookbook.Tasks
{
public class ResetLayoutDetailsJob
{
private string _jobName = "Reset Layout Details Job";
public Job Job
{
get { return JobManager.GetJob(_jobName); }
}
public void Run(Item rootItem)
{
JobOptions options = new JobOptions(_jobName,
"Reset Layout", Context.Site.Name, this, "ResetLayoutDetails",
new object[] { rootItem })
{
EnableSecurity = true,
ContextUser = Sitecore.Context.User,
Priority = ThreadPriority.AboveNormal
};
JobManager.Start(options);
}
private void ResetLayoutDetails(Item rootItem)
{
if (Job != null && rootItem != null)
{
List<Item> itemList = rootItem.Axes.GetDescendants().ToList();
itemList.Add(rootItem);
Job.Status.Total = itemList.Count;
Job.Status.State = JobState.Running;
foreach (Item item in itemList)
{
using (new EditContext(item))
{
item.Fields["__renderings"].Reset();
}
Job.Status.Processed++;
}
Job.Status.State = JobState.Finished;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment