Add the recovery feature.

This commit is contained in:
lishuang
2020-07-12 21:03:01 +08:00
parent a92e172d26
commit 8a0c66ceff
3 changed files with 111 additions and 1 deletions

View File

@ -450,7 +450,7 @@ func (this *MatterDao) Delete(matter *Matter) {
}
}
//soft delete a file from db and disk.
//soft delete a file
func (this *MatterDao) SoftDelete(matter *Matter) {
// recursive if dir
@ -481,6 +481,30 @@ func (this *MatterDao) SoftDelete(matter *Matter) {
}
}
//recovery a file
func (this *MatterDao) Recovery(matter *Matter) {
// recursive if dir
if matter.Dir {
matters := this.FindByPuuidAndUserUuid(matter.Uuid, matter.UserUuid, nil)
for _, f := range matters {
this.SoftDelete(f)
}
//recovery from db.
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", matter.Uuid).Update(map[string]interface{}{"deleted": false, "delete_time": time.Now()})
this.PanicError(db.Error)
} else {
//recovery from db.
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", matter.Uuid).Update(map[string]interface{}{"deleted": false, "delete_time": time.Now()})
this.PanicError(db.Error)
}
}
func (this *MatterDao) DeleteByUserUuid(userUuid string) {
db := core.CONTEXT.GetDB().Where("user_uuid = ?", userUuid).Delete(Matter{})