import ( | import ( | ||||
"context" | "context" | ||||
"database/sql" | |||||
"fmt" | "fmt" | ||||
"code.gitea.io/gitea/models/db" | "code.gitea.io/gitea/models/db" | ||||
return nil | return nil | ||||
} | } | ||||
var maxSorting int64 | |||||
has, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_issue"). | |||||
var maxSorting sql.NullInt64 | |||||
if _, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_issue"). | |||||
Where("project_id=?", newProjectID). | Where("project_id=?", newProjectID). | ||||
And("project_board_id=?", newColumnID). | And("project_board_id=?", newColumnID). | ||||
Get(&maxSorting) | |||||
if err != nil { | |||||
Get(&maxSorting); err != nil { | |||||
return err | return err | ||||
} | } | ||||
if has { | |||||
maxSorting++ | |||||
if maxSorting.Valid { | |||||
maxSorting.Int64++ | |||||
} | } | ||||
return db.Insert(ctx, &project_model.ProjectIssue{ | return db.Insert(ctx, &project_model.ProjectIssue{ | ||||
IssueID: issue.ID, | IssueID: issue.ID, | ||||
ProjectID: newProjectID, | ProjectID: newProjectID, | ||||
ProjectBoardID: newColumnID, | ProjectBoardID: newColumnID, | ||||
Sorting: maxSorting, | |||||
Sorting: maxSorting.Int64, | |||||
}) | }) | ||||
}) | }) | ||||
} | } |
import ( | import ( | ||||
"context" | "context" | ||||
"database/sql" | |||||
"errors" | "errors" | ||||
"fmt" | "fmt" | ||||
"regexp" | "regexp" | ||||
} | } | ||||
if totalColumns > 0 { | if totalColumns > 0 { | ||||
var maxSorting int8 | |||||
has, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_board"). | |||||
Where("project_id=?", board.ProjectID).Get(&maxSorting) | |||||
if err != nil { | |||||
var maxSorting sql.NullByte | |||||
if _, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_board"). | |||||
Where("project_id=?", board.ProjectID).Get(&maxSorting); err != nil { | |||||
return err | return err | ||||
} | } | ||||
if has { | |||||
board.Sorting = maxSorting + 1 | |||||
if maxSorting.Valid { | |||||
board.Sorting = int8(maxSorting.Byte) + 1 | |||||
} | } | ||||
} | } | ||||
import ( | import ( | ||||
"context" | "context" | ||||
"database/sql" | |||||
"fmt" | "fmt" | ||||
"code.gitea.io/gitea/models/db" | "code.gitea.io/gitea/models/db" | ||||
return nil | return nil | ||||
} | } | ||||
var maxSorting int8 | |||||
has, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_issue"). | |||||
var maxSorting sql.NullByte | |||||
if _, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_issue"). | |||||
Where("project_id=?", newColumn.ProjectID). | Where("project_id=?", newColumn.ProjectID). | ||||
And("project_board_id=?", newColumn.ID). | And("project_board_id=?", newColumn.ID). | ||||
Get(&maxSorting) | |||||
if err != nil { | |||||
Get(&maxSorting); err != nil { | |||||
return err | return err | ||||
} | } | ||||
if has { | |||||
maxSorting++ | |||||
if maxSorting.Valid { | |||||
maxSorting.Byte++ | |||||
} | } | ||||
issues, err := b.GetIssues(ctx) | issues, err := b.GetIssues(ctx) | ||||
return db.WithTx(ctx, func(ctx context.Context) error { | return db.WithTx(ctx, func(ctx context.Context) error { | ||||
for i, issue := range issues { | for i, issue := range issues { | ||||
issue.ProjectBoardID = newColumn.ID | issue.ProjectBoardID = newColumn.ID | ||||
issue.Sorting = int64(maxSorting) + int64(i) | |||||
issue.Sorting = int64(maxSorting.Byte) + int64(i) | |||||
if _, err := db.GetEngine(ctx).ID(issue.ID).Cols("project_board_id", "sorting").Update(issue); err != nil { | if _, err := db.GetEngine(ctx).ID(issue.ID).Cols("project_board_id", "sorting").Update(issue); err != nil { | ||||
return err | return err | ||||
} | } |