Last active
October 31, 2018 06:34
-
-
Save nick-hoang/32b29b26db45a7e9cdb43df2a5b2c292 to your computer and use it in GitHub Desktop.
Umbraco - move published content without raising events
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
public class Mover { | |
public void PerformMovePublishedContent(IContent content, int parentId, int userId = 0) | |
{ | |
if(content.ParentId == parentId) | |
{ | |
return; | |
} | |
var contentService = ApplicationContext.Current.Services.ContentService; | |
if (parentId == Constants.System.Root) | |
{ | |
content.Path = string.Concat(Constants.System.Root, ",", content.Id); | |
content.Level = 1; | |
} | |
else | |
{ | |
var parent = contentService.GetById(parentId); | |
content.Path = string.Concat(parent.Path, ",", content.Id); | |
content.Level = parent.Level + 1; | |
} | |
content.ParentId = parentId; | |
contentService.SaveAndPublishWithStatus(content, userId, false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment