mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 13:13:22 +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)
|
public bool Delete(TModel item)
|
||||||
{
|
{
|
||||||
if (item.DeletePending)
|
using (var realm = ContextFactory.CreateContext())
|
||||||
return false;
|
{
|
||||||
|
if (!item.IsManaged)
|
||||||
|
item = realm.Find<TModel>(item.ID);
|
||||||
|
|
||||||
item.Realm.Write(r => item.DeletePending = true);
|
if (item?.DeletePending != false)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
|
realm.Write(r => item.DeletePending = true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Undelete(TModel item)
|
public void Undelete(TModel item)
|
||||||
{
|
{
|
||||||
if (!item.DeletePending)
|
using (var realm = ContextFactory.CreateContext())
|
||||||
return;
|
{
|
||||||
|
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
|
// TODO: delete or abstract
|
||||||
|
Loading…
Reference in New Issue
Block a user