@@ -15,6 +15,7 @@ import {
1515import { getRepository } from '@server/datasource' ;
1616import Media from '@server/entity/Media' ;
1717import { MediaRequest } from '@server/entity/MediaRequest' ;
18+ import Season from '@server/entity/Season' ;
1819import SeasonRequest from '@server/entity/SeasonRequest' ;
1920import notificationManager , { Notification } from '@server/lib/notifications' ;
2021import { getSettings } from '@server/lib/settings' ;
@@ -815,19 +816,6 @@ export class MediaRequestSubscriber implements EntitySubscriberInterface<MediaRe
815816 await mediaRepository . save ( media ) ;
816817 }
817818
818- logger . debug ( 'updateParentStatus: checking TV declined conditions' , {
819- label : 'Media Request' ,
820- requestId : entity . id ,
821- mediaId : media . id ,
822- mediaType : media . mediaType ,
823- entityStatus : entity . status ,
824- mediaStatus : media [ statusKey ] ,
825- statusKey,
826- isMediaTypeTv : media . mediaType === MediaType . TV ,
827- isDeclined : entity . status === MediaRequestStatus . DECLINED ,
828- isPending : media [ statusKey ] === MediaStatus . PENDING ,
829- } ) ;
830-
831819 /**
832820 * If the media type is TV, and we are declining a request,
833821 * we must check if its the only pending request and that
@@ -849,39 +837,43 @@ export class MediaRequestSubscriber implements EntitySubscriberInterface<MediaRe
849837 } ,
850838 } ) ;
851839
852- logger . debug ( 'updateParentStatus: TV declined pending count result' , {
853- label : 'Media Request' ,
854- requestId : entity . id ,
855- mediaId : media . id ,
856- pendingCount,
857- entityIs4k : entity . is4k ,
858- } ) ;
859-
860840 if ( pendingCount === 0 ) {
861841 // Re-fetch media without requests to avoid cascade issues
862842 const freshMedia = await mediaRepository . findOne ( {
863843 where : { id : media . id } ,
864844 } ) ;
865- logger . debug ( 'updateParentStatus: TV declined resetting to UNKNOWN' , {
866- label : 'Media Request' ,
867- requestId : entity . id ,
868- mediaId : media . id ,
869- freshMediaFound : ! ! freshMedia ,
870- freshMediaStatus : freshMedia ?. [ statusKey ] ,
871- } ) ;
872845 if ( freshMedia ) {
873- logger . debug ( 'updateParentStatus: setting media status to UNKNOWN' , {
874- label : 'Media Request' ,
875- requestId : entity . id ,
876- mediaId : media . id ,
877- statusKey,
878- } ) ;
879846 freshMedia [ statusKey ] = MediaStatus . UNKNOWN ;
880847 await mediaRepository . save ( freshMedia ) ;
881848 }
882849 }
883850 }
884851
852+ // Reset season statuses when a TV request is declined
853+ if (
854+ media . mediaType === MediaType . TV &&
855+ entity . status === MediaRequestStatus . DECLINED
856+ ) {
857+ const seasonRepository = getRepository ( Season ) ;
858+ const actualSeasons = await seasonRepository . find ( {
859+ where : { media : { id : media . id } } ,
860+ } ) ;
861+
862+ for ( const seasonRequest of entity . seasons ) {
863+ seasonRequest . status = MediaRequestStatus . DECLINED ;
864+ await seasonRequestRepository . save ( seasonRequest ) ;
865+
866+ const season = actualSeasons . find (
867+ ( s ) => s . seasonNumber === seasonRequest . seasonNumber
868+ ) ;
869+
870+ if ( season ) {
871+ season [ statusKey ] = MediaStatus . UNKNOWN ;
872+ await seasonRepository . save ( season ) ;
873+ }
874+ }
875+ }
876+
885877 // Approve child seasons if parent is approved
886878 if (
887879 media . mediaType === MediaType . TV &&
0 commit comments