DeleteOldEbook 删除旧电子书 1. 相同ext,状态为 Success 之外的记录以及电子书文件
(bookId int, ext string, ignoreEbookId int)
| 436 | // DeleteOldEbook 删除旧电子书 |
| 437 | // 1. 相同ext,状态为 Success 之外的记录以及电子书文件 |
| 438 | func (m *Ebook) DeleteOldEbook(bookId int, ext string, ignoreEbookId int) { |
| 439 | var ( |
| 440 | ebooks []Ebook |
| 441 | o = orm.NewOrm() |
| 442 | ) |
| 443 | |
| 444 | query := o.QueryTable(m).Filter("book_id", bookId).Filter("ext", ext) |
| 445 | query.All(&ebooks) |
| 446 | if len(ebooks) == 0 { |
| 447 | return |
| 448 | } |
| 449 | |
| 450 | for _, ebook := range ebooks { |
| 451 | if ebook.Id == ignoreEbookId { |
| 452 | continue |
| 453 | } |
| 454 | utils.DeleteFile(ebook.Path) |
| 455 | o.QueryTable(m).Filter("id", ebook.Id).Delete() |
| 456 | } |
| 457 | } |
no test coverage detected