Fix new records being added on completing a campaign (#2599)

There were new records with name '[Deleted]' being added when a campaign was
completed. This used to happen when the resource associated with a campaign
(template, page, profile) was deleted before marking the campaign as
completed. The save gorm call used to upsert these values and ended up adding
rogue records.
This commit is contained in:
Vivek Kekuda 2022-10-13 20:46:37 +05:30 committed by GitHub
parent 095a9ba20c
commit cec2da5128
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -661,7 +661,8 @@ func CompleteCampaign(id int64, uid int64) error {
// Mark the campaign as complete
c.CompletedDate = time.Now().UTC()
c.Status = CampaignComplete
err = db.Where("id=? and user_id=?", id, uid).Save(&c).Error
err = db.Model(&Campaign{}).Where("id=? and user_id=?", id, uid).
Select([]string{"completed_date", "status"}).UpdateColumns(&c).Error
if err != nil {
log.Error(err)
}