forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Fix schedule tasks bugs (go-gitea#28691)" (part 2)
This function is now being used elsewhere and cannot be reverted. Only the part that was modified in addition to being moved is deleted. (cherry picked from commit 72954836a492f552ccc03250ba560951eedc199d) (cherry picked from commit 86f4d1871e5605c1592cb83b178f8ebe69ccdfa8) (cherry picked from commit 8089076ee2434a5f8b0abc11c0c06b5425fb7c14)
- Loading branch information
1 parent
fe8622d
commit 540ec07
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repository | ||
|
||
import ( | ||
"context" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
repo_model "code.gitea.io/gitea/models/repo" | ||
"code.gitea.io/gitea/models/unit" | ||
) | ||
|
||
// UpdateRepositoryUnits updates a repository's units | ||
func UpdateRepositoryUnits(ctx context.Context, repo *repo_model.Repository, units []repo_model.RepoUnit, deleteUnitTypes []unit.Type) (err error) { | ||
ctx, committer, err := db.TxContext(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
defer committer.Close() | ||
|
||
// Delete existing settings of units before adding again | ||
for _, u := range units { | ||
deleteUnitTypes = append(deleteUnitTypes, u.Type) | ||
} | ||
|
||
if _, err = db.GetEngine(ctx).Where("repo_id = ?", repo.ID).In("type", deleteUnitTypes).Delete(new(repo_model.RepoUnit)); err != nil { | ||
return err | ||
} | ||
|
||
if len(units) > 0 { | ||
if err = db.Insert(ctx, units); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return committer.Commit() | ||
} |