@@ -163,6 +163,77 @@ func (r *mutationResolver) StudioUpdate(ctx context.Context, input models.Studio
163163 return r .getStudio (ctx , studioID )
164164}
165165
166+ func (r * mutationResolver ) BulkStudioUpdate (ctx context.Context , input BulkStudioUpdateInput ) ([]* models.Studio , error ) {
167+ ids , err := stringslice .StringSliceToIntSlice (input .Ids )
168+ if err != nil {
169+ return nil , fmt .Errorf ("converting ids: %w" , err )
170+ }
171+
172+ translator := changesetTranslator {
173+ inputMap : getUpdateInputMap (ctx ),
174+ }
175+
176+ // Populate performer from the input
177+ partial := models .NewStudioPartial ()
178+
179+ partial .ParentID , err = translator .optionalIntFromString (input .ParentID , "parent_id" )
180+ if err != nil {
181+ return nil , fmt .Errorf ("converting parent id: %w" , err )
182+ }
183+
184+ partial .URL = translator .optionalString (input .URL , "url" )
185+ partial .Favorite = translator .optionalBool (input .Favorite , "favorite" )
186+ partial .Rating = translator .optionalInt (input .Rating100 , "rating100" )
187+ partial .Details = translator .optionalString (input .Details , "details" )
188+ partial .IgnoreAutoTag = translator .optionalBool (input .IgnoreAutoTag , "ignore_auto_tag" )
189+
190+ partial .TagIDs , err = translator .updateIdsBulk (input .TagIds , "tag_ids" )
191+ if err != nil {
192+ return nil , fmt .Errorf ("converting tag ids: %w" , err )
193+ }
194+
195+ ret := []* models.Studio {}
196+
197+ // Start the transaction and save the performers
198+ if err := r .withTxn (ctx , func (ctx context.Context ) error {
199+ qb := r .repository .Studio
200+
201+ for _ , id := range ids {
202+ local := partial
203+ local .ID = id
204+ if err := studio .ValidateModify (ctx , local , qb ); err != nil {
205+ return err
206+ }
207+
208+ updated , err := qb .UpdatePartial (ctx , local )
209+ if err != nil {
210+ return err
211+ }
212+
213+ ret = append (ret , updated )
214+ }
215+
216+ return nil
217+ }); err != nil {
218+ return nil , err
219+ }
220+
221+ // execute post hooks outside of txn
222+ var newRet []* models.Studio
223+ for _ , studio := range ret {
224+ r .hookExecutor .ExecutePostHooks (ctx , studio .ID , hook .StudioUpdatePost , input , translator .getFields ())
225+
226+ studio , err = r .getStudio (ctx , studio .ID )
227+ if err != nil {
228+ return nil , err
229+ }
230+
231+ newRet = append (newRet , studio )
232+ }
233+
234+ return newRet , nil
235+ }
236+
166237func (r * mutationResolver ) StudioDestroy (ctx context.Context , input StudioDestroyInput ) (bool , error ) {
167238 id , err := strconv .Atoi (input .ID )
168239 if err != nil {
0 commit comments