diff --git a/Core/Settings.cs b/Core/Settings.cs index 32f03b0..5dc4315 100644 --- a/Core/Settings.cs +++ b/Core/Settings.cs @@ -1163,6 +1163,20 @@ namespace ScrewTurn.Wiki { } } + /// + /// Gets or sets the last page indexing. + /// + /// The last page indexing DateTime. + public static DateTime LastPageIndexing { + get { + return DateTime.ParseExact(GetString(Provider.GetSetting("LastPageIndexing"), DateTime.Now.AddYears(-10).ToString("yyyyMMddHHmmss")), + "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture); + } + set { + Provider.SetSetting("LastPageIndexing", value.ToString("yyyyMMddHHmmss")); + } + } + #endregion /// diff --git a/Core/StartupTools.cs b/Core/StartupTools.cs index 14fc1bd..6b57ba4 100644 --- a/Core/StartupTools.cs +++ b/Core/StartupTools.cs @@ -189,6 +189,25 @@ namespace ScrewTurn.Wiki { if(Pages.FindPage(Settings.DefaultPage) == null) CreateMainPage(); Log.LogEntry("ScrewTurn Wiki is ready", EntryType.General, Log.SystemUsername); + + System.Threading.ThreadPool.QueueUserWorkItem(ignored => { + if((DateTime.Now - Settings.LastPageIndexing).TotalDays > 7) { + Settings.LastPageIndexing = DateTime.Now; + System.Threading.Thread.Sleep(10000); + using(MemoryStream ms = new MemoryStream()) { + using(StreamWriter wr = new System.IO.StreamWriter(ms)) { + System.Web.HttpContext.Current = new System.Web.HttpContext(new System.Web.Hosting.SimpleWorkerRequest("", "", wr)); + foreach(var provider in Collectors.PagesProviderCollector.AllProviders) { + if(!provider.ReadOnly) { + Log.LogEntry("Starting automatic rebuilding index for provider: " + provider.Information.Name, EntryType.General, Log.SystemUsername); + provider.RebuildIndex(); + Log.LogEntry("Finished automatic rebuilding index for provider: " + provider.Information.Name, EntryType.General, Log.SystemUsername); + } + } + } + } + } + }); } /// diff --git a/PluginFramework/ContextInformation.cs b/PluginFramework/ContextInformation.cs index a11aae7..5f563a0 100644 --- a/PluginFramework/ContextInformation.cs +++ b/PluginFramework/ContextInformation.cs @@ -80,6 +80,7 @@ namespace ScrewTurn.Wiki.PluginFramework { /// /// Gets the current HTTP Context object. /// + /// The context might not be valid when doing an index rebuild (see ). public HttpContext HttpContext { get { return httpContext; } }