Files
Ben Schumacher c7461751f2 Use request.CTX instead of *request.Context (#24877)
* Use request.CTX instead of *request.Context

* Fix tests
2023-10-30 16:33:37 +01:00

56 строки
1.5 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package migrations
import (
"net/http"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
)
const (
MigrationStateUnscheduled = "unscheduled"
MigrationStateInProgress = "in_progress"
MigrationStateCompleted = "completed"
JobDataKeyMigration = "migration_key"
JobDataKeyMigrationLastDone = "last_done"
)
func MakeMigrationsList() []string {
return []string{
model.MigrationKeyAdvancedPermissionsPhase2,
}
}
func GetMigrationState(c request.CTX, migration string, store store.Store) (string, *model.Job, *model.AppError) {
if _, err := store.System().GetByName(migration); err == nil {
return MigrationStateCompleted, nil, nil
}
jobs, err := store.Job().GetAllByType(c, model.JobTypeMigrations)
if err != nil {
return "", nil, model.NewAppError("GetMigrationState", "app.job.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
for _, job := range jobs {
if key, ok := job.Data[JobDataKeyMigration]; ok {
if key != migration {
continue
}
switch job.Status {
case model.JobStatusInProgress, model.JobStatusPending:
return MigrationStateInProgress, job, nil
default:
return MigrationStateUnscheduled, job, nil
}
}
}
return MigrationStateUnscheduled, nil, nil
}