diff --git a/src/Bonsai/Code/Config/Startup.Database.cs b/src/Bonsai/Code/Config/Startup.Database.cs index ce09a19..dad15da 100644 --- a/src/Bonsai/Code/Config/Startup.Database.cs +++ b/src/Bonsai/Code/Config/Startup.Database.cs @@ -2,8 +2,10 @@ using System.IO; using System.Linq; using System.Threading.Tasks; +using Bonsai.Areas.Admin.Logic.Tree; using Bonsai.Code.Services; using Bonsai.Code.Services.Config; +using Bonsai.Code.Services.Jobs; using Bonsai.Code.Services.Search; using Bonsai.Data; using Bonsai.Data.Models; @@ -134,7 +136,8 @@ private void InitDatabase(IApplicationBuilder app) var pages = await db.Pages.Include(x => x.Aliases).ToListAsync(); foreach (var page in pages) await search.AddPageAsync(page); - }); + } + ); startupService.AddTask( "BuildPageReferences", @@ -142,6 +145,20 @@ private void InitDatabase(IApplicationBuilder app) () => BuildPageReferences(sp) ); + startupService.AddTask( + "InitTree", + "Построение дерева", + async () => + { + var db = sp.GetService(); + if (await db.TreeLayouts.AnyAsync()) + return; + + var jobs = sp.GetService(); + await jobs.RunAsync(JobBuilder.For().SupersedeAll()); + } + ); + startupService.AddTask("CheckMissingMedia", "", () => CheckMissingMediaAsync(sp)); startupService.AddTask("Finalize", "", async () => scope.Dispose()); @@ -157,7 +174,7 @@ private async Task CheckMissingMediaAsync(IServiceProvider sp) var db = sp.GetService(); var env = sp.GetService(); - if (!(await db.Media.AnyAsync())) + if (await db.Media.AnyAsync() == false) return; var path = Path.Combine(env.WebRootPath, "media");