Found where we potentially are setting a new poster path, looks like the entity was being modified and being set as Tracked by entity framework, so the next time we called SaveChangesAsync() it would save the new posterpath on the entity.

This commit is contained in:
Jamie 2017-10-26 08:33:06 +01:00
parent 51c2e13e35
commit 20f3239b94
8 changed files with 51 additions and 15 deletions

View file

@ -144,7 +144,11 @@ namespace Ombi.Core.Engine
public async Task<IEnumerable<MovieRequests>> SearchMovieRequest(string search)
{
var allRequests = await MovieRepository.GetWithUser().ToListAsync();
var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase));
var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToList();
results.ForEach(x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
});
return results;
}
@ -175,11 +179,6 @@ namespace Ombi.Core.Engine
};
}
/// <summary>
/// This is the method that is triggered by pressing Approve on the requests page
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<RequestEngineResult> ApproveMovie(MovieRequests request)
{
if (request == null)
@ -242,7 +241,7 @@ namespace Ombi.Core.Engine
results.IssueId = request.IssueId;
results.Issues = request.Issues;
results.Overview = request.Overview;
results.PosterPath = request.PosterPath;
results.PosterPath = PosterPathHelper.FixPosterPath(request.PosterPath);
results.QualityOverride = request.QualityOverride;
results.RootPathOverride = request.RootPathOverride;

View file

@ -95,7 +95,7 @@ namespace Ombi.Notifications.Agents
{
user = MovieRequest.RequestedUser.UserAlias;
title = MovieRequest.Title;
img = MovieRequest.PosterPath;
img = $"https://image.tmdb.org/t/p/w300/{MovieRequest.PosterPath}";
}
else
{

View file

@ -1,6 +1,8 @@
using System;
using System.Threading.Tasks;
using EnsureThat;
using MailKit.Net.Smtp;
using Microsoft.Extensions.Logging;
using MimeKit;
using Ombi.Core.Settings;
using Ombi.Notifications.Models;
@ -12,11 +14,13 @@ namespace Ombi.Notifications
{
public class GenericEmailProvider : IEmailProvider
{
public GenericEmailProvider(ISettingsService<CustomizationSettings> s)
public GenericEmailProvider(ISettingsService<CustomizationSettings> s, ILogger<GenericEmailProvider> log)
{
CustomizationSettings = s;
_log = log;
}
private ISettingsService<CustomizationSettings> CustomizationSettings { get; }
private readonly ILogger<GenericEmailProvider> _log;
/// <summary>
/// This will load up the Email template and generate the HTML
@ -95,6 +99,11 @@ namespace Ombi.Notifications
{
try
{
EnsureArg.IsNotNullOrEmpty(settings.SenderAddress);
EnsureArg.IsNotNullOrEmpty(model.To);
EnsureArg.IsNotNullOrEmpty(model.Message);
EnsureArg.IsNotNullOrEmpty(settings.Host);
var body = new BodyBuilder
{
HtmlBody = model.Message,
@ -141,8 +150,8 @@ namespace Ombi.Notifications
}
catch (Exception e)
{
//Log.Error(e);
throw new InvalidOperationException(e.Message);
_log.LogError(e, "Exception when attempting to send email");
throw;
}
}
}

View file

@ -105,7 +105,6 @@ namespace Ombi.Notifications.Interfaces
if (type == RequestType.Movie)
{
MovieRequest = await MovieRepository.GetWithUser().FirstOrDefaultAsync(x => x.Id == requestId);
MovieRequest.PosterPath = $"https://image.tmdb.org/t/p/w300/{MovieRequest.PosterPath}";
}
else
{

View file

@ -21,7 +21,8 @@ namespace Ombi.Notifications
Type = req.RequestType.ToString();
Overview = req.Overview;
Year = req.ReleaseDate.Year.ToString();
PosterImage = req.PosterPath;
PosterImage = req.RequestType == RequestType.Movie ?
$"https://image.tmdb.org/t/p/w300/{req.PosterPath}" : req.PosterPath;
}
public void Setup(ChildRequests req, CustomizationSettings s)
@ -36,7 +37,8 @@ namespace Ombi.Notifications
Type = req.RequestType.ToString();
Overview = req.ParentRequest.Overview;
Year = req.ParentRequest.ReleaseDate.Year.ToString();
PosterImage = req.ParentRequest.PosterPath;
PosterImage = req.RequestType == RequestType.Movie ?
$"https://image.tmdb.org/t/p/w300/{req.ParentRequest.PosterPath}" : req.ParentRequest.PosterPath;
// DO Episode and Season Lists
}

View file

@ -9,6 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Ensure.That" Version="7.0.0-pre32" />
<PackageReference Include="MailKit" Version="1.18.1.1" />
</ItemGroup>

View file

@ -120,7 +120,7 @@ namespace Ombi.Schedule.Jobs.Plex
private async Task ProcessEpsiodes(PlexContainer episodes, IQueryable<PlexEpisode> currentEpisodes)
{
var ep = new HashSet<PlexEpisode>();
foreach (var episode in episodes.MediaContainer.Metadata)
foreach (var episode in episodes?.MediaContainer?.Metadata ?? new Metadata[]{})
{
// I don't think we need to get the metadata, we only need to get the metadata if we need the provider id (TheTvDbid). Why do we need it for episodes?
// We have the parent and grandparent rating keys to link up to the season and series

View file

@ -0,0 +1,26 @@
using System.Collections.Generic;
using NUnit.Framework;
using Ombi.Helpers;
namespace Ombi.Tests
{
[TestFixture]
public class PosterPathHelperTests
{
[TestCaseSource(nameof(TestData))]
public string PostPathTest(string posterPath)
{
return PosterPathHelper.FixPosterPath(posterPath);
}
private static IEnumerable<TestCaseData> TestData
{
get
{
yield return new TestCaseData("https://image.tmdb.org/t/p/w150/fJAvGOitU8y53ByeHnM4avtKFaG.jpg").Returns("fJAvGOitU8y53ByeHnM4avtKFaG.jpg").SetName("Full tmdb poster path returns last part");
yield return new TestCaseData("https://image.tmdb.org/t/p/w300/https://image.tmdb.org/t/p/w300//fJAvGOitU8y53ByeHnM4avtKFaG.jpg").Returns("fJAvGOitU8y53ByeHnM4avtKFaG.jpg").SetName("Double tmdb poster path returns last part");
}
}
}
}