diff --git a/pkg/models/playlist.go b/pkg/models/playlist.go index 1bfa5949fe2..ca607c00b21 100644 --- a/pkg/models/playlist.go +++ b/pkg/models/playlist.go @@ -12,12 +12,12 @@ var ( // Playlist model type Playlist struct { - Id int64 `json:"id"` - Title string `json:"title"` - Type string `json:"type"` - Timespan string `json:"timespan"` - Data []int `json:"data"` - OrgId int64 `json:"-"` + Id int64 `json:"id"` + Title string `json:"title"` + Type string `json:"type"` + Timespan string `json:"timespan"` + Data []int64 `json:"data"` + OrgId int64 `json:"-"` } type PlaylistDashboard struct { @@ -49,7 +49,7 @@ type UpdatePlaylistQuery struct { Title string Type string Timespan string - Data []int + Data []int64 Result *Playlist } @@ -58,7 +58,7 @@ type CreatePlaylistQuery struct { Title string Type string Timespan string - Data []int + Data []int64 OrgId int64 Result *Playlist diff --git a/pkg/services/sqlstore/dashboard.go b/pkg/services/sqlstore/dashboard.go index bbec541589c..547c24fc7df 100644 --- a/pkg/services/sqlstore/dashboard.go +++ b/pkg/services/sqlstore/dashboard.go @@ -220,6 +220,26 @@ func DeleteDashboard(cmd *m.DeleteDashboardCommand) error { } } + var playlists = make(m.Playlists, 0) + err = sess.Where("data LIKE ?", fmt.Sprintf("%%%v%%", dashboard.Id)).Find(&playlists) + if err != nil { + return err + } + + for _, playlist := range playlists { + filteredData := make([]int64, 0) + for _, plDashboardId := range playlist.Data { + if plDashboardId != dashboard.Id { + filteredData = append(filteredData, plDashboardId) + } + } + playlist.Data = filteredData + _, err = sess.Id(playlist.Id).Cols("data").Update(playlist) + if err != nil { + return err + } + } + return nil }) }