Created
June 18, 2015 16:08
-
-
Save jamiepollock/f5d4c89766433e402383 to your computer and use it in GitHub Desktop.
Tool for automatically resaving media nodes in Umbraco v6. Add to your dashboard.config to gain easy access to this tool.
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
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RebuildMediaCacheTool.ascx.cs" Inherits="My.Website.Dashboard.RebuildMediaCacheTool" %> | |
<div class="dashboardWrapper"> | |
<h2>Rebuild Media Cache</h2> | |
<img src="/umbraco_client/Dashboards/ExamineManagementIco.png" alt="" class="dashboardIcon" /> | |
<asp:MultiView ID="MainView" runat="server"> | |
<asp:View ID="InitialView" runat="server"> | |
<asp:Button ID="RebuildButton" Text="Rebuild Media Cache" runat="server"/> | |
</asp:View> | |
<asp:View ID="CompleteView" runat="server"> | |
<p>Rebuild complete!</p> | |
<p><%: MediaCount %> Media Items cache rebuilt</p> | |
</asp:View> | |
</asp:MultiView> | |
</div> |
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
using System; | |
using System.Linq; | |
using Umbraco.Core.Models; | |
using Umbraco.Web.UI.Controls; | |
namespace My.Website.Dashboard { | |
public partial class RebuildMediaCacheTool : UmbracoUserControl { | |
public int MediaCount { get; set; } | |
protected void Page_Load(object sender, EventArgs e) { | |
if (IsPostBack == false) { | |
MainView.SetActiveView(InitialView); | |
} | |
RebuildButton.Click += OnRebuildButtonClick; | |
} | |
private void OnRebuildButtonClick(object sender, EventArgs e) { | |
var rootNodes = Services.MediaService.GetRootMedia(); | |
foreach (var rootNode in rootNodes.Where(x => x.Trashed == false)) { | |
Services.MediaService.Save(rootNode); | |
MediaCount++; | |
foreach (var ancestor in rootNode.Descendants().Where(x => x.Trashed == false)) { | |
Services.MediaService.Save(ancestor); | |
MediaCount++; | |
} | |
} | |
MainView.SetActiveView(CompleteView); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment