This commit is contained in:
Jamie.Rees 2017-06-13 14:05:23 +01:00
commit 515312427e
7 changed files with 43 additions and 55 deletions

View file

@ -3,6 +3,7 @@ using Moq;
using Ombi.Core.Claims; using Ombi.Core.Claims;
using Ombi.Core.Models.Requests; using Ombi.Core.Models.Requests;
using Ombi.Core.Rule.Rules; using Ombi.Core.Rule.Rules;
using Ombi.Core.Rule.Rules.Request;
using Xunit; using Xunit;
namespace Ombi.Core.Tests.Rule namespace Ombi.Core.Tests.Rule

View file

@ -184,6 +184,8 @@ namespace Ombi.Core.Engine
var results = allRequests.FirstOrDefault(x => x.Id == request.Id); var results = allRequests.FirstOrDefault(x => x.Id == request.Id);
results = Mapper.Map<TvRequestModel>(request); results = Mapper.Map<TvRequestModel>(request);
// TODO need to check if we need to approve any child requests since they may have updated
var model = TvRequestService.UpdateRequest(results); var model = TvRequestService.UpdateRequest(results);
return model; return model;
} }
@ -211,7 +213,7 @@ namespace Ombi.Core.Engine
existingRequest.ChildRequests.AddRange(newRequest.ChildRequests); existingRequest.ChildRequests.AddRange(newRequest.ChildRequests);
TvRequestService.UpdateRequest(existingRequest); TvRequestService.UpdateRequest(existingRequest);
if (ShouldAutoApprove(RequestType.TvShow)) if (newRequest.Approved) // The auto approve rule
{ {
// TODO Auto Approval Code // TODO Auto Approval Code
} }

View file

@ -1,11 +1,10 @@
using Ombi.Core.Claims; using System.Security.Principal;
using Ombi.Core.Claims;
using Ombi.Core.Models.Requests; using Ombi.Core.Models.Requests;
using Ombi.Core.Rules;
using Ombi.Store.Entities;
using System.Security.Principal;
using Ombi.Core.Rule.Interfaces; using Ombi.Core.Rule.Interfaces;
using Ombi.Store.Entities;
namespace Ombi.Core.Rule.Rules namespace Ombi.Core.Rule.Rules.Request
{ {
public class AutoApproveRule : BaseRequestRule, IRequestRules<BaseRequestModel> public class AutoApproveRule : BaseRequestRule, IRequestRules<BaseRequestModel>
{ {

View file

@ -77,45 +77,6 @@ namespace Ombi.Schedule.Jobs
Logger.LogWarning(LoggingEvents.CacherException, e, "Exception thrown when attempting to cache the Plex Content"); Logger.LogWarning(LoggingEvents.CacherException, e, "Exception thrown when attempting to cache the Plex Content");
} }
} }
//private List<PlexLibraries> CachedLibraries(PlexSettings plexSettings)
//{
// var results = new List<PlexLibraries>();
// results = GetLibraries(plexSettings);
// foreach (PlexLibraries t in results)
// {
// foreach (var t1 in t.MediaContainer.Directory)
// {
// var currentItem = t1;
// var metaData = PlexApi.GetMetadata(plexSettings.PlexAuthToken, plexSettings.FullUri,
// currentItem.ratingKey).Result;
// // Get the seasons for each show
// if (currentItem.type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase))
// {
// var seasons = PlexApi.GetSeasons(plexSettings.PlexAuthToken, plexSettings.FullUri,
// currentItem.ratingKey).Result;
// // We do not want "all episodes" this as a season
// var filtered = seasons.MediaContainer.Directory.Where(x => !x.title.Equals("All episodes", StringComparison.CurrentCultureIgnoreCase));
// t1.seasons.AddRange(filtered);
// }
// var providerId = PlexHelper.GetProviderIdFromPlexGuid(metaData.MediaContainer);
// t1.providerId = providerId;
// }
// foreach (Video t1 in t.Video)
// {
// var currentItem = t1;
// var metaData = PlexApi.GetMetadata(plexSettings.PlexAuthToken, plexSettings.FullUri,
// currentItem.RatingKey);
// var providerId = PlexHelper.GetProviderIdFromPlexGuid(metaData.Video.Guid);
// t1.ProviderId = providerId;
// }
// }
//}
private async Task StartTheCache(PlexSettings plexSettings) private async Task StartTheCache(PlexSettings plexSettings)
{ {
@ -154,19 +115,17 @@ namespace Ombi.Schedule.Jobs
var itemAdded = false; var itemAdded = false;
foreach (var season in seasonsContent) foreach (var season in seasonsContent)
{ {
var seasonExists = existingContent.Seasons.Where(x => x.SeasonKey == season.SeasonKey); var seasonExists = existingContent.Seasons.FirstOrDefault(x => x.SeasonKey == season.SeasonKey);
if (seasonExists != null) if (seasonExists != null)
{ {
// We already have this season // We already have this season
continue; continue;
} }
else
{
existingContent.Seasons.Add(season); existingContent.Seasons.Add(season);
itemAdded = true; itemAdded = true;
} }
}
if (itemAdded) await Repo.Update(existingContent); if (itemAdded) await Repo.Update(existingContent);
} }

View file

@ -44,7 +44,7 @@ namespace Ombi.Store.Entities
/// <summary> /// <summary>
/// Only used for TV Shows /// Only used for TV Shows
/// </summary> /// </summary>
public virtual ICollection<SeasonsContent> Seasons { get; set; } public virtual ICollection<PlexSeasonsContent> Seasons { get; set; }
/// <summary> /// <summary>
/// Plex's internal ID for this item /// Plex's internal ID for this item
@ -53,7 +53,8 @@ namespace Ombi.Store.Entities
public DateTime AddedAt { get; set; } public DateTime AddedAt { get; set; }
} }
public class SeasonsContent : Entity [Table("PlexSeasonsContent")]
public class PlexSeasonsContent : Entity
{ {
public int PlexContentId { get; set; } public int PlexContentId { get; set; }
public int SeasonNumber { get; set; } public int SeasonNumber { get; set; }

View file

@ -0,0 +1,15 @@
using System;
namespace Ombi.Store.Entities
{
public class RequestHistory : Entity
{
public int UserId { get; set; }
public RequestType Type { get; set; }
public DateTime RequestedDate { get; set; }
public int RequestId { get; set; }
public virtual RequestBlobs Request { get; set; }
public virtual User User { get; set; }
}
}

View file

@ -23,9 +23,10 @@ CREATE TABLE IF NOT EXISTS RadarrCache
TheMovieDbId INTEGER NOT NULL TheMovieDbId INTEGER NOT NULL
); );
CREATE TABLE IF NOT EXISTS SeasonsContent CREATE TABLE IF NOT EXISTS PlexSeasonsContent
( (
Id INTEGER PRIMARY KEY AUTOINCREMENT, Id INTEGER PRIMARY KEY AUTOINCREMENT,
PlexContentId integer not null,
SeasonNumber INTEGER NOT NULL, SeasonNumber INTEGER NOT NULL,
SeasonKey INTEGER NOT NULL, SeasonKey INTEGER NOT NULL,
ParentKey INTEGER NOT NULL ParentKey INTEGER NOT NULL
@ -53,3 +54,13 @@ CREATE TABLE IF NOT EXISTS Users
UserType INTEGER NOT NULL UserType INTEGER NOT NULL
); );
CREATE TABLE IF NOT EXISTS RequestHistory
{
Id INTEGER PRIMARY KEY AUTOINCREMENT,
Type INTEGER NOT NULL,
RequestedDate varchar(50) NOT NULL,
RequestId INTEGER NOT NULL
}