Fix importing with no existing system
This commit is contained in:
parent
c6905f4ca1
commit
a41e20a0a3
@ -85,7 +85,7 @@ namespace PluralKit.Bot.Commands
|
||||
|
||||
// If passed system is null, it'll create a new one
|
||||
// (and that's okay!)
|
||||
var result = await DataFiles.ImportSystem(data, Context.SenderSystem);
|
||||
var result = await DataFiles.ImportSystem(data, Context.SenderSystem, Context.User.Id);
|
||||
|
||||
if (Context.SenderSystem == null)
|
||||
{
|
||||
|
@ -64,8 +64,11 @@ namespace PluralKit.Bot
|
||||
Timestamp = Formats.TimestampExportFormat.Format(sw.Timestamp)
|
||||
};
|
||||
|
||||
public async Task<ImportResult> ImportSystem(DataFileSystem data, PKSystem system)
|
||||
public async Task<ImportResult> ImportSystem(DataFileSystem data, PKSystem system, ulong accountId)
|
||||
{
|
||||
// TODO: make atomic, somehow - we'd need to obtain one IDbConnection and reuse it
|
||||
// which probably means refactoring SystemStore.Save and friends etc
|
||||
|
||||
var result = new ImportResult {AddedNames = new List<string>(), ModifiedNames = new List<string>()};
|
||||
|
||||
// If we don't already have a system to save to, create one
|
||||
@ -78,6 +81,9 @@ namespace PluralKit.Bot
|
||||
if (data.AvatarUrl != null) system.AvatarUrl = data.AvatarUrl;
|
||||
if (data.TimeZone != null) system.UiTz = data.TimeZone ?? "UTC";
|
||||
await _systems.Save(system);
|
||||
|
||||
// Make sure to link the sender account, too
|
||||
await _systems.Link(system, accountId);
|
||||
|
||||
// Apply members
|
||||
// TODO: parallelize?
|
||||
|
@ -25,8 +25,10 @@ namespace PluralKit {
|
||||
}
|
||||
|
||||
public async Task Link(PKSystem system, ulong accountId) {
|
||||
// We have "on conflict do nothing" since linking an account when it's already linked to the same system is idempotent
|
||||
// This is used in import/export, although the pk;link command checks for this case beforehand
|
||||
using (var conn = _conn.Obtain())
|
||||
await conn.ExecuteAsync("insert into accounts (uid, system) values (@Id, @SystemId)", new { Id = accountId, SystemId = system.Id });
|
||||
await conn.ExecuteAsync("insert into accounts (uid, system) values (@Id, @SystemId) on conflict do nothing", new { Id = accountId, SystemId = system.Id });
|
||||
}
|
||||
|
||||
public async Task Unlink(PKSystem system, ulong accountId) {
|
||||
|
Loading…
Reference in New Issue
Block a user