Skip to content

Instantly share code, notes, and snippets.

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 jbat04/305c02cf3fd36928268ecfde805ee429 to your computer and use it in GitHub Desktop.
Save jbat04/305c02cf3fd36928268ecfde805ee429 to your computer and use it in GitHub Desktop.
Ingeniux Custom Hooks
public void OnRename(string oldName, string newName, IPage page, IUserWriteSession session)
{
if (newName == "foo")
{
ISchema folderSchema = session.SchemasManager.SchemaByRootName("Folder");
int count;
IPage[] allChildren = page.Children(out count).ToArray();
IPage[] childPages = allChildren.Where(c => c.SchemaName != "Folder").OrderBy(c => c.Name).ToArray();
Dictionary<String, IPage> folders = allChildren.Where(c => c.SchemaName == "Folder").ToDictionary(f => f.Name, f => f);
foreach (IPage child in childPages)
{
this.SetElementValue(child, "SiteControl", "x6");
page.Save();
}
}
}
//a random page/folder must be named 'TriggerSaveOn_xID' where ID is the root of the pages to save
[CustomHook("OnRename_Page")]
public void OnRename(string oldName, string newName, IPage page, IUserWriteSession session)
{
if (newName.StartsWith("TriggerSaveOn_x3"))
{
var refId = newName.SubstringAfter("_");
if (string.IsNullOrWhiteSpace(refId))
{
return;
}
session.Info(string.Format("== OnRename: Triggering Page Save on {0}", refId));
{
var startPage = session.Site.Page(refId);
int count;
var descendantIds = (startPage as Page).DescendantsIDs(out count).Select(o => o.Id).Where(id => !string.IsNullOrEmpty(id)).Distinct();
var store = session.Site.ContentStore as ContentStore;
startPage.Save();
foreach (var batch in descendantIds.Batch(1024))
{
session.Info(string.Format("=== processing batch save"));
using (var inner = store.OpenWriteSession(session.OperatingUser))
{
var pages = inner.Site.Pages(batch);
foreach (var p in pages)
{
if (p != null)
{
p.Save();
}
}
}
}
session.Info(string.Format("== OnRename: Triggering Page Save complete"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment