diff --git a/src/Umbraco.Infrastructure/Install/PackageMigrationRunner.cs b/src/Umbraco.Infrastructure/Install/PackageMigrationRunner.cs index db054b2dc5..348496a03c 100644 --- a/src/Umbraco.Infrastructure/Install/PackageMigrationRunner.cs +++ b/src/Umbraco.Infrastructure/Install/PackageMigrationRunner.cs @@ -1,4 +1,7 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Umbraco.Cms.Core; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Logging; using Umbraco.Cms.Core.Migrations; @@ -32,7 +35,8 @@ public class PackageMigrationRunner PackageMigrationPlanCollection packageMigrationPlans, IMigrationPlanExecutor migrationPlanExecutor, IKeyValueService keyValueService, - IEventAggregator eventAggregator) + IEventAggregator eventAggregator, + ILogger logger) { _profilingLogger = profilingLogger; _scopeProvider = scopeProvider; @@ -43,6 +47,27 @@ public class PackageMigrationRunner _packageMigrationPlans = packageMigrationPlans.ToDictionary(x => x.Name); } + [Obsolete("Use constructor that takes ILogger, this will be removed in V13")] + public PackageMigrationRunner( + IProfilingLogger profilingLogger, + ICoreScopeProvider scopeProvider, + PendingPackageMigrations pendingPackageMigrations, + PackageMigrationPlanCollection packageMigrationPlans, + IMigrationPlanExecutor migrationPlanExecutor, + IKeyValueService keyValueService, + IEventAggregator eventAggregator) + : this( + profilingLogger, + scopeProvider, + pendingPackageMigrations, + packageMigrationPlans, + migrationPlanExecutor, + keyValueService, + eventAggregator, + StaticServiceProvider.Instance.GetRequiredService>()) + { + } + /// /// Runs all migration plans for a package name if any are pending. /// diff --git a/src/Umbraco.Infrastructure/Migrations/IMigrationContext.cs b/src/Umbraco.Infrastructure/Migrations/IMigrationContext.cs index 6af5af23a3..5e0766755a 100644 --- a/src/Umbraco.Infrastructure/Migrations/IMigrationContext.cs +++ b/src/Umbraco.Infrastructure/Migrations/IMigrationContext.cs @@ -41,6 +41,7 @@ public interface IMigrationContext /// /// Adds a post-migration. /// + [Obsolete("This will be removed in the V13, and replaced with a RebuildCache flag on the MigrationBase")] void AddPostMigration() where TMigration : MigrationBase; } diff --git a/src/Umbraco.Infrastructure/Migrations/IMigrationPlanExecutor.cs b/src/Umbraco.Infrastructure/Migrations/IMigrationPlanExecutor.cs index 552ca21b5e..78ae07ccf5 100644 --- a/src/Umbraco.Infrastructure/Migrations/IMigrationPlanExecutor.cs +++ b/src/Umbraco.Infrastructure/Migrations/IMigrationPlanExecutor.cs @@ -4,5 +4,12 @@ namespace Umbraco.Cms.Core.Migrations; public interface IMigrationPlanExecutor { + [Obsolete("Use ExecutePlan instead.")] string Execute(MigrationPlan plan, string fromState); + + ExecutedMigrationPlan ExecutePlan(MigrationPlan plan, string fromState) + { + var state = Execute(plan, fromState); + return new ExecutedMigrationPlan(plan, fromState, state); + } } diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs index bd3fc6849d..3abd2216ec 100644 --- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs +++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs @@ -1,9 +1,12 @@ using System.Data.Common; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.DependencyInjection; +using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Install; using Umbraco.Cms.Core.Install.Models; using Umbraco.Cms.Core.Migrations; @@ -54,7 +57,8 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install IOptionsMonitor connectionStrings, IMigrationPlanExecutor migrationPlanExecutor, DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory, - IEnumerable databaseProviderMetadata) + IEnumerable databaseProviderMetadata, + IEventAggregator eventAggregator) { _scopeProvider = scopeProvider; _scopeAccessor = scopeAccessor; @@ -71,6 +75,40 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install _databaseProviderMetadata = databaseProviderMetadata; } + [Obsolete("Use constructor that takes IEventAggregator, this will be removed in V13.")] + public DatabaseBuilder( + ICoreScopeProvider scopeProvider, + IScopeAccessor scopeAccessor, + IUmbracoDatabaseFactory databaseFactory, + IRuntimeState runtimeState, + ILoggerFactory loggerFactory, + IKeyValueService keyValueService, + IDbProviderFactoryCreator dbProviderFactoryCreator, + IConfigManipulator configManipulator, + IOptionsMonitor globalSettings, + IOptionsMonitor connectionStrings, + IMigrationPlanExecutor migrationPlanExecutor, + DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory, + IEnumerable databaseProviderMetadata) + : this( + scopeProvider, + scopeAccessor, + databaseFactory, + runtimeState, + loggerFactory, + keyValueService, + dbProviderFactoryCreator, + configManipulator, + globalSettings, + connectionStrings, + migrationPlanExecutor, + databaseSchemaCreatorFactory, + databaseProviderMetadata, + StaticServiceProvider.Instance.GetRequiredService() + ) + { + } + #region Status /// diff --git a/src/Umbraco.Infrastructure/Migrations/MigrationContext.cs b/src/Umbraco.Infrastructure/Migrations/MigrationContext.cs index eaf2eb4f4d..f400a71420 100644 --- a/src/Umbraco.Infrastructure/Migrations/MigrationContext.cs +++ b/src/Umbraco.Infrastructure/Migrations/MigrationContext.cs @@ -22,6 +22,7 @@ internal class MigrationContext : IMigrationContext } // this is only internally exposed + [Obsolete("This will be removed in the V13, and replaced with a RebuildCache flag on the MigrationBase")] public IReadOnlyList PostMigrations => _postMigrations; /// @@ -42,6 +43,7 @@ internal class MigrationContext : IMigrationContext public bool BuildingExpression { get; set; } /// + [Obsolete("This will be removed in the V13, and replaced with a RebuildCache flag on the MigrationBase, and a UmbracoPlanExecutedNotification.")] public void AddPostMigration() where TMigration : MigrationBase => diff --git a/src/Umbraco.Infrastructure/Migrations/MigrationPlan.cs b/src/Umbraco.Infrastructure/Migrations/MigrationPlan.cs index 68b870bb7c..0ce07475d7 100644 --- a/src/Umbraco.Infrastructure/Migrations/MigrationPlan.cs +++ b/src/Umbraco.Infrastructure/Migrations/MigrationPlan.cs @@ -45,6 +45,7 @@ public class MigrationPlan /// public IReadOnlyDictionary Transitions => _transitions; + [Obsolete("This will be removed in the V13, and replaced with a RebuildCache flag on the MigrationBase")] public IReadOnlyList PostMigrationTypes => _postMigrationTypes; /// @@ -296,6 +297,7 @@ public class MigrationPlan /// /// Adds a post-migration to the plan. /// + [Obsolete("This will be removed in the V13, and replaced with a RebuildCache flag on the MigrationBase")] public virtual MigrationPlan AddPostMigration() where TMigration : MigrationBase { diff --git a/src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs b/src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs index caf498132e..69e69ee85b 100644 --- a/src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs +++ b/src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs @@ -1,6 +1,11 @@ +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Umbraco.Cms.Core.Cache; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Migrations; +using Umbraco.Cms.Core.PublishedCache; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Infrastructure.Migrations; @@ -17,7 +22,10 @@ public class MigrationPlanExecutor : IMigrationPlanExecutor ICoreScopeProvider scopeProvider, IScopeAccessor scopeAccessor, ILoggerFactory loggerFactory, - IMigrationBuilder migrationBuilder) + IMigrationBuilder migrationBuilder, + IUmbracoDatabaseFactory databaseFactory, + IPublishedSnapshotService publishedSnapshotService, + DistributedCache distributedCache) { _scopeProvider = scopeProvider; _scopeAccessor = scopeAccessor; @@ -26,6 +34,23 @@ public class MigrationPlanExecutor : IMigrationPlanExecutor _logger = _loggerFactory.CreateLogger(); } + [Obsolete("Use constructor with 7 parameters")] + public MigrationPlanExecutor( + ICoreScopeProvider scopeProvider, + IScopeAccessor scopeAccessor, + ILoggerFactory loggerFactory, + IMigrationBuilder migrationBuilder) + : this( + scopeProvider, + scopeAccessor, + loggerFactory, + migrationBuilder, + StaticServiceProvider.Instance.GetRequiredService(), + StaticServiceProvider.Instance.GetRequiredService(), + StaticServiceProvider.Instance.GetRequiredService()) + { + } + /// /// Executes the plan. /// @@ -36,6 +61,7 @@ public class MigrationPlanExecutor : IMigrationPlanExecutor /// /// The final state. /// The plan executes within the scope, which must then be completed. + [Obsolete("This will return an ExecutedMigrationPlan in V13")] public string Execute(MigrationPlan plan, string fromState) { plan.Validate(); diff --git a/src/Umbraco.Infrastructure/Migrations/PostMigrations/ClearCsrfCookies.cs b/src/Umbraco.Infrastructure/Migrations/PostMigrations/ClearCsrfCookies.cs index c991d35f01..a343635666 100644 --- a/src/Umbraco.Infrastructure/Migrations/PostMigrations/ClearCsrfCookies.cs +++ b/src/Umbraco.Infrastructure/Migrations/PostMigrations/ClearCsrfCookies.cs @@ -6,6 +6,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.PostMigrations; /// /// Clears Csrf tokens. /// +[Obsolete("Removed in the V13, and replaced with a notification handler")] public class ClearCsrfCookies : MigrationBase { private readonly ICookieManager _cookieManager; diff --git a/src/Umbraco.Infrastructure/Migrations/PostMigrations/DeleteLogViewerQueryFile.cs b/src/Umbraco.Infrastructure/Migrations/PostMigrations/DeleteLogViewerQueryFile.cs index a75b01edaf..ac7260bd74 100644 --- a/src/Umbraco.Infrastructure/Migrations/PostMigrations/DeleteLogViewerQueryFile.cs +++ b/src/Umbraco.Infrastructure/Migrations/PostMigrations/DeleteLogViewerQueryFile.cs @@ -6,6 +6,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.PostMigrations; /// /// Deletes the old file that saved log queries /// +[Obsolete("This will be removed in the V13")] public class DeleteLogViewerQueryFile : MigrationBase { private readonly IHostingEnvironment _hostingEnvironment; @@ -26,5 +27,6 @@ public class DeleteLogViewerQueryFile : MigrationBase // { // File.Delete(logViewerQueryFile); // } + // }Rebuild } } diff --git a/src/Umbraco.Infrastructure/Migrations/PostMigrations/RebuildPublishedSnapshot.cs b/src/Umbraco.Infrastructure/Migrations/PostMigrations/RebuildPublishedSnapshot.cs index f8f81acd7b..c0cc2c2993 100644 --- a/src/Umbraco.Infrastructure/Migrations/PostMigrations/RebuildPublishedSnapshot.cs +++ b/src/Umbraco.Infrastructure/Migrations/PostMigrations/RebuildPublishedSnapshot.cs @@ -3,6 +3,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.PostMigrations; /// /// Rebuilds the published snapshot. /// +[Obsolete("This will be removed in the V13, and replaced with a RebuildCache flag on the MigrationBase")] public class RebuildPublishedSnapshot : MigrationBase { private readonly IPublishedSnapshotRebuilder _rebuilder; diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/Upgrader.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/Upgrader.cs index e67ed8da43..e5b8c7d055 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/Upgrader.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/Upgrader.cs @@ -70,7 +70,7 @@ public class Upgrader } // execute plan - var state = migrationPlanExecutor.Execute(Plan, currentState); + var state = migrationPlanExecutor.ExecutePlan(Plan, currentState).FinalState; if (string.IsNullOrWhiteSpace(state)) { throw new InvalidOperationException("Plan execution returned an invalid null or empty state."); diff --git a/tests/Umbraco.Tests.UnitTests/AutoFixture/Customizations/UmbracoCustomizations.cs b/tests/Umbraco.Tests.UnitTests/AutoFixture/Customizations/UmbracoCustomizations.cs index 76643279fa..7b840b18da 100644 --- a/tests/Umbraco.Tests.UnitTests/AutoFixture/Customizations/UmbracoCustomizations.cs +++ b/tests/Umbraco.Tests.UnitTests/AutoFixture/Customizations/UmbracoCustomizations.cs @@ -39,7 +39,8 @@ internal class UmbracoCustomizations : ICustomization .Customize(new ConstructorCustomization(typeof(MemberManager), new GreedyConstructorQuery())) .Customize(new ConstructorCustomization(typeof(DatabaseSchemaCreatorFactory), new GreedyConstructorQuery())) .Customize(new ConstructorCustomization(typeof(BackOfficeServerVariables), new GreedyConstructorQuery())) - .Customize(new ConstructorCustomization(typeof(InstallHelper), new GreedyConstructorQuery())); + .Customize(new ConstructorCustomization(typeof(InstallHelper), new GreedyConstructorQuery())) + .Customize(new ConstructorCustomization(typeof(DatabaseBuilder), new GreedyConstructorQuery())); // When requesting an IUserStore ensure we actually uses a IUserLockoutStore fixture.Customize>(cc => diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationPlanTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationPlanTests.cs index 8349974ebd..56c85e4157 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationPlanTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationPlanTests.cs @@ -9,9 +9,12 @@ using Microsoft.Extensions.Options; using Moq; using NPoco; using NUnit.Framework; +using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Events; +using Umbraco.Cms.Core.PublishedCache; using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Sync; using Umbraco.Cms.Infrastructure.Migrations; using Umbraco.Cms.Infrastructure.Migrations.Upgrade; using Umbraco.Cms.Infrastructure.Persistence; @@ -59,7 +62,17 @@ public class MigrationPlanTests } }); - var executor = new MigrationPlanExecutor(scopeProvider, scopeProvider, loggerFactory, migrationBuilder); + var databaseFactory = Mock.Of(); + var publishedSnapshotService = Mock.Of(); + var distributedCache = new DistributedCache(Mock.Of(), new CacheRefresherCollection(Enumerable.Empty)); + var executor = new MigrationPlanExecutor( + scopeProvider, + scopeProvider, + loggerFactory, + migrationBuilder, + databaseFactory, + publishedSnapshotService, + distributedCache); var plan = new MigrationPlan("default") .From(string.Empty) diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs index fdae9cda06..69fc050d31 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs @@ -8,11 +8,14 @@ using Microsoft.Extensions.Options; using Moq; using NPoco; using NUnit.Framework; +using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Migrations; +using Umbraco.Cms.Core.PublishedCache; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Sync; using Umbraco.Cms.Infrastructure.Migrations; using Umbraco.Cms.Infrastructure.Migrations.Upgrade; using Umbraco.Cms.Infrastructure.Persistence; @@ -32,7 +35,12 @@ public class PostMigrationTests ICoreScopeProvider scopeProvider, IScopeAccessor scopeAccessor, IMigrationBuilder builder) - => new MigrationPlanExecutor(scopeProvider, scopeAccessor, s_loggerFactory, builder); + { + var databaseFactory = Mock.Of(); + var publishedSnapshotService = Mock.Of(); + var distributedCache = new DistributedCache(Mock.Of(), new CacheRefresherCollection(Enumerable.Empty)); + return new MigrationPlanExecutor(scopeProvider, scopeAccessor, s_loggerFactory, builder, databaseFactory, publishedSnapshotService, distributedCache); + } [Test] public void ExecutesPlanPostMigration()