From d7c0c6a93287d05257073a85d4cd4a491a4573c8 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Thu, 17 Jun 2021 18:00:49 +1000 Subject: [PATCH] Adjust the runtime state and keep disabling unattended package migrations simple (#10486) * Clean up and changes to backoffice for the nuget only packages * temp commit of package logic removal * Lots of package code cleanup and removal * Removes old package data from the test package xml * Updates packaging code to take in XDocument instead of a file since we'll not be dealing with files, starts creating expressions for the package migrations scripting. * fixing tests * Fixes runtime state and boot failed middleware so that it actually runs. Separates out unattended install/upgrade into notification handlers. * Gets unattended package migrations working and running * Gets embedded package.xml resources able to install from package migration. * Implements automatic package migrations for package that just declare an xml data manifest. * fix build * small cleanups * fix build * adds some tests * Fix export test * Fix newlines in test for linux * Typo * removes old todos and updates AutomaticPackgeMigrationPlan to use getter with backing field. * Update dictionary package data to use GUID * Ensures macros are packaged and used with their GUID * Ensures the GUID for doc types and media types remains consistent for package installation based on what is in the xml. * fix automatic migrations to not validate initial state, fixes packaging GUIDs for multiple entities. * Added guids to embedded test packages (Some tests are still failing) * Fix one more test * Fixes up Key vs Id, moves tests to correct namespace, fix tests * Fixes Dictionary packaging to ensure an xml hierarchy * Fixes tests * fixes package xml * Removes the runtime PackageMigrations state, the state is just run if unattended migrations are disabled. * change log level * Small clean up and reuse of attribute Co-authored-by: Bjarke Berg --- src/Umbraco.Core/Extensions/XmlExtensions.cs | 11 ++++++----- src/Umbraco.Core/RuntimeLevel.cs | 7 +------ .../Runtime/RuntimeState.cs | 17 ++++++++++++++--- .../Umbraco.Core/RuntimeStateTests.cs | 6 +++--- .../Routing/BackOfficeAreaRoutes.cs | 1 - .../Routing/PreviewRoutes.cs | 1 - 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/Umbraco.Core/Extensions/XmlExtensions.cs b/src/Umbraco.Core/Extensions/XmlExtensions.cs index 8ad37bd93e..aa3fe25eef 100644 --- a/src/Umbraco.Core/Extensions/XmlExtensions.cs +++ b/src/Umbraco.Core/Extensions/XmlExtensions.cs @@ -8,6 +8,7 @@ using System.Text; using System.Xml; using System.Xml.Linq; using System.Xml.XPath; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Xml; namespace Umbraco.Extensions @@ -238,7 +239,7 @@ namespace Umbraco.Extensions { if (xml == null) { - throw new ArgumentNullException("xml"); + throw new ArgumentNullException(nameof(xml)); } if (xml.HasAttributes == false) @@ -246,19 +247,19 @@ namespace Umbraco.Extensions throw new InvalidOperationException($"{attributeName} not found in xml"); } - if (xml.Attribute(attributeName) == null) + XAttribute attribute = xml.Attribute(attributeName); + if (attribute is null) { throw new InvalidOperationException($"{attributeName} not found in xml"); } - var val = xml.Attribute(attributeName).Value; - var result = val.TryConvertTo(); + Attempt result = attribute.Value.TryConvertTo(); if (result.Success) { return result.Result; } - throw new InvalidOperationException($"{val} attribute value cannot be converted to {typeof(T)}"); + throw new InvalidOperationException($"{attribute.Value} attribute value cannot be converted to {typeof(T)}"); } public static T AttributeValue(this XElement xml, string attributeName) diff --git a/src/Umbraco.Core/RuntimeLevel.cs b/src/Umbraco.Core/RuntimeLevel.cs index 4330c33d94..d6687d4628 100644 --- a/src/Umbraco.Core/RuntimeLevel.cs +++ b/src/Umbraco.Core/RuntimeLevel.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Cms.Core +namespace Umbraco.Cms.Core { /// /// Describes the levels in which the runtime can run. @@ -32,11 +32,6 @@ /// Upgrade = 3, - /// - /// The runtime has detected that Package Migrations need to be executed. - /// - PackageMigrations = 4, - /// /// The runtime has detected an up-to-date Umbraco install and is running. /// diff --git a/src/Umbraco.Infrastructure/Runtime/RuntimeState.cs b/src/Umbraco.Infrastructure/Runtime/RuntimeState.cs index add276760f..42a7e0812d 100644 --- a/src/Umbraco.Infrastructure/Runtime/RuntimeState.cs +++ b/src/Umbraco.Infrastructure/Runtime/RuntimeState.cs @@ -144,9 +144,20 @@ namespace Umbraco.Cms.Infrastructure.Runtime break; case UmbracoDatabaseState.NeedsPackageMigration: - _logger.LogDebug("Package migrations need to execute."); - Level = _unattendedSettings.Value.PackageMigrationsUnattended ? RuntimeLevel.Run : RuntimeLevel.PackageMigrations; - Reason = RuntimeLevelReason.UpgradePackageMigrations; + // no matter what the level is run for package migrations. + // they either run unattended, or only manually via the back office. + Level = RuntimeLevel.Run; + + if (_unattendedSettings.Value.PackageMigrationsUnattended) + { + _logger.LogDebug("Package migrations need to execute."); + Reason = RuntimeLevelReason.UpgradePackageMigrations; + } + else + { + _logger.LogInformation("Package migrations need to execute but unattended package migrations is disabled. They will need to be run from the back office."); + Reason = RuntimeLevelReason.Run; + } break; case UmbracoDatabaseState.Ok: diff --git a/src/Umbraco.Tests.Integration/Umbraco.Core/RuntimeStateTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Core/RuntimeStateTests.cs index c9838361c6..60d36cb87b 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Core/RuntimeStateTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Core/RuntimeStateTests.cs @@ -60,15 +60,15 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Core } [Test] - public void GivenPackageMigrationsExist_WhenNotUnattendedMigrations_ThenLevelIsPackageMigrations() + public void GivenPackageMigrationsExist_WhenNotUnattendedMigrations_ThenLevelIsRun() { var unattendedOptions = Services.GetRequiredService>(); unattendedOptions.Value.PackageMigrationsUnattended = false; RuntimeState.DetermineRuntimeLevel(); - Assert.AreEqual(RuntimeLevel.PackageMigrations, RuntimeState.Level); - Assert.AreEqual(RuntimeLevelReason.UpgradePackageMigrations, RuntimeState.Reason); + Assert.AreEqual(RuntimeLevel.Run, RuntimeState.Level); + Assert.AreEqual(RuntimeLevelReason.Run, RuntimeState.Reason); } private class TestMigrationPlan : PackageMigrationPlan diff --git a/src/Umbraco.Web.BackOffice/Routing/BackOfficeAreaRoutes.cs b/src/Umbraco.Web.BackOffice/Routing/BackOfficeAreaRoutes.cs index 3f171d6439..13d57ccc43 100644 --- a/src/Umbraco.Web.BackOffice/Routing/BackOfficeAreaRoutes.cs +++ b/src/Umbraco.Web.BackOffice/Routing/BackOfficeAreaRoutes.cs @@ -48,7 +48,6 @@ namespace Umbraco.Cms.Web.BackOffice.Routing { case RuntimeLevel.Install: case RuntimeLevel.Upgrade: - case RuntimeLevel.PackageMigrations: case RuntimeLevel.Run: MapMinimalBackOffice(endpoints); diff --git a/src/Umbraco.Web.BackOffice/Routing/PreviewRoutes.cs b/src/Umbraco.Web.BackOffice/Routing/PreviewRoutes.cs index 15012728d9..bda08d0d87 100644 --- a/src/Umbraco.Web.BackOffice/Routing/PreviewRoutes.cs +++ b/src/Umbraco.Web.BackOffice/Routing/PreviewRoutes.cs @@ -36,7 +36,6 @@ namespace Umbraco.Cms.Web.BackOffice.Routing { case RuntimeLevel.Install: case RuntimeLevel.Upgrade: - case RuntimeLevel.PackageMigrations: case RuntimeLevel.Run: endpoints.MapHub(GetPreviewHubRoute()); endpoints.MapUmbracoRoute(_umbracoPathSegment, Constants.Web.Mvc.BackOfficeArea, null);