streamline runtime level checks
This commit is contained in:
@@ -5,9 +5,26 @@ namespace Umbraco.Extensions
|
||||
{
|
||||
public static class RuntimeStateExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns true if the installer is enabled based on the current runtime state
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
/// <returns></returns>
|
||||
public static bool EnableInstaller(this IRuntimeState state)
|
||||
=> state.Level == RuntimeLevel.Install || state.Level == RuntimeLevel.Upgrade || state.Level == RuntimeLevel.PackageMigrations;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if Umbraco <see cref="IRuntimeState"/> is greater than <see cref="RuntimeLevel.BootFailed"/>
|
||||
/// </summary>
|
||||
public static bool UmbracoCanBoot(this IRuntimeState state) => state.Level > RuntimeLevel.BootFailed;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the runtime state indicates that unattended boot logic should execute
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
/// <returns></returns>
|
||||
public static bool RunUnattendedBootLogic(this IRuntimeState state)
|
||||
=> (state.Reason == RuntimeLevelReason.UpgradeMigrations || state.Reason == RuntimeLevelReason.UpgradePackageMigrations)
|
||||
&& state.Level == RuntimeLevel.Run;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.Cache
|
||||
/// <inheritdoc/>
|
||||
public void Handle(UmbracoApplicationStartingNotification notification)
|
||||
{
|
||||
if (_runtimeState.Level < RuntimeLevel.Run)
|
||||
if (_runtimeState.Level != RuntimeLevel.Run)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanRun() => _mainDom.IsMainDom && _runtimeState.Level >= RuntimeLevel.Run;
|
||||
private bool CanRun() => _mainDom.IsMainDom && _runtimeState.Level == RuntimeLevel.Run;
|
||||
|
||||
private void RebuildIndex(string indexName, TimeSpan delay, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
/// <param name="notification"></param>
|
||||
public void Handle(UmbracoRequestBeginNotification notification)
|
||||
{
|
||||
if (_runtimeState.Level < RuntimeLevel.Run)
|
||||
if (_runtimeState.Level != RuntimeLevel.Run)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using NPoco;
|
||||
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
|
||||
@@ -33,6 +33,8 @@ namespace Umbraco.Cms.Infrastructure.Persistence
|
||||
{
|
||||
var columnInfo = base.GetColumnInfo(mi, type);
|
||||
|
||||
// TODO: Is this upgrade flag still relevant? It's a lot of hacking to just set this value
|
||||
// including the interface method ConfigureForUpgrade for this one circumstance.
|
||||
if (_upgrading)
|
||||
{
|
||||
if (type == typeof(UserDto) && mi.Name == "TourData") columnInfo.IgnoreColumn = true;
|
||||
|
||||
@@ -15,6 +15,7 @@ using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Infrastructure.Migrations.Install;
|
||||
using Umbraco.Cms.Infrastructure.Migrations.Upgrade;
|
||||
using Umbraco.Cms.Infrastructure.Persistence;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.Runtime
|
||||
{
|
||||
@@ -106,7 +107,7 @@ namespace Umbraco.Cms.Infrastructure.Runtime
|
||||
DoUnattendedInstall();
|
||||
DetermineRuntimeLevel();
|
||||
|
||||
if (State.Level <= RuntimeLevel.BootFailed)
|
||||
if (!State.UmbracoCanBoot())
|
||||
{
|
||||
return; // The exception will be rethrown by BootFailedMiddelware
|
||||
}
|
||||
@@ -117,17 +118,14 @@ namespace Umbraco.Cms.Infrastructure.Runtime
|
||||
throw new InvalidOperationException($"An instance of {typeof(IApplicationShutdownRegistry)} could not be resolved from the container, ensure that one if registered in your runtime before calling {nameof(IRuntime)}.{nameof(StartAsync)}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if level is Run and reason is UpgradeMigrations, that means we need to perform an unattended upgrade
|
||||
if (State.Reason == RuntimeLevelReason.UpgradeMigrations && State.Level == RuntimeLevel.Run)
|
||||
if (State.RunUnattendedBootLogic())
|
||||
{
|
||||
// do the upgrade
|
||||
DoUnattendedUpgrade();
|
||||
|
||||
// upgrade is done, set reason to Run
|
||||
DetermineRuntimeLevel();
|
||||
|
||||
}
|
||||
|
||||
// create & initialize the components
|
||||
|
||||
@@ -236,26 +236,36 @@ namespace Umbraco.Cms.Core
|
||||
{
|
||||
// unattended install is not enabled
|
||||
if (_unattendedSettings.Value.InstallUnattended == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// no connection string set
|
||||
if (_databaseFactory.Configured == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var connect = false;
|
||||
var tries = _globalSettings.Value.InstallMissingDatabase ? 2 : 5;
|
||||
|
||||
bool connect;
|
||||
for (var i = 0; ;)
|
||||
{
|
||||
connect = _databaseFactory.CanConnect;
|
||||
if (connect || ++i == tries)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
_logger.LogDebug("Could not immediately connect to database, trying again.");
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
// could not connect to the database
|
||||
if (connect == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using (var database = _databaseFactory.CreateDatabase())
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Security;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Web.BackOffice.Authorization
|
||||
{
|
||||
@@ -30,8 +31,7 @@ namespace Umbraco.Cms.Web.BackOffice.Authorization
|
||||
|
||||
switch (_runtimeState.Level)
|
||||
{
|
||||
case RuntimeLevel.Install:
|
||||
case RuntimeLevel.Upgrade:
|
||||
case var _ when _runtimeState.EnableInstaller():
|
||||
return Task.FromResult(true);
|
||||
default:
|
||||
if (!_backOfficeSecurity.BackOfficeSecurity.IsAuthenticated())
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Umbraco.Cms.Core;
|
||||
@@ -29,9 +29,8 @@ namespace Umbraco.Cms.Web.BackOffice.Install
|
||||
|
||||
switch (_runtime.Level)
|
||||
{
|
||||
case RuntimeLevel.Install:
|
||||
case RuntimeLevel.Upgrade:
|
||||
|
||||
case var _ when _runtime.EnableInstaller():
|
||||
|
||||
endpoints.MapUmbracoRoute<InstallApiController>(installPathSegment, Cms.Core.Constants.Web.Mvc.InstallArea, "api", includeControllerNameInRoute: false);
|
||||
endpoints.MapUmbracoRoute<InstallController>(installPathSegment, Cms.Core.Constants.Web.Mvc.InstallArea, string.Empty, includeControllerNameInRoute: false);
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Web.BackOffice.Install
|
||||
{
|
||||
@@ -44,8 +45,7 @@ namespace Umbraco.Cms.Web.BackOffice.Install
|
||||
{
|
||||
// if not configured (install or upgrade) then we can continue
|
||||
// otherwise we need to ensure that a user is logged in
|
||||
return _runtimeState.Level == RuntimeLevel.Install
|
||||
|| _runtimeState.Level == RuntimeLevel.Upgrade
|
||||
return _runtimeState.EnableInstaller()
|
||||
|| (authorizationFilterContext.HttpContext.User?.Identity?.IsAuthenticated ?? false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace Umbraco.Cms.Web.BackOffice.Routing
|
||||
{
|
||||
case RuntimeLevel.Install:
|
||||
case RuntimeLevel.Upgrade:
|
||||
case RuntimeLevel.PackageMigrations:
|
||||
case RuntimeLevel.Run:
|
||||
|
||||
MapMinimalBackOffice(endpoints);
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace Umbraco.Cms.Web.BackOffice.Routing
|
||||
{
|
||||
case RuntimeLevel.Install:
|
||||
case RuntimeLevel.Upgrade:
|
||||
case RuntimeLevel.PackageMigrations:
|
||||
case RuntimeLevel.Run:
|
||||
endpoints.MapHub<PreviewHub>(GetPreviewHubRoute());
|
||||
endpoints.MapUmbracoRoute<PreviewController>(_umbracoPathSegment, Constants.Web.Mvc.BackOfficeArea, null);
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Umbraco.Cms.Web.Common.Profiler
|
||||
|
||||
public void UmbracoApplicationBeginRequest(HttpContext context, RuntimeLevel runtimeLevel)
|
||||
{
|
||||
if (runtimeLevel < RuntimeLevel.Run)
|
||||
if (runtimeLevel != RuntimeLevel.Run)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -55,7 +55,7 @@ namespace Umbraco.Cms.Web.Common.Profiler
|
||||
|
||||
public void UmbracoApplicationEndRequest(HttpContext context, RuntimeLevel runtimeLevel)
|
||||
{
|
||||
if (runtimeLevel < RuntimeLevel.Run)
|
||||
if (runtimeLevel != RuntimeLevel.Run)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user