d5b98772ed
* Add providers to folder and dashboard services * Refactor folder and dashboard services * Move store implementation to its own file due wire cannot allow us to cast to SQLStore * Add store in some places and more missing dependencies * Bad merge fix * Remove old functions from tests and few fixes * Fix provisioning * Remove store from http server and some test fixes * Test fixes * Fix dashboard and folder tests * Fix library tests * Fix provisioning tests * Fix plugins manager tests * Fix alert and org users tests * Refactor service package and more test fixes * Fix dashboard_test tets * Fix api tests * Some lint fixes * Fix lint * More lint :/ * Move dashboard integration tests to dashboards service and fix dependencies * Lint + tests * More integration tests fixes * Lint * Lint again * Fix tests again and again anda again * Update searchstore_test * Fix goimports * More go imports * More imports fixes * Fix lint * Move UnprovisionDashboard function into dashboard service and remove bus * Use search service instead of bus * Fix test * Fix go imports * Use nil in tests
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package sqlstore
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
)
|
|
|
|
func (ss *SQLStore) addDashboardProvisioningQueryAndCommandHandlers() {
|
|
bus.AddHandler("sql", ss.DeleteOrphanedProvisionedDashboards)
|
|
}
|
|
|
|
type DashboardExtras struct {
|
|
Id int64
|
|
DashboardId int64
|
|
Key string
|
|
Value string
|
|
}
|
|
|
|
func (ss *SQLStore) DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *models.DeleteOrphanedProvisionedDashboardsCommand) error {
|
|
var result []*models.DashboardProvisioning
|
|
|
|
convertedReaderNames := make([]interface{}, len(cmd.ReaderNames))
|
|
for index, readerName := range cmd.ReaderNames {
|
|
convertedReaderNames[index] = readerName
|
|
}
|
|
|
|
err := x.NotIn("name", convertedReaderNames...).Find(&result)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, deleteDashCommand := range result {
|
|
err := ss.DeleteDashboard(ctx, &models.DeleteDashboardCommand{Id: deleteDashCommand.DashboardId})
|
|
if err != nil && !errors.Is(err, models.ErrDashboardNotFound) {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|