Skip to content

Instantly share code, notes, and snippets.

@dougludlow
Created September 5, 2014 17:30
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 dougludlow/289ac34ca834bd0e1736 to your computer and use it in GitHub Desktop.
Save dougludlow/289ac34ca834bd0e1736 to your computer and use it in GitHub Desktop.
Resave media nodes to fix cache problem
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