mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-04 01:53:52 +01:00
Migrate reference to AppType in server settings (Fix #4882)
This commit is contained in:
parent
7d14cd74f2
commit
8e60932f81
3 changed files with 70 additions and 0 deletions
|
@ -2445,6 +2445,31 @@ namespace BTCPayServer.Tests
|
|||
Assert.False(fn.Seen);
|
||||
}
|
||||
|
||||
[Fact(Timeout = LongRunningTestTimeout)]
|
||||
[Trait("Integration", "Integration")]
|
||||
public async Task CanFixMappedDomainAppType()
|
||||
{
|
||||
using var tester = CreateServerTester(newDb: true);
|
||||
await tester.StartAsync();
|
||||
var f = tester.PayTester.GetService<ApplicationDbContextFactory>();
|
||||
using (var ctx = f.CreateContext())
|
||||
{
|
||||
var setting = new SettingData() { Id = "BTCPayServer.Services.PoliciesSettings" };
|
||||
setting.Value = JObject.Parse("{\"RootAppId\": null, \"RootAppType\": 1, \"Experimental\": false, \"PluginSource\": null, \"LockSubscription\": false, \"DisableSSHService\": false, \"PluginPreReleases\": false, \"BlockExplorerLinks\": [],\"DomainToAppMapping\": [{\"AppId\": \"87kj5yKay8mB4UUZcJhZH5TqDKMD3CznjwLjiu1oYZXe\", \"Domain\": \"donate.nicolas-dorier.com\", \"AppType\": 0}], \"CheckForNewVersions\": false, \"AllowHotWalletForAll\": false, \"RequiresConfirmedEmail\": false, \"DiscourageSearchEngines\": false, \"DisableInstantNotifications\": false, \"DisableNonAdminCreateUserApi\": false, \"AllowHotWalletRPCImportForAll\": false, \"AllowLightningInternalNodeForAll\": false, \"DisableStoresToUseServerEmailSettings\": false}").ToString();
|
||||
ctx.Settings.Add(setting);
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
await RestartMigration(tester);
|
||||
using (var ctx = f.CreateContext())
|
||||
{
|
||||
var setting = await ctx.Settings.FirstOrDefaultAsync(c => c.Id == "BTCPayServer.Services.PoliciesSettings");
|
||||
var o = JObject.Parse(setting.Value);
|
||||
Assert.Equal("Crowdfund", o["RootAppType"].Value<string>());
|
||||
o = (JObject)((JArray)o["DomainToAppMapping"])[0];
|
||||
Assert.Equal("PointOfSale", o["AppType"].Value<string>());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact(Timeout = LongRunningTestTimeout)]
|
||||
[Trait("Integration", "Integration")]
|
||||
public async Task CanDoLightningInternalNodeMigration()
|
||||
|
|
|
@ -242,6 +242,12 @@ namespace BTCPayServer.Hosting
|
|||
settings.FixSeqAfterSqliteMigration = true;
|
||||
await _Settings.UpdateSetting(settings);
|
||||
}
|
||||
if (!settings.FixMappedDomainAppType)
|
||||
{
|
||||
await FixMappedDomainAppType();
|
||||
settings.FixMappedDomainAppType = true;
|
||||
await _Settings.UpdateSetting(settings);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -250,6 +256,44 @@ namespace BTCPayServer.Hosting
|
|||
}
|
||||
}
|
||||
|
||||
private async Task FixMappedDomainAppType()
|
||||
{
|
||||
await using var ctx = _DBContextFactory.CreateContext();
|
||||
var setting = await ctx.Settings.FirstOrDefaultAsync(s => s.Id == "BTCPayServer.Services.PoliciesSettings");
|
||||
if (setting?.Value is null)
|
||||
return;
|
||||
string MapToString(int v)
|
||||
{
|
||||
return v switch
|
||||
{
|
||||
0 => "PointOfSale",
|
||||
1 => "Crowdfund",
|
||||
_ => throw new NotSupportedException()
|
||||
};
|
||||
}
|
||||
var data = JObject.Parse(setting.Value);
|
||||
if (data["RootAppType"]?.Type is JTokenType.Integer)
|
||||
{
|
||||
var v = data["RootAppType"].Value<int>();
|
||||
data["RootAppType"] = new JValue(MapToString(v));
|
||||
}
|
||||
var arr = data["DomainToAppMapping"] as JArray;
|
||||
if (arr != null)
|
||||
{
|
||||
foreach (var map in arr)
|
||||
{
|
||||
if (map["AppType"]?.Type is JTokenType.Integer)
|
||||
{
|
||||
var v = map["AppType"].Value<int>();
|
||||
map["AppType"] = new JValue(MapToString(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
setting.Value = data.ToString();
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
||||
private async Task FixSeqAfterSqliteMigration()
|
||||
{
|
||||
await using var ctx = _DBContextFactory.CreateContext();
|
||||
|
|
|
@ -36,5 +36,6 @@ namespace BTCPayServer.Services
|
|||
public bool MigrateWalletColors { get; set; }
|
||||
public bool FileSystemStorageAsDefault { get; set; }
|
||||
public bool FixSeqAfterSqliteMigration { get; set; }
|
||||
public bool FixMappedDomainAppType { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue