From da1e83c0d1d83e89b18102dc9d4696aeb14beabc Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 1 May 2020 08:26:05 +0200 Subject: [PATCH] AB#6233 - Added application url on IHostingEnvironment. Still need a way to figure out how to get this value --- src/Umbraco.Core/Hosting/IHostingEnvironment.cs | 2 ++ .../DatabaseServerRegistrarAndMessengerComponent.cs | 2 +- .../{Intall => Install}/FilePermissionHelper.cs | 0 .../{Intall => Install}/InstallHelper.cs | 0 .../{Intall => Install}/InstallStepCollection.cs | 0 .../InstallSteps/DatabaseConfigureStep.cs | 0 .../InstallSteps/DatabaseInstallStep.cs | 0 .../InstallSteps/DatabaseUpgradeStep.cs | 0 .../InstallSteps/NewInstallStep.cs | 0 .../InstallSteps/SetUmbracoVersionStep.cs | 10 ++++++++-- .../InstallSteps/StarterKitDownloadStep.cs | 0 .../InstallSteps/StarterKitInstallStep.cs | 0 .../Models/InstallInstructions.cs | 0 src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs | 2 +- src/Umbraco.Infrastructure/RuntimeState.cs | 12 ++++++++++-- src/Umbraco.Tests.Common/TestHelperBase.cs | 5 +++-- src/Umbraco.Tests/Routing/UmbracoModuleTests.cs | 2 +- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 2 +- .../AspNetCore/AspNetCoreHostingEnvironment.cs | 2 ++ .../Install/HttpInstallAuthorizeAttribute.cs | 2 +- .../Install/InstallApiController.cs | 8 +------- .../src/installer/installer.service.js | 6 ++++-- src/Umbraco.Web.UI.NetCore/appsettings.json | 4 +++- src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs | 12 +++++++++--- 24 files changed, 47 insertions(+), 24 deletions(-) rename src/Umbraco.Infrastructure/{Intall => Install}/FilePermissionHelper.cs (100%) rename src/Umbraco.Infrastructure/{Intall => Install}/InstallHelper.cs (100%) rename src/Umbraco.Infrastructure/{Intall => Install}/InstallStepCollection.cs (100%) rename src/Umbraco.Infrastructure/{Intall => Install}/InstallSteps/DatabaseConfigureStep.cs (100%) rename src/Umbraco.Infrastructure/{Intall => Install}/InstallSteps/DatabaseInstallStep.cs (100%) rename src/Umbraco.Infrastructure/{Intall => Install}/InstallSteps/DatabaseUpgradeStep.cs (100%) rename src/Umbraco.Infrastructure/{Intall => Install}/InstallSteps/NewInstallStep.cs (100%) rename src/Umbraco.Infrastructure/{Intall => Install}/InstallSteps/SetUmbracoVersionStep.cs (86%) rename src/Umbraco.Infrastructure/{Intall => Install}/InstallSteps/StarterKitDownloadStep.cs (100%) rename src/Umbraco.Infrastructure/{Intall => Install}/InstallSteps/StarterKitInstallStep.cs (100%) rename src/Umbraco.Infrastructure/{Intall => Install}/Models/InstallInstructions.cs (100%) diff --git a/src/Umbraco.Core/Hosting/IHostingEnvironment.cs b/src/Umbraco.Core/Hosting/IHostingEnvironment.cs index b653f535fa..38190112d3 100644 --- a/src/Umbraco.Core/Hosting/IHostingEnvironment.cs +++ b/src/Umbraco.Core/Hosting/IHostingEnvironment.cs @@ -23,6 +23,8 @@ namespace Umbraco.Core.Hosting /// string ApplicationVirtualPath { get; } + string ApplicationServerAddress { get; } + bool IsDebugMode { get; } /// diff --git a/src/Umbraco.Infrastructure/Compose/DatabaseServerRegistrarAndMessengerComponent.cs b/src/Umbraco.Infrastructure/Compose/DatabaseServerRegistrarAndMessengerComponent.cs index fdc672c534..33cbac3301 100644 --- a/src/Umbraco.Infrastructure/Compose/DatabaseServerRegistrarAndMessengerComponent.cs +++ b/src/Umbraco.Infrastructure/Compose/DatabaseServerRegistrarAndMessengerComponent.cs @@ -164,7 +164,7 @@ namespace Umbraco.Web.Compose // only perform this one time ever LazyInitializer.EnsureInitialized(ref _tasks, ref _started, ref _locker, () => { - var serverAddress = _runtime.ApplicationUrl.ToString(); + var serverAddress = _runtime.ApplicationUrl?.ToString(); return new[] { diff --git a/src/Umbraco.Infrastructure/Intall/FilePermissionHelper.cs b/src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs similarity index 100% rename from src/Umbraco.Infrastructure/Intall/FilePermissionHelper.cs rename to src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs diff --git a/src/Umbraco.Infrastructure/Intall/InstallHelper.cs b/src/Umbraco.Infrastructure/Install/InstallHelper.cs similarity index 100% rename from src/Umbraco.Infrastructure/Intall/InstallHelper.cs rename to src/Umbraco.Infrastructure/Install/InstallHelper.cs diff --git a/src/Umbraco.Infrastructure/Intall/InstallStepCollection.cs b/src/Umbraco.Infrastructure/Install/InstallStepCollection.cs similarity index 100% rename from src/Umbraco.Infrastructure/Intall/InstallStepCollection.cs rename to src/Umbraco.Infrastructure/Install/InstallStepCollection.cs diff --git a/src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseConfigureStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs similarity index 100% rename from src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseConfigureStep.cs rename to src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseConfigureStep.cs diff --git a/src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseInstallStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseInstallStep.cs similarity index 100% rename from src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseInstallStep.cs rename to src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseInstallStep.cs diff --git a/src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseUpgradeStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs similarity index 100% rename from src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseUpgradeStep.cs rename to src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs diff --git a/src/Umbraco.Infrastructure/Intall/InstallSteps/NewInstallStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs similarity index 100% rename from src/Umbraco.Infrastructure/Intall/InstallSteps/NewInstallStep.cs rename to src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs diff --git a/src/Umbraco.Infrastructure/Intall/InstallSteps/SetUmbracoVersionStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/SetUmbracoVersionStep.cs similarity index 86% rename from src/Umbraco.Infrastructure/Intall/InstallSteps/SetUmbracoVersionStep.cs rename to src/Umbraco.Infrastructure/Install/InstallSteps/SetUmbracoVersionStep.cs index 5bdd6624d5..a0f6fd594a 100644 --- a/src/Umbraco.Infrastructure/Intall/InstallSteps/SetUmbracoVersionStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/SetUmbracoVersionStep.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Net; using Umbraco.Web.Install.Models; namespace Umbraco.Web.Install.InstallSteps @@ -14,13 +15,16 @@ 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) + public SetUmbracoVersionStep(IUmbracoContextAccessor umbracoContextAccessor, InstallHelper installHelper, + IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IUmbracoApplicationLifetime umbracoApplicationLifetime) { _umbracoContextAccessor = umbracoContextAccessor; _installHelper = installHelper; _globalSettings = globalSettings; _umbracoVersion = umbracoVersion; + _umbracoApplicationLifetime = umbracoApplicationLifetime; } public override Task ExecuteAsync(object model) @@ -49,10 +53,12 @@ namespace Umbraco.Web.Install.InstallSteps // // for installs, we need to log the super user in // security.PerformLogin(Constants.Security.SuperUserId); // } - + //reports the ended install _installHelper.InstallStatus(true, ""); + _umbracoApplicationLifetime.Restart(); + return Task.FromResult(null); } diff --git a/src/Umbraco.Infrastructure/Intall/InstallSteps/StarterKitDownloadStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/StarterKitDownloadStep.cs similarity index 100% rename from src/Umbraco.Infrastructure/Intall/InstallSteps/StarterKitDownloadStep.cs rename to src/Umbraco.Infrastructure/Install/InstallSteps/StarterKitDownloadStep.cs diff --git a/src/Umbraco.Infrastructure/Intall/InstallSteps/StarterKitInstallStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/StarterKitInstallStep.cs similarity index 100% rename from src/Umbraco.Infrastructure/Intall/InstallSteps/StarterKitInstallStep.cs rename to src/Umbraco.Infrastructure/Install/InstallSteps/StarterKitInstallStep.cs diff --git a/src/Umbraco.Infrastructure/Intall/Models/InstallInstructions.cs b/src/Umbraco.Infrastructure/Install/Models/InstallInstructions.cs similarity index 100% rename from src/Umbraco.Infrastructure/Intall/Models/InstallInstructions.cs rename to src/Umbraco.Infrastructure/Install/Models/InstallInstructions.cs diff --git a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs index c91ae530ce..cbcf90ab9a 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs @@ -65,7 +65,7 @@ namespace Umbraco.Core.Runtime // runtime state // beware! must use '() => _factory.GetInstance()' and NOT '_factory.GetInstance' // as the second one captures the current value (null) and therefore fails - _state = new RuntimeState(Logger, Configs.Global(), UmbracoVersion, BackOfficeInfo) + _state = new RuntimeState(Logger, Configs.Global(), UmbracoVersion, BackOfficeInfo, HostingEnvironment) { Level = RuntimeLevel.Boot }; diff --git a/src/Umbraco.Infrastructure/RuntimeState.cs b/src/Umbraco.Infrastructure/RuntimeState.cs index 3f5e209858..3d8335734e 100644 --- a/src/Umbraco.Infrastructure/RuntimeState.cs +++ b/src/Umbraco.Infrastructure/RuntimeState.cs @@ -24,18 +24,22 @@ namespace Umbraco.Core private readonly ConcurrentHashSet _applicationUrls = new ConcurrentHashSet(); private readonly IUmbracoVersion _umbracoVersion; private readonly IBackOfficeInfo _backOfficeInfo; + private readonly IHostingEnvironment _hostingEnvironment; + private Uri _applicationUrl; /// /// Initializes a new instance of the class. /// public RuntimeState(ILogger logger, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, - IBackOfficeInfo backOfficeInfo) + IBackOfficeInfo backOfficeInfo, + IHostingEnvironment hostingEnvironment) { _logger = logger; _globalSettings = globalSettings; _umbracoVersion = umbracoVersion; _backOfficeInfo = backOfficeInfo; + _hostingEnvironment = hostingEnvironment; } @@ -49,7 +53,11 @@ namespace Umbraco.Core public SemVersion SemanticVersion => _umbracoVersion.SemanticVersion; /// - public Uri ApplicationUrl { get; private set; } + public Uri ApplicationUrl + { + get => _applicationUrl ??= new Uri(_hostingEnvironment.ApplicationServerAddress); + private set => _applicationUrl = value; + } /// public string CurrentMigrationState { get; private set; } diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index 5f4faf8547..9f3735a616 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -34,7 +34,7 @@ namespace Umbraco.Tests.Common protected TestHelperBase(Assembly entryAssembly) { - SettingsForTests = new SettingsForTests(); + SettingsForTests = new SettingsForTests(); MainDom = new SimpleMainDom(); _typeFinder = new TypeFinder(Mock.Of(), new DefaultUmbracoAssemblyProvider(entryAssembly), new VaryingRuntimeHash()); } @@ -54,7 +54,8 @@ namespace Umbraco.Tests.Common Mock.Of(), Mock.Of(), GetUmbracoVersion(), - GetBackOfficeInfo()); + GetBackOfficeInfo(), + GetHostingEnvironment()); } public abstract IBackOfficeInfo GetBackOfficeInfo(); diff --git a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs index 2e83427b07..a4819582dc 100644 --- a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs +++ b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs @@ -32,7 +32,7 @@ namespace Umbraco.Tests.Routing //create the module var logger = Mock.Of(); var globalSettings = TestObjects.GetGlobalSettings(); - var runtime = new RuntimeState(logger, globalSettings, UmbracoVersion, BackOfficeInfo); + var runtime = new RuntimeState(logger, globalSettings, UmbracoVersion, BackOfficeInfo, HostingEnvironment); _module = new UmbracoInjectedModule ( diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index 5100e2e21c..3088af0b5a 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -73,7 +73,7 @@ namespace Umbraco.Tests.Runtimes var mainDom = new SimpleMainDom(); var umbracoVersion = TestHelper.GetUmbracoVersion(); var backOfficeInfo = TestHelper.GetBackOfficeInfo(); - var runtimeState = new RuntimeState(logger, null, umbracoVersion, backOfficeInfo); + var runtimeState = new RuntimeState(logger, null, umbracoVersion, backOfficeInfo, hostingEnvironment); var configs = TestHelper.GetConfigs(); var variationContextAccessor = TestHelper.VariationContextAccessor; diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs index b3ec11c241..0f76e78f29 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -26,6 +26,7 @@ namespace Umbraco.Web.Common.AspNetCore ApplicationPhysicalPath = webHostEnvironment.ContentRootPath; ApplicationVirtualPath = "/"; //TODO how to find this, This is a server thing, not application thing. + ApplicationServerAddress = "https://localhost:44354"; // TODO how to find this? IISVersion = new Version(0, 0); // TODO not necessary IIS } @@ -34,6 +35,7 @@ namespace Umbraco.Web.Common.AspNetCore public string SiteName { get; } public string ApplicationId { get; } public string ApplicationPhysicalPath { get; } + public string ApplicationServerAddress { get; } public string ApplicationVirtualPath { get; } public bool IsDebugMode => _hostingSettings.DebugMode; diff --git a/src/Umbraco.Web.Common/Install/HttpInstallAuthorizeAttribute.cs b/src/Umbraco.Web.Common/Install/HttpInstallAuthorizeAttribute.cs index 0c03b1ce28..8ee59105e4 100644 --- a/src/Umbraco.Web.Common/Install/HttpInstallAuthorizeAttribute.cs +++ b/src/Umbraco.Web.Common/Install/HttpInstallAuthorizeAttribute.cs @@ -41,7 +41,7 @@ namespace Umbraco.Web.Install // otherwise we need to ensure that a user is logged in return runtimeState.Level == RuntimeLevel.Install || runtimeState.Level == RuntimeLevel.Upgrade - || umbracoContext.Security.ValidateCurrentUser(); + || (umbracoContext?.Security?.ValidateCurrentUser() ?? false); } catch (Exception ex) { diff --git a/src/Umbraco.Web.Common/Install/InstallApiController.cs b/src/Umbraco.Web.Common/Install/InstallApiController.cs index 16a93672ba..5584bfd1d9 100644 --- a/src/Umbraco.Web.Common/Install/InstallApiController.cs +++ b/src/Umbraco.Web.Common/Install/InstallApiController.cs @@ -24,22 +24,17 @@ namespace Umbraco.Web.Common.Install { private readonly DatabaseBuilder _databaseBuilder; private readonly InstallStatusTracker _installStatusTracker; - private readonly IRuntimeState _runtimeState; - 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, - IRuntimeState runtimeState, IUmbracoApplicationLifetime umbracoApplicationLifetime) + InstallHelper installHelper, InstallStepCollection installSteps, InstallStatusTracker installStatusTracker) { _databaseBuilder = databaseBuilder ?? throw new ArgumentNullException(nameof(databaseBuilder)); _proflog = proflog ?? throw new ArgumentNullException(nameof(proflog)); _installSteps = installSteps; _installStatusTracker = installStatusTracker; - _runtimeState = runtimeState; - _umbracoApplicationLifetime = umbracoApplicationLifetime; InstallHelper = installHelper; _logger = _proflog; } @@ -175,7 +170,6 @@ namespace Umbraco.Web.Common.Install } _installStatusTracker.Reset(); - _umbracoApplicationLifetime.Restart(); return new InstallProgressResultModel(true, "", ""); } 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 05c391c3e7..a7e118cbe8 100644 --- a/src/Umbraco.Web.UI.Client/src/installer/installer.service.js +++ b/src/Umbraco.Web.UI.Client/src/installer/installer.service.js @@ -237,7 +237,7 @@ angular.module("umbraco.install").factory('installerService', function ($rootSco service.status.feedback = getDescriptionForStepAtIndex(service.status.steps, 0); service.status.progress = 0; - function processInstallStep() { + function processInstallStep(retry) { $http.post(Umbraco.Sys.ServerVariables.installApiBaseUrl + "PostPerformInstall", _installerModel) .then(function (response) { @@ -275,7 +275,9 @@ angular.module("umbraco.install").factory('installerService', function ($rootSco // 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) { + 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 diff --git a/src/Umbraco.Web.UI.NetCore/appsettings.json b/src/Umbraco.Web.UI.NetCore/appsettings.json index 6cc0a49b4b..e9d34dce46 100644 --- a/src/Umbraco.Web.UI.NetCore/appsettings.json +++ b/src/Umbraco.Web.UI.NetCore/appsettings.json @@ -1,5 +1,7 @@ { - "ConnectionStrings": {}, + "ConnectionStrings": { + "umbracoDbDSN": "Data Source=|DataDirectory|\\Umbraco.sdf;Flush Interval=1;" + }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs b/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs index 03c12c36f8..06e5638204 100644 --- a/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs +++ b/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs @@ -10,9 +10,10 @@ namespace Umbraco.Web.Hosting { public class AspNetHostingEnvironment : IHostingEnvironment { - + private readonly IHostingSettings _hostingSettings; private string _localTempPath; + private string _applicationServerAddress; public AspNetHostingEnvironment(IHostingSettings hostingSettings) { @@ -25,6 +26,8 @@ namespace Umbraco.Web.Hosting ?? HostingEnvironment.ApplicationVirtualPath?.EnsureStartsWith("/") ?? "/"; IISVersion = HttpRuntime.IISVersion; + + ApplicationServerAddress = "https://localhost:44354"; // TODO how to find this? } public string SiteName { get; } @@ -32,6 +35,9 @@ namespace Umbraco.Web.Hosting public string ApplicationPhysicalPath { get; } public string ApplicationVirtualPath { get; } + + public string ApplicationServerAddress { get; } + public bool IsDebugMode => HttpContext.Current?.IsDebuggingEnabled ?? _hostingSettings.DebugMode; /// public bool IsHosted => (HttpContext.Current != null || HostingEnvironment.IsHosted); @@ -48,7 +54,7 @@ namespace Umbraco.Web.Hosting } public string ToAbsolute(string virtualPath) => VirtualPathUtility.ToAbsolute(virtualPath, ApplicationVirtualPath); - + public string LocalTempPath { @@ -87,7 +93,7 @@ namespace Umbraco.Web.Hosting } } } - + }