Move attachment into models/repo/ (#17650)

* Move attachment into models/repo/

* Fix test

* Fix bug
This commit is contained in:
Lunny Xiao 2021-11-19 21:39:57 +08:00 committed by GitHub
parent 7a03473159
commit fc3d082609
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 477 additions and 414 deletions

View file

@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
@ -206,7 +207,7 @@ func UpdateRelease(doer *models.User, gitRepo *git.Repository, rel *models.Relea
var deletedUUIDsMap = make(map[string]bool)
if len(delAttachmentUUIDs) > 0 {
// Check attachments
attachments, err := models.GetAttachmentsByUUIDs(ctx, delAttachmentUUIDs)
attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, delAttachmentUUIDs)
if err != nil {
return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %v", delAttachmentUUIDs, err)
}
@ -217,7 +218,7 @@ func UpdateRelease(doer *models.User, gitRepo *git.Repository, rel *models.Relea
deletedUUIDsMap[attach.UUID] = true
}
if _, err := models.DeleteAttachments(ctx, attachments, false); err != nil {
if _, err := repo_model.DeleteAttachments(ctx, attachments, false); err != nil {
return fmt.Errorf("DeleteAttachments [uuids: %v]: %v", delAttachmentUUIDs, err)
}
}
@ -228,7 +229,7 @@ func UpdateRelease(doer *models.User, gitRepo *git.Repository, rel *models.Relea
updateAttachmentsList = append(updateAttachmentsList, k)
}
// Check attachments
attachments, err := models.GetAttachmentsByUUIDs(ctx, updateAttachmentsList)
attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, updateAttachmentsList)
if err != nil {
return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %v", updateAttachmentsList, err)
}
@ -240,7 +241,7 @@ func UpdateRelease(doer *models.User, gitRepo *git.Repository, rel *models.Relea
for uuid, newName := range editAttachments {
if !deletedUUIDsMap[uuid] {
if err = models.UpdateAttachmentByUUID(ctx, &models.Attachment{
if err = repo_model.UpdateAttachmentByUUID(ctx, &repo_model.Attachment{
UUID: uuid,
Name: newName,
}, "name"); err != nil {
@ -255,7 +256,7 @@ func UpdateRelease(doer *models.User, gitRepo *git.Repository, rel *models.Relea
}
for _, uuid := range delAttachmentUUIDs {
if err := storage.Attachments.Delete(models.AttachmentRelativePath(uuid)); err != nil {
if err := storage.Attachments.Delete(repo_model.AttachmentRelativePath(uuid)); err != nil {
// Even delete files failed, but the attachments has been removed from database, so we
// should not return error but only record the error on logs.
// users have to delete this attachments manually or we should have a
@ -321,7 +322,7 @@ func DeleteReleaseByID(id int64, doer *models.User, delTag bool) error {
return fmt.Errorf("LoadAttributes: %v", err)
}
if err := models.DeleteAttachmentsByRelease(rel.ID); err != nil {
if err := repo_model.DeleteAttachmentsByRelease(rel.ID); err != nil {
return fmt.Errorf("DeleteAttachments: %v", err)
}