Created
January 9, 2012 16:01
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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