mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
* 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
36 lines
766 B
Go
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
|
|
}
|