1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 09:32:55 +08:00

Reattach detached items on delete/undelete

This commit is contained in:
Dean Herbert 2022-01-08 14:03:04 +09:00
parent e74a5022c9
commit b619ff1264

View File

@ -156,19 +156,31 @@ namespace osu.Game.Stores
public bool Delete(TModel item)
{
if (item.DeletePending)
return false;
using (var realm = ContextFactory.CreateContext())
{
if (!item.IsManaged)
item = realm.Find<TModel>(item.ID);
item.Realm.Write(r => item.DeletePending = true);
return true;
if (item?.DeletePending != false)
return false;
realm.Write(r => item.DeletePending = true);
return true;
}
}
public void Undelete(TModel item)
{
if (!item.DeletePending)
return;
using (var realm = ContextFactory.CreateContext())
{
if (!item.IsManaged)
item = realm.Find<TModel>(item.ID);
item.Realm.Write(r => item.DeletePending = false);
if (item?.DeletePending != true)
return;
realm.Write(r => item.DeletePending = false);
}
}
// TODO: delete or abstract