mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Parent studios (#595)
* Refactor getMultiCriterionClause Co-authored-by: Anon247 <61889302+Anon247@users.noreply.github.com>
This commit is contained in:
36
pkg/manager/studio.go
Normal file
36
pkg/manager/studio.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
func ValidateModifyStudio(studio models.StudioPartial, tx *sqlx.Tx) error {
|
||||
if studio.ParentID == nil || !studio.ParentID.Valid {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ensure there is no cyclic dependency
|
||||
thisID := studio.ID
|
||||
qb := models.NewStudioQueryBuilder()
|
||||
|
||||
currentParentID := *studio.ParentID
|
||||
|
||||
for currentParentID.Valid {
|
||||
if currentParentID.Int64 == int64(thisID) {
|
||||
return errors.New("studio cannot be an ancestor of itself")
|
||||
}
|
||||
|
||||
currentStudio, err := qb.Find(int(currentParentID.Int64), tx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error finding parent studio: %s", err.Error())
|
||||
}
|
||||
|
||||
currentParentID = currentStudio.ParentID
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user