Last active
April 8, 2020 21:24
-
-
Save jbat04/305c02cf3fd36928268ecfde805ee429 to your computer and use it in GitHub Desktop.
Ingeniux Custom Hooks
This file contains 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
Cutsom Hooks |
This file contains 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
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(); | |
} | |
} | |
} |
This file contains 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
Cutsom Hooks |
This file contains 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
//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