From ca4a7d8771dfa1dd8c2ad2d12b51380421a0ab0b Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Tue, 8 Oct 2024 16:21:44 +0900 Subject: [PATCH] Migrate excludedPaymentMethods from stores --- BTCPayServer/Hosting/MigrationStartupTask.cs | 24 ++++++++++++++++++++ BTCPayServer/Services/MigrationSettings.cs | 1 + 2 files changed, 25 insertions(+) diff --git a/BTCPayServer/Hosting/MigrationStartupTask.cs b/BTCPayServer/Hosting/MigrationStartupTask.cs index d18bdaa22..4626b8d50 100644 --- a/BTCPayServer/Hosting/MigrationStartupTask.cs +++ b/BTCPayServer/Hosting/MigrationStartupTask.cs @@ -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())) + .ToArray()); + if (array.ToString() == newArray.ToString()) + continue; + blob["excludedPaymentMethods"] = newArray; + } + } + private async Task MigrateBlockExplorerLinks() { await using var ctx = _DBContextFactory.CreateContext(); diff --git a/BTCPayServer/Services/MigrationSettings.cs b/BTCPayServer/Services/MigrationSettings.cs index cd0225f48..f9742bb3d 100644 --- a/BTCPayServer/Services/MigrationSettings.cs +++ b/BTCPayServer/Services/MigrationSettings.cs @@ -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; } } }