From b70d7101e3f7cd2216b539d11127790cd8cdf6df Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 1 May 2020 13:40:26 +0200 Subject: [PATCH] AB#6233 - Explicit restarts umbraco after install to ensure runtime state is run and umbraco is correct composed. --- .../InstallSteps/SetUmbracoVersionStep.cs | 6 +- .../Controllers/BackOfficeController.cs | 8 +- .../Install/InstallApiController.cs | 13 ++- .../src/installer/installer.service.js | 81 ++++++++++--------- .../Umbraco.Web.UI.NetCore.csproj | 1 - 5 files changed, 61 insertions(+), 48 deletions(-) diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/SetUmbracoVersionStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/SetUmbracoVersionStep.cs index a0f6fd594a..8eac6711c4 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/SetUmbracoVersionStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/SetUmbracoVersionStep.cs @@ -15,16 +15,14 @@ namespace Umbraco.Web.Install.InstallSteps private readonly InstallHelper _installHelper; private readonly IGlobalSettings _globalSettings; private readonly IUmbracoVersion _umbracoVersion; - private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime; public SetUmbracoVersionStep(IUmbracoContextAccessor umbracoContextAccessor, InstallHelper installHelper, - IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IUmbracoApplicationLifetime umbracoApplicationLifetime) + IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion) { _umbracoContextAccessor = umbracoContextAccessor; _installHelper = installHelper; _globalSettings = globalSettings; _umbracoVersion = umbracoVersion; - _umbracoApplicationLifetime = umbracoApplicationLifetime; } public override Task ExecuteAsync(object model) @@ -57,8 +55,6 @@ namespace Umbraco.Web.Install.InstallSteps //reports the ended install _installHelper.InstallStatus(true, ""); - _umbracoApplicationLifetime.Restart(); - return Task.FromResult(null); } diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs index 79612fec45..bb895f61e2 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs @@ -2,9 +2,8 @@ using Microsoft.AspNetCore.Mvc; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; -using Umbraco.Core.Runtime; using Umbraco.Core.WebAssets; +using Umbraco.Net; using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.Common.ActionResults; using Umbraco.Web.WebAssets; @@ -16,17 +15,20 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly IRuntimeMinifier _runtimeMinifier; private readonly IGlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; + private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime; - public BackOfficeController(IRuntimeMinifier runtimeMinifier, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public BackOfficeController(IRuntimeMinifier runtimeMinifier, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IUmbracoApplicationLifetime umbracoApplicationLifetime) { _runtimeMinifier = runtimeMinifier; _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; + _umbracoApplicationLifetime = umbracoApplicationLifetime; } // GET public IActionResult Index() { + _umbracoApplicationLifetime.Restart(); //TODO remove return View(); } diff --git a/src/Umbraco.Web.Common/Install/InstallApiController.cs b/src/Umbraco.Web.Common/Install/InstallApiController.cs index 5584bfd1d9..db27a274e1 100644 --- a/src/Umbraco.Web.Common/Install/InstallApiController.cs +++ b/src/Umbraco.Web.Common/Install/InstallApiController.cs @@ -24,17 +24,20 @@ namespace Umbraco.Web.Common.Install { private readonly DatabaseBuilder _databaseBuilder; private readonly InstallStatusTracker _installStatusTracker; + private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime; private readonly InstallStepCollection _installSteps; private readonly ILogger _logger; private readonly IProfilingLogger _proflog; public InstallApiController(DatabaseBuilder databaseBuilder, IProfilingLogger proflog, - InstallHelper installHelper, InstallStepCollection installSteps, InstallStatusTracker installStatusTracker) + InstallHelper installHelper, InstallStepCollection installSteps, InstallStatusTracker installStatusTracker, + IUmbracoApplicationLifetime umbracoApplicationLifetime) { _databaseBuilder = databaseBuilder ?? throw new ArgumentNullException(nameof(databaseBuilder)); _proflog = proflog ?? throw new ArgumentNullException(nameof(proflog)); _installSteps = installSteps; _installStatusTracker = installStatusTracker; + _umbracoApplicationLifetime = umbracoApplicationLifetime; InstallHelper = installHelper; _logger = _proflog; } @@ -76,6 +79,14 @@ namespace Umbraco.Web.Common.Install return starterKits; } + + [HttpPost] + public ActionResult CompleteInstall() + { + _umbracoApplicationLifetime.Restart(); + return NoContent(); + } + /// /// Installs. /// diff --git a/src/Umbraco.Web.UI.Client/src/installer/installer.service.js b/src/Umbraco.Web.UI.Client/src/installer/installer.service.js index a7e118cbe8..68b1153c21 100644 --- a/src/Umbraco.Web.UI.Client/src/installer/installer.service.js +++ b/src/Umbraco.Web.UI.Client/src/installer/installer.service.js @@ -266,34 +266,7 @@ angular.module("umbraco.install").factory('installerService', function ($rootSco else { service.complete(); } - }, function (response) { - - var data = response.data; - var status = response.status; - //need to handle 500's separately, this will happen if something goes wrong outside - // of the installer (like app startup events or something) and these will get returned as text/html - // not as json. If this happens we can't actually load in external views since they will YSOD as well! - // so we need to display this in our own internal way - - if(status === 502 && retry !== true){ - processInstallStep(true); - }else if (status >= 500 && status < 600) { - service.status.current = { view: "ysod", model: null }; - var ysod = data; - //we need to manually write the html to the iframe - the html contains full html markup - $timeout(function () { - document.getElementById('ysod').contentDocument.write(ysod); - }, 500); - } - else { - //this is where we handle installer error - var v = data.view ? resolveView(data.view) : resolveView("error"); - var model = data.model ? data.model : data; - service.status.current = { view: v, model: model }; - } - - service.switchToConfiguration(); - }); + }, handleErrorResponse); } processInstallStep(); }, @@ -331,20 +304,52 @@ angular.module("umbraco.install").factory('installerService', function ($rootSco complete : function(){ - service.status.progress = "100%"; - service.status.done = true; - service.status.feedback = "Redirecting you to Umbraco, please wait"; - service.status.loading = false; + $http.post(Umbraco.Sys.ServerVariables.installApiBaseUrl + "CompleteInstall", _installerModel) + .then(function () { + service.status.progress = "100%"; + service.status.done = true; + service.status.feedback = "Restarting and redirecting you to Umbraco, please wait"; + service.status.loading = false; - if (factTimer) { - clearInterval(factTimer); - } + if (factTimer) { + clearInterval(factTimer); + } - $timeout(function(){ - window.location.href = Umbraco.Sys.ServerVariables.umbracoBaseUrl; - }, 1500); + $timeout(function(){ + window.location.href = Umbraco.Sys.ServerVariables.umbracoBaseUrl; + }, 5000); + }, handleErrorResponse); + + } }; + var handleErrorResponse = function (response) { + + var data = response.data; + var status = response.status; + //need to handle 500's separately, this will happen if something goes wrong outside + // of the installer (like app startup events or something) and these will get returned as text/html + // not as json. If this happens we can't actually load in external views since they will YSOD as well! + // so we need to display this in our own internal way + + if (status >= 500 && status < 600) { + service.status.current = { view: "ysod", model: null }; + var ysod = data; + //we need to manually write the html to the iframe - the html contains full html markup + $timeout(function () { + document.getElementById('ysod').contentDocument.write(ysod); + }, 500); + } + else { + //this is where we handle installer error + var v = data.view ? resolveView(data.view) : resolveView("error"); + var model = data.model ? data.model : data; + service.status.current = { view: v, model: model }; + } + + service.switchToConfiguration(); + } + return service; }); diff --git a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj index df916c50f9..60b3f3c0f4 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj +++ b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj @@ -4,7 +4,6 @@ netcoreapp3.1 Umbraco.Web.UI.NetCore -