mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Scene play and o-counter history view and editing (#4532)
Co-authored-by: randemgame <61895715+randemgame@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/fsutil"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
@@ -14,13 +15,15 @@ import (
|
||||
"github.com/stashapp/stash/pkg/txn"
|
||||
)
|
||||
|
||||
func (s *Service) Merge(
|
||||
ctx context.Context,
|
||||
sourceIDs []int,
|
||||
destinationID int,
|
||||
scenePartial models.ScenePartial,
|
||||
fileDeleter *FileDeleter,
|
||||
) error {
|
||||
type MergeOptions struct {
|
||||
ScenePartial models.ScenePartial
|
||||
IncludePlayHistory bool
|
||||
IncludeOHistory bool
|
||||
}
|
||||
|
||||
func (s *Service) Merge(ctx context.Context, sourceIDs []int, destinationID int, fileDeleter *FileDeleter, options MergeOptions) error {
|
||||
scenePartial := options.ScenePartial
|
||||
|
||||
// ensure source ids are unique
|
||||
sourceIDs = sliceutil.AppendUniques(nil, sourceIDs)
|
||||
|
||||
@@ -74,6 +77,44 @@ func (s *Service) Merge(
|
||||
return fmt.Errorf("updating scene: %w", err)
|
||||
}
|
||||
|
||||
// merge play history
|
||||
if options.IncludePlayHistory {
|
||||
var allDates []time.Time
|
||||
for _, src := range sources {
|
||||
thisDates, err := s.Repository.GetViewDates(ctx, src.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting view dates for scene %d: %w", src.ID, err)
|
||||
}
|
||||
|
||||
allDates = append(allDates, thisDates...)
|
||||
}
|
||||
|
||||
if len(allDates) > 0 {
|
||||
if _, err := s.Repository.AddViews(ctx, destinationID, allDates); err != nil {
|
||||
return fmt.Errorf("adding view dates to scene %d: %w", destinationID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// merge o history
|
||||
if options.IncludeOHistory {
|
||||
var allDates []time.Time
|
||||
for _, src := range sources {
|
||||
thisDates, err := s.Repository.GetODates(ctx, src.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting o dates for scene %d: %w", src.ID, err)
|
||||
}
|
||||
|
||||
allDates = append(allDates, thisDates...)
|
||||
}
|
||||
|
||||
if len(allDates) > 0 {
|
||||
if _, err := s.Repository.AddO(ctx, destinationID, allDates); err != nil {
|
||||
return fmt.Errorf("adding o dates to scene %d: %w", destinationID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// delete old scenes
|
||||
for _, src := range sources {
|
||||
const deleteGenerated = true
|
||||
|
||||
Reference in New Issue
Block a user