stash/internal/manager/studio.go
DingDongSoLong4 1c13c9e1b1
SQLite model refactoring (#3791)
* Remove ID from PerformerPartial
* Separate studio model from sqlite model
* Separate movie model from sqlite model
* Separate tag model from sqlite model
* Separate saved filter model from sqlite model
* Separate scene marker model from sqlite model
* Separate gallery chapter model from sqlite model
* Move ErrNoRows checks into sqlite, improve empty result error messages
* Move SQLiteDate and SQLiteTimestamp to sqlite
* Use changesetTranslator everywhere, refactor for consistency
* Make PerformerStore.DestroyImage private
* Fix rating on movie create
2023-06-15 12:46:09 +10:00

38 lines
827 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, studioID int, studio models.StudioPartial, qb studio.Finder) error {
if studio.ParentID.Ptr() == nil {
return nil
}
// ensure there is no cyclic dependency
currentParentID := studio.ParentID.Ptr()
for currentParentID != nil {
if *currentParentID == studioID {
return errors.New("studio cannot be an ancestor of itself")
}
currentStudio, err := qb.Find(ctx, *currentParentID)
if err != nil {
return fmt.Errorf("error finding parent studio: %v", err)
}
if currentStudio == nil {
return fmt.Errorf("studio with id %d not found", *currentParentID)
}
currentParentID = currentStudio.ParentID
}
return nil
}