Created
September 5, 2014 17:30
-
-
Save dougludlow/289ac34ca834bd0e1736 to your computer and use it in GitHub Desktop.
Resave media nodes to fix cache problem
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 System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using umbraco.cms.businesslogic.media; | |
using umbraco.presentation.umbracobase; | |
[RestExtension("Media")] | |
public class SaveMedia | |
{ | |
[RestExtensionMethod(allowAll = true)] | |
public static string SaveRecursive(int nodeId) | |
{ | |
int nodeCount = 0; | |
var node = new Media(nodeId); | |
if (node != null && node.Id != 0) | |
{ | |
node.Save(); | |
nodeCount++; | |
var descendants = node.GetDescendants().Cast<Media>(); | |
foreach (var n in descendants) | |
{ | |
n.Save(); | |
nodeCount++; | |
} | |
} | |
return string.Format("Saved {0} media nodes.", nodeCount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment