Migrate excludedPaymentMethods from stores

This commit is contained in:
nicolas.dorier 2024-10-08 16:21:44 +09:00
parent 663f97265a
commit ca4a7d8771
No known key found for this signature in database
GPG key ID: 6618763EF09186FE
2 changed files with 25 additions and 0 deletions

View file

@ -217,6 +217,12 @@ namespace BTCPayServer.Hosting
settings.MigrateBlockExplorerLinks = true;
await _Settings.UpdateSetting(settings);
}
if (!settings.MigrateStoreExcludedPaymentMethods)
{
await MigrateStoreExcludedPaymentMethods();
settings.MigrateStoreExcludedPaymentMethods = true;
await _Settings.UpdateSetting(settings);
}
}
catch (Exception ex)
{
@ -225,6 +231,24 @@ namespace BTCPayServer.Hosting
}
}
private async Task MigrateStoreExcludedPaymentMethods()
{
await using var ctx = _DBContextFactory.CreateContext();
var stores = await ctx.Stores.ToArrayAsync();
foreach (var store in stores)
{
var blob = JObject.Parse(store.StoreBlob);
var array = blob["excludedPaymentMethods"] as JArray;
if (array is null || array.Count == 0)
continue;
var newArray = new JArray(array.Select(a => MigrationExtensions.MigratePaymentMethodId(a.Value<string>()))
.ToArray());
if (array.ToString() == newArray.ToString())
continue;
blob["excludedPaymentMethods"] = newArray;
}
}
private async Task MigrateBlockExplorerLinks()
{
await using var ctx = _DBContextFactory.CreateContext();

View file

@ -32,5 +32,6 @@ namespace BTCPayServer.Services
public bool MigrateAppYmlToJson { get; set; }
public bool MigrateToStoreConfig { get; set; }
public bool MigrateBlockExplorerLinks { get; set; }
public bool MigrateStoreExcludedPaymentMethods { get; internal set; }
}
}