Delete maillogs if a campaign is deleted. Fixes #1318

pull/1323/head
Jordan Wright 2018-12-15 21:47:40 -06:00
parent a73ac4ab7c
commit c14be36e05
2 changed files with 19 additions and 0 deletions

View File

@ -568,6 +568,11 @@ func DeleteCampaign(id int64) error {
log.Error(err)
return err
}
err = db.Where("campaign_id=?", id).Delete(&MailLog{}).Error
if err != nil {
log.Error(err)
return err
}
// Delete the campaign
err = db.Delete(&Campaign{Id: id}).Error
if err != nil {

View File

@ -105,3 +105,17 @@ func (s *ModelsSuite) TestLaunchCampaignMaillogStatus(c *check.C) {
c.Assert(m.Processing, check.Equals, false)
}
}
func (s *ModelsSuite) TestDeleteCampaignAlsoDeletesMailLogs(c *check.C) {
campaign := s.createCampaign(c)
ms, err := GetMailLogsByCampaign(campaign.Id)
c.Assert(err, check.Equals, nil)
c.Assert(len(ms), check.Equals, len(campaign.Results))
err = DeleteCampaign(campaign.Id)
c.Assert(err, check.Equals, nil)
ms, err = GetMailLogsByCampaign(campaign.Id)
c.Assert(err, check.Equals, nil)
c.Assert(len(ms), check.Equals, 0)
}