Fixed: Saving IndexerSettings into DB which confuses the datamapper.

Fixes #2945
pull/2948/head
Leonardo Galli 7 years ago
parent c4ca2f12bb
commit b553d8aef6

@ -33,9 +33,18 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.Search
IndexerId = 1, IndexerId = 1,
Title = "Series.Title.S01.720p.BluRay.X264-RlsGrp", Title = "Series.Title.S01.720p.BluRay.X264-RlsGrp",
Seeders = 0, Seeders = 0,
IndexerSettings = new TorrentRssIndexerSettings {MinimumSeeders = 5} //IndexerSettings = new TorrentRssIndexerSettings {MinimumSeeders = 5}
} }
}; };
_indexerDefinition = new IndexerDefinition
{
Settings = new TorrentRssIndexerSettings { MinimumSeeders = 5 }
};
Mocker.GetMock<IIndexerFactory>()
.Setup(v => v.Get(1))
.Returns(_indexerDefinition);
} }
private void GivenReleaseSeeders(int? seeders) private void GivenReleaseSeeders(int? seeders)
@ -56,7 +65,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.Search
} }
// These tests are not needed anymore, since indexer settings are saved on the release itself! // These tests are not needed anymore, since indexer settings are saved on the release itself!
/*
[Test] [Test]
public void should_return_true_if_indexer_not_specified() public void should_return_true_if_indexer_not_specified()
{ {
@ -73,7 +82,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.Search
.Callback<int>(i => { throw new ModelNotFoundException(typeof(IndexerDefinition), i); }); .Callback<int>(i => { throw new ModelNotFoundException(typeof(IndexerDefinition), i); });
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
}*/ }
[Test] [Test]
public void should_return_true_if_seeds_unknown() public void should_return_true_if_seeds_unknown()

@ -3,7 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Rarbg; using NzbDrone.Core.Indexers.Rarbg;
using NzbDrone.Core.Indexers.TorrentRss;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Augmenters; using NzbDrone.Core.Parser.Augmenters;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
@ -13,15 +15,31 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests.AugmentersTests
[TestFixture] [TestFixture]
public class AugmentWithReleaseInfoFixture : AugmentMovieInfoFixture<AugmentWithReleaseInfo> public class AugmentWithReleaseInfoFixture : AugmentMovieInfoFixture<AugmentWithReleaseInfo>
{ {
private IndexerDefinition _indexerDefinition;
[SetUp]
public void Setup()
{
}
private ReleaseInfo ReleaseInfoWithLanguages(params Language[] languages) private ReleaseInfo ReleaseInfoWithLanguages(params Language[] languages)
{ {
return new ReleaseInfo _indexerDefinition = new IndexerDefinition
{ {
IndexerSettings = new RarbgSettings Settings = new RarbgSettings { MultiLanguages = languages.ToList().Select(l => (int) l) }
};
Mocker.GetMock<IIndexerFactory>()
.Setup(v => v.Get(1))
.Returns(_indexerDefinition);
return new ReleaseInfo
{ {
MultiLanguages = languages.ToList().Select(l => (int) l) IndexerId = 1
}
}; };
} }
[Test] [Test]

@ -1,3 +1,4 @@
using System;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
@ -25,24 +26,33 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
{ {
var torrentInfo = subject.Release; var torrentInfo = subject.Release;
if (torrentInfo == null || torrentInfo.IndexerSettings == null)
IIndexerSettings indexerSettings = null;
try {
indexerSettings = _indexerFactory.Get(subject.Release.IndexerId)?.Settings as IIndexerSettings;
}
catch (Exception e)
{ {
return Decision.Accept(); _logger.Debug("Indexer with id {0} does not exist, skipping required indexer flags specs.", subject.Release.IndexerId);
} }
var torrentIndexerSettings = torrentInfo.IndexerSettings as ITorrentIndexerSettings; if (torrentInfo == null || indexerSettings == null)
{
return Decision.Accept();
}
if (torrentIndexerSettings != null) if (indexerSettings is ITorrentIndexerSettings torrentIndexerSettings)
{ {
var requiredFlags = torrentIndexerSettings.RequiredFlags; var requiredFlags = torrentIndexerSettings.RequiredFlags;
var requiredFlag = (IndexerFlags) 0; var requiredFlag = (IndexerFlags) 0;
if (requiredFlags == null || requiredFlags.Count() == 0) var enumerable = requiredFlags.ToList();
if (requiredFlags == null || !enumerable.Any())
{ {
return Decision.Accept(); return Decision.Accept();
} }
foreach (var flag in requiredFlags) foreach (var flag in enumerable)
{ {
if (torrentInfo.IndexerFlags.HasFlag((IndexerFlags)flag)) if (torrentInfo.IndexerFlags.HasFlag((IndexerFlags)flag))
{ {

@ -1,3 +1,4 @@
using System;
using NLog; using NLog;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
@ -24,14 +25,22 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
{ {
var torrentInfo = subject.Release as TorrentInfo; var torrentInfo = subject.Release as TorrentInfo;
if (torrentInfo == null || torrentInfo.IndexerSettings == null) IIndexerSettings indexerSettings = null;
try {
indexerSettings = _indexerFactory.Get(subject.Release.IndexerId)?.Settings as IIndexerSettings;
}
catch (Exception e)
{ {
return Decision.Accept(); _logger.Debug("Indexer with id {0} does not exist, skipping minimum seeder checks.", subject.Release.IndexerId);
} }
var torrentIndexerSettings = torrentInfo.IndexerSettings as ITorrentIndexerSettings;
if (torrentIndexerSettings != null) if (torrentInfo == null || indexerSettings == null)
{
return Decision.Accept();
}
if (indexerSettings is ITorrentIndexerSettings torrentIndexerSettings)
{ {
var minimumSeeders = torrentIndexerSettings.MinimumSeeders; var minimumSeeders = torrentIndexerSettings.MinimumSeeders;

@ -69,7 +69,6 @@ namespace NzbDrone.Core.Indexers
{ {
c.IndexerId = Definition.Id; c.IndexerId = Definition.Id;
c.Indexer = Definition.Name; c.Indexer = Definition.Name;
c.IndexerSettings = Definition.Settings as IIndexerSettings;
c.DownloadProtocol = Protocol; c.DownloadProtocol = Protocol;
}); });

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.Composition; using NzbDrone.Common.Composition;
@ -84,5 +85,7 @@ namespace NzbDrone.Core.Indexers
yield return indexer; yield return indexer;
} }
} }
} }
} }

@ -40,8 +40,8 @@ namespace NzbDrone.Core.Parser.Augmenters
if (int.TryParse(history.Data.GetValueOrDefault("indexerId"), out var indexerId)) if (int.TryParse(history.Data.GetValueOrDefault("indexerId"), out var indexerId))
{ {
var indexerSettings = _indexerFactory.Get(indexerId).Settings as IIndexerSettings; //var indexerSettings = _indexerFactory.Get(indexerId).Settings as IIndexerSettings;
releaseInfo.IndexerSettings = indexerSettings; releaseInfo.IndexerId = indexerId;
} }
if (int.TryParse(history.Data.GetValueOrDefault("size"), out var size)) if (int.TryParse(history.Data.GetValueOrDefault("size"), out var size))

@ -1,6 +1,7 @@
using System; using System;
using System.Linq; using System.Linq;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Parser.Augmenters namespace NzbDrone.Core.Parser.Augmenters
@ -8,6 +9,13 @@ namespace NzbDrone.Core.Parser.Augmenters
public class AugmentWithReleaseInfo : IAugmentParsedMovieInfo public class AugmentWithReleaseInfo : IAugmentParsedMovieInfo
{ {
private readonly IIndexerFactory _indexerFactory;
public AugmentWithReleaseInfo(IIndexerFactory indexerFactory)
{
_indexerFactory = indexerFactory;
}
public Type HelperType public Type HelperType
{ {
get get
@ -18,17 +26,23 @@ namespace NzbDrone.Core.Parser.Augmenters
public ParsedMovieInfo AugmentMovieInfo(ParsedMovieInfo movieInfo, object helper) public ParsedMovieInfo AugmentMovieInfo(ParsedMovieInfo movieInfo, object helper)
{ {
var releaseInfo = helper as ReleaseInfo; if (helper is ReleaseInfo releaseInfo)
{
if (releaseInfo != null) IIndexerSettings indexerSettings = null;
try {
indexerSettings = _indexerFactory.Get(releaseInfo.IndexerId)?.Settings as IIndexerSettings;
}
catch (Exception e)
{ {
// First, let's augment the language! //_logger.Debug("Indexer with id {0} does not exist, skipping minimum seeder checks.", subject.Release.IndexerId);
} // First, let's augment the language!
var languageTitle = movieInfo.SimpleReleaseTitle; var languageTitle = movieInfo.SimpleReleaseTitle;
if (movieInfo.MovieTitle.IsNotNullOrWhiteSpace()) if (movieInfo.MovieTitle.IsNotNullOrWhiteSpace())
{ {
if (languageTitle.ToLower().Contains("multi") && releaseInfo?.IndexerSettings?.MultiLanguages?.Any() == true) if (languageTitle.ToLower().Contains("multi") && indexerSettings?.MultiLanguages?.Any() == true)
{ {
foreach (var i in releaseInfo.IndexerSettings.MultiLanguages) foreach (var i in indexerSettings.MultiLanguages)
{ {
var language = (Language) i; var language = (Language) i;
if (!movieInfo.Languages.Contains(language)) if (!movieInfo.Languages.Contains(language))

@ -13,7 +13,6 @@ namespace NzbDrone.Core.Parser.Model
public string InfoUrl { get; set; } public string InfoUrl { get; set; }
public string CommentUrl { get; set; } public string CommentUrl { get; set; }
public int IndexerId { get; set; } public int IndexerId { get; set; }
public IIndexerSettings IndexerSettings { get; set; }
public string Indexer { get; set; } public string Indexer { get; set; }
public DownloadProtocol DownloadProtocol { get; set; } public DownloadProtocol DownloadProtocol { get; set; }
public int TvdbId { get; set; } public int TvdbId { get; set; }

Loading…
Cancel
Save