Fix check for pending package migration to use the package not the plan name (#19509)
* Fix check for pending package migration to use the package not plan name. * Cover all package name/identifier permutations and fix the API output for multiple plans * Adjusted log message to not refer to unattended migrations as migrations may be being run attended. --------- Co-authored-by: Kenn Jacobsen <kja@umbraco.dk>
This commit is contained in:
@@ -77,8 +77,9 @@ public class PackageMigrationRunner
|
||||
/// </summary>
|
||||
public async Task<Attempt<bool, PackageMigrationOperationStatus>> RunPendingPackageMigrations(string packageName)
|
||||
{
|
||||
// Check if there are any migrations
|
||||
if (_packageMigrationPlans.ContainsKey(packageName) == false)
|
||||
// Check if there are any migrations (note that the key for _packageMigrationPlans is the migration plan name, not the package name).
|
||||
if (_packageMigrationPlans.Values
|
||||
.Any(x => x.PackageName.InvariantEquals(packageName)) is false)
|
||||
{
|
||||
return Attempt.FailWithStatus(PackageMigrationOperationStatus.NotFound, false);
|
||||
}
|
||||
@@ -121,8 +122,8 @@ public class PackageMigrationRunner
|
||||
}
|
||||
|
||||
using (_profilingLogger.TraceDuration<PackageMigrationRunner>(
|
||||
"Starting unattended package migration for " + migrationName,
|
||||
"Unattended upgrade completed for " + migrationName))
|
||||
"Starting package migration for " + migrationName,
|
||||
"Package migration completed for " + migrationName))
|
||||
{
|
||||
Upgrader upgrader = new(plan);
|
||||
|
||||
|
||||
@@ -314,8 +314,9 @@ public class PackagingService : IPackagingService
|
||||
/// <inheritdoc/>
|
||||
public Task<PagedModel<InstalledPackage>> GetInstalledPackagesFromMigrationPlansAsync(int skip, int take)
|
||||
{
|
||||
IReadOnlyDictionary<string, string?>? keyValues =
|
||||
_keyValueService.FindByKeyPrefix(Constants.Conventions.Migrations.KeyValuePrefix);
|
||||
IReadOnlyDictionary<string, string?> keyValues =
|
||||
_keyValueService.FindByKeyPrefix(Constants.Conventions.Migrations.KeyValuePrefix)
|
||||
?? new Dictionary<string, string?>();
|
||||
|
||||
InstalledPackage[] installedPackages = _packageMigrationPlans
|
||||
.GroupBy(plan => (plan.PackageName, plan.PackageId))
|
||||
@@ -326,15 +327,21 @@ public class PackagingService : IPackagingService
|
||||
PackageName = group.Key.PackageName,
|
||||
};
|
||||
|
||||
var packageKey = Constants.Conventions.Migrations.KeyValuePrefix + (group.Key.PackageId ?? group.Key.PackageName);
|
||||
var currentState = keyValues?
|
||||
.GetValueOrDefault(packageKey);
|
||||
|
||||
package.PackageMigrationPlans = group
|
||||
.Select(plan => new InstalledPackageMigrationPlans
|
||||
.Select(plan =>
|
||||
{
|
||||
CurrentMigrationId = currentState,
|
||||
FinalMigrationId = plan.FinalState,
|
||||
// look for migration states in this order:
|
||||
// - plan name
|
||||
// - package identifier
|
||||
// - package name
|
||||
var currentState =
|
||||
keyValues.GetValueOrDefault($"{Constants.Conventions.Migrations.KeyValuePrefix}{plan.Name}")
|
||||
?? keyValues.GetValueOrDefault($"{Constants.Conventions.Migrations.KeyValuePrefix}{plan.PackageId ?? plan.PackageName}");
|
||||
|
||||
return new InstalledPackageMigrationPlans
|
||||
{
|
||||
CurrentMigrationId = currentState, FinalMigrationId = plan.FinalState,
|
||||
};
|
||||
});
|
||||
|
||||
return package;
|
||||
|
||||
Reference in New Issue
Block a user