stash/internal/manager/studio.go
WithoutPants 964b559309 Restructure data layer (#2532)
* Add new txn manager interface
* Add txn management to sqlite
* Rename get to getByID
* Add contexts to repository methods
* Update query builders
* Add context to reader writer interfaces
* Use repository in resolver
* Tighten interfaces
* Tighten interfaces in dlna
* Tighten interfaces in match package
* Tighten interfaces in scraper package
* Tighten interfaces in scan code
* Tighten interfaces on autotag package
* Remove ReaderWriter usage
* Merge database package into sqlite
2022-09-06 07:03:40 +00:00

36 lines
766 B
Go

package manager
import (
"context"
"errors"
"fmt"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/studio"
)
func ValidateModifyStudio(ctx context.Context, studio models.StudioPartial, qb studio.Finder) error {
if studio.ParentID == nil || !studio.ParentID.Valid {
return nil
}
// ensure there is no cyclic dependency
thisID := studio.ID
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(ctx, int(currentParentID.Int64))
if err != nil {
return fmt.Errorf("error finding parent studio: %v", err)
}
currentParentID = currentStudio.ParentID
}
return nil
}