From a456abe06e732be869770eaf3ed88798ff0b51fb Mon Sep 17 00:00:00 2001 From: akuma06 Date: Tue, 1 Aug 2017 00:05:30 +0200 Subject: [PATCH] Adds a calllback function on type to update anidbid when a tag is accepted --- models/tag/helpers.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/models/tag/helpers.go b/models/tag/helpers.go index 4c711138..e2d05dbb 100644 --- a/models/tag/helpers.go +++ b/models/tag/helpers.go @@ -3,12 +3,15 @@ package tags import ( "fmt" + "github.com/NyaaPantsu/nyaa/models/torrents" + "github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models/users" "github.com/NyaaPantsu/nyaa/utils/log" ) +// Filter check if a tag type has reached the maximal votes and removes the other tag of the same type func Filter(tag string, tagType string, torrentID uint) bool { if torrentID == 0 || tagType == "" || tag == "" { return false @@ -42,8 +45,22 @@ func Filter(tag string, tagType string, torrentID uint) bool { tagSum.UserID = 0 // System ID tagSum.Weight = config.Get().Torrents.Tags.MaxWeight // Overriden to the maximal value models.ORM.Save(&tagSum) // We only add back the tag accepted + callbackOnType(&tagSum) return true } } return false } + +func callbackOnType(tag *models.Tag) { + switch tag.Type { + case "anidbid", "vndbid": + if tag.Accepted && tag.TorrentID > 0 { + torrent, err := torrents.FindByID(tag.TorrentID) + if err == nil { + torrent.DbID = tag.Tag + torrent.Update(false) + } + } + } +}