Obsolete things broken in migrations refactor (#13658)
* Obsolete chings changed in v13 * Fix tests * Obsolete Execute and add ExecutePlan with default implementation. This just calls the old implementation and creates an ExecutedMigrationPlan from the result In V13 this has its own implementation. * Mention notification in obsolete message
This commit is contained in:
@@ -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<PackageMigrationRunner> 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<ILogger<PackageMigrationRunner>>())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs all migration plans for a package name if any are pending.
|
||||
/// </summary>
|
||||
|
||||
@@ -41,6 +41,7 @@ public interface IMigrationContext
|
||||
/// <summary>
|
||||
/// Adds a post-migration.
|
||||
/// </summary>
|
||||
[Obsolete("This will be removed in the V13, and replaced with a RebuildCache flag on the MigrationBase")]
|
||||
void AddPostMigration<TMigration>()
|
||||
where TMigration : MigrationBase;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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> connectionStrings,
|
||||
IMigrationPlanExecutor migrationPlanExecutor,
|
||||
DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory,
|
||||
IEnumerable<IDatabaseProviderMetadata> databaseProviderMetadata)
|
||||
IEnumerable<IDatabaseProviderMetadata> 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> globalSettings,
|
||||
IOptionsMonitor<ConnectionStrings> connectionStrings,
|
||||
IMigrationPlanExecutor migrationPlanExecutor,
|
||||
DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory,
|
||||
IEnumerable<IDatabaseProviderMetadata> databaseProviderMetadata)
|
||||
: this(
|
||||
scopeProvider,
|
||||
scopeAccessor,
|
||||
databaseFactory,
|
||||
runtimeState,
|
||||
loggerFactory,
|
||||
keyValueService,
|
||||
dbProviderFactoryCreator,
|
||||
configManipulator,
|
||||
globalSettings,
|
||||
connectionStrings,
|
||||
migrationPlanExecutor,
|
||||
databaseSchemaCreatorFactory,
|
||||
databaseProviderMetadata,
|
||||
StaticServiceProvider.Instance.GetRequiredService<IEventAggregator>()
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
#region Status
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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<Type> PostMigrations => _postMigrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -42,6 +43,7 @@ internal class MigrationContext : IMigrationContext
|
||||
public bool BuildingExpression { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[Obsolete("This will be removed in the V13, and replaced with a RebuildCache flag on the MigrationBase, and a UmbracoPlanExecutedNotification.")]
|
||||
public void AddPostMigration<TMigration>()
|
||||
where TMigration : MigrationBase =>
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ public class MigrationPlan
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, Transition?> Transitions => _transitions;
|
||||
|
||||
[Obsolete("This will be removed in the V13, and replaced with a RebuildCache flag on the MigrationBase")]
|
||||
public IReadOnlyList<Type> PostMigrationTypes => _postMigrationTypes;
|
||||
|
||||
/// <summary>
|
||||
@@ -296,6 +297,7 @@ public class MigrationPlan
|
||||
/// <summary>
|
||||
/// Adds a post-migration to the plan.
|
||||
/// </summary>
|
||||
[Obsolete("This will be removed in the V13, and replaced with a RebuildCache flag on the MigrationBase")]
|
||||
public virtual MigrationPlan AddPostMigration<TMigration>()
|
||||
where TMigration : MigrationBase
|
||||
{
|
||||
|
||||
@@ -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<MigrationPlanExecutor>();
|
||||
}
|
||||
|
||||
[Obsolete("Use constructor with 7 parameters")]
|
||||
public MigrationPlanExecutor(
|
||||
ICoreScopeProvider scopeProvider,
|
||||
IScopeAccessor scopeAccessor,
|
||||
ILoggerFactory loggerFactory,
|
||||
IMigrationBuilder migrationBuilder)
|
||||
: this(
|
||||
scopeProvider,
|
||||
scopeAccessor,
|
||||
loggerFactory,
|
||||
migrationBuilder,
|
||||
StaticServiceProvider.Instance.GetRequiredService<IUmbracoDatabaseFactory>(),
|
||||
StaticServiceProvider.Instance.GetRequiredService<IPublishedSnapshotService>(),
|
||||
StaticServiceProvider.Instance.GetRequiredService<DistributedCache>())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the plan.
|
||||
/// </summary>
|
||||
@@ -36,6 +61,7 @@ public class MigrationPlanExecutor : IMigrationPlanExecutor
|
||||
/// <param name="loggerFactory"></param>
|
||||
/// <returns>The final state.</returns>
|
||||
/// <remarks>The plan executes within the scope, which must then be completed.</remarks>
|
||||
[Obsolete("This will return an ExecutedMigrationPlan in V13")]
|
||||
public string Execute(MigrationPlan plan, string fromState)
|
||||
{
|
||||
plan.Validate();
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.PostMigrations;
|
||||
/// <summary>
|
||||
/// Clears Csrf tokens.
|
||||
/// </summary>
|
||||
[Obsolete("Removed in the V13, and replaced with a notification handler")]
|
||||
public class ClearCsrfCookies : MigrationBase
|
||||
{
|
||||
private readonly ICookieManager _cookieManager;
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.PostMigrations;
|
||||
/// <summary>
|
||||
/// Deletes the old file that saved log queries
|
||||
/// </summary>
|
||||
[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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.PostMigrations;
|
||||
/// <summary>
|
||||
/// Rebuilds the published snapshot.
|
||||
/// </summary>
|
||||
[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;
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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<IUserStore<BackOfficeIdentityUser>>(cc =>
|
||||
|
||||
@@ -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<IUmbracoDatabaseFactory>();
|
||||
var publishedSnapshotService = Mock.Of<IPublishedSnapshotService>();
|
||||
var distributedCache = new DistributedCache(Mock.Of<IServerMessenger>(), new CacheRefresherCollection(Enumerable.Empty<ICacheRefresher>));
|
||||
var executor = new MigrationPlanExecutor(
|
||||
scopeProvider,
|
||||
scopeProvider,
|
||||
loggerFactory,
|
||||
migrationBuilder,
|
||||
databaseFactory,
|
||||
publishedSnapshotService,
|
||||
distributedCache);
|
||||
|
||||
var plan = new MigrationPlan("default")
|
||||
.From(string.Empty)
|
||||
|
||||
@@ -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<IUmbracoDatabaseFactory>();
|
||||
var publishedSnapshotService = Mock.Of<IPublishedSnapshotService>();
|
||||
var distributedCache = new DistributedCache(Mock.Of<IServerMessenger>(), new CacheRefresherCollection(Enumerable.Empty<ICacheRefresher>));
|
||||
return new MigrationPlanExecutor(scopeProvider, scopeAccessor, s_loggerFactory, builder, databaseFactory, publishedSnapshotService, distributedCache);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExecutesPlanPostMigration()
|
||||
|
||||
Reference in New Issue
Block a user