Skip to content

Instantly share code, notes, and snippets.

@sclarson
Created March 31, 2011 15:56
Show Gist options
  • Save sclarson/896636 to your computer and use it in GitHub Desktop.
Save sclarson/896636 to your computer and use it in GitHub Desktop.
Unstoppable EPiServer Schedule Job Example
using System.Linq;
using System.Text;
using EPiServer;
using EPiServer.Core;
using EPiServer.PlugIn;
namespace BlendInteractive.AppCode.Plugins
{
[ScheduledPlugIn(DisplayName = "Delete Unpublished Faculty and Staff")]
public class DeleteUnpublishedPeople
{
private static int staffPages;
private static int facultyPages;
public static string Execute()
{
staffPages = 0;
facultyPages = 0;
StringBuilder returnValue = new StringBuilder();
var facultyList = Utilities.GetFilteredPageCollection(PageReference.RootPage, "Faculty Page").Where(p => p.Status != VersionStatus.Published);
var stafflist = Utilities.GetFilteredPageCollection(PageReference.RootPage, "Staff Page").Where(p => p.Status != VersionStatus.Published);
foreach (var person in facultyList)
{
DataFactory.Instance.MoveToWastebasket(person.PageLink);
returnValue.AppendLine("Added: " + person.PageName + " to wastebasket: id - " + person.PageLink.ID + "<br />");
facultyPages++;
}
foreach (var person in stafflist)
{
DataFactory.Instance.MoveToWastebasket(person.PageLink);
returnValue.AppendLine("Added: " + person.PageName + " to wastebasket: id - " + person.PageLink.ID + "<br />");
staffPages++;
}
return "Deleted Pages: " + facultyPages + "<br />Deleted Staff Pages: " + staffPages + "<br />" + returnValue.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment