Skip to content

Instantly share code, notes, and snippets.

@leekelleher
Created January 9, 2012 16:01
Show Gist options
  • Save leekelleher/1583566 to your computer and use it in GitHub Desktop.
Save leekelleher/1583566 to your computer and use it in GitHub Desktop.
Example Umbraco /Base method to archive news pages if they are over 30 days. (Using uComponents' uQuery)
using uComponents.Core.uQueryExtensions;
using umbraco.presentation.umbracobase;
namespace Our.Umbraco
{
[RestExtension("examples")]
public class Examples
{
public static bool ArchiveNewsPages()
{
// get all the nodes that haven't been archived
var nodes = uComponents.Core.uQuery.GetNodesByXPath("//NewsPage[@isDoc and string(archived) != '1']");
// loop over each node
foreach (var node in nodes)
{
// test if create date is over 30 days old...
if (node.CreateDate.AddDays(30) < DateTime.Today)
{
// ... then set the property as archived.
node.SetProperty("archived", true);
}
}
// return some value since it's using /Base
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment