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:
parent
e74a5022c9
commit
b619ff1264
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user