-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Make Migrations Cancelable #12917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Migrations Cancelable #12917
Changes from 8 commits
b5c9eaf
fe9557a
8da1497
714351a
fd09715
e174d8c
ab941d7
6d91ba8
cab5d46
a009150
1d206d8
e757442
d9b6d09
934ed01
6a89ee6
f7e9022
cfed3be
b5c2461
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,17 @@ | |
package repo | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
|
||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/auth" | ||
"code.gitea.io/gitea/modules/base" | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/migrations" | ||
"code.gitea.io/gitea/modules/process" | ||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/structs" | ||
"code.gitea.io/gitea/modules/task" | ||
|
@@ -188,3 +192,29 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) { | |
|
||
handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, &form) | ||
} | ||
|
||
// CancelMigration cancels a running migration | ||
func CancelMigration(ctx *context.Context) { | ||
if !ctx.Repo.IsOwner() { | ||
6543 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ctx.Error(http.StatusNotFound) | ||
return | ||
} | ||
|
||
if ctx.Repo.Repository.Status != models.RepositoryBeingMigrated { | ||
ctx.Error(http.StatusConflict, "repo already migrated") | ||
return | ||
} | ||
|
||
6543 marked this conversation as resolved.
Show resolved
Hide resolved
6543 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for _, ps := range process.GetManager().Processes() { | ||
if ps.Description == fmt.Sprintf("MigrateTask: %s", ctx.Repo.Repository.FullName()) { | ||
6543 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
log.Trace("Migration Canceled: %s", ctx.Repo.Repository.FullName()) | ||
process.GetManager().Cancel(ps.PID) | ||
ctx.Flash.Success(ctx.Tr("repo.migrate.cancelled")) | ||
ctx.Redirect(ctx.Repo.Owner.DashboardLink()) | ||
return | ||
} | ||
} | ||
6543 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ctx.Flash.Error(ctx.Tr("repo.migrate.task_not_found", ctx.Repo.Repository.FullName())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user will see a migrating task, but when click cancel, gitea will say it's not exist. This is still a problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it even sensible to flash a message if the next action is to redirect back to the homepage? |
||
ctx.Redirect(ctx.Repo.Owner.DashboardLink()) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.