Fixed: Remove Indexer if categories were changed to not include in sync

Applies to Full Sync Update

Fixes #912
pull/962/head
Qstick 3 years ago
parent cf01c52c34
commit 302ed91d05

@ -0,0 +1,87 @@
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.IndexerTests
{
[TestFixture]
public class IndexerCapabilitiesCategoriesFixture : CoreTest<IndexerCapabilitiesCategories>
{
[Test]
public void should_support_parent_if_child_mapping()
{
Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
var categories = new int[] { 2000 };
var supported = Subject.SupportedCategories(categories);
supported.Should().HaveCount(1);
}
[Test]
public void should_support_category_if_mapped()
{
Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
var categories = new int[] { 2030 };
var supported = Subject.SupportedCategories(categories);
supported.Should().HaveCount(1);
}
[Test]
public void should_not_support_category_if_not_mapped()
{
Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
var categories = new int[] { 2040 };
var supported = Subject.SupportedCategories(categories);
supported.Should().HaveCount(0);
}
[Test]
public void should_get_tracker_category_list()
{
Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
Subject.AddCategoryMapping(2, NewznabStandardCategory.MoviesHD, "Filme HD");
var supported = Subject.GetTrackerCategories();
supported.Should().HaveCount(2);
supported.First().Should().NotBeNull();
supported.First().Should().Be("1");
}
[Test]
public void should_get_category_by_tracker_id()
{
Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
Subject.AddCategoryMapping(2, NewznabStandardCategory.MoviesHD, "Filme HD");
var supported = Subject.MapTrackerCatToNewznab(2.ToString());
supported.Should().HaveCount(2);
supported.First().Should().NotBeNull();
supported.First().Id.Should().Be(NewznabStandardCategory.MoviesHD.Id);
}
[Test]
public void should_get_category_by_tracker_desc()
{
Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
Subject.AddCategoryMapping(2, NewznabStandardCategory.MoviesHD, "Filme HD");
var supported = Subject.MapTrackerCatDescToNewznab("Filme HD");
supported.Should().HaveCount(2);
supported.First().Should().NotBeNull();
supported.First().Id.Should().Be(NewznabStandardCategory.MoviesHD.Id);
}
}
}

@ -124,7 +124,17 @@ namespace NzbDrone.Core.Applications.Lidarr
if (!lidarrIndexer.Equals(remoteIndexer))
{
_lidarrV1Proxy.UpdateIndexer(lidarrIndexer, Settings);
if (indexer.Capabilities.Categories.SupportedCategories(Settings.SyncCategories.ToArray()).Any())
{
// Update the indexer if it still has categories that match
_lidarrV1Proxy.UpdateIndexer(lidarrIndexer, Settings);
}
else
{
// Else remove it, it no longer should be used
_lidarrV1Proxy.RemoveIndexer(remoteIndexer.Id, Settings);
_appIndexerMapService.Delete(indexerMapping.Id);
}
}
}
else

@ -124,7 +124,17 @@ namespace NzbDrone.Core.Applications.Radarr
if (!radarrIndexer.Equals(remoteIndexer))
{
_radarrV3Proxy.UpdateIndexer(radarrIndexer, Settings);
if (indexer.Capabilities.Categories.SupportedCategories(Settings.SyncCategories.ToArray()).Any())
{
// Update the indexer if it still has categories that match
_radarrV3Proxy.UpdateIndexer(radarrIndexer, Settings);
}
else
{
// Else remove it, it no longer should be used
_radarrV3Proxy.RemoveIndexer(remoteIndexer.Id, Settings);
_appIndexerMapService.Delete(indexerMapping.Id);
}
}
}
else

@ -124,7 +124,17 @@ namespace NzbDrone.Core.Applications.Readarr
if (!readarrIndexer.Equals(remoteIndexer))
{
_readarrV1Proxy.UpdateIndexer(readarrIndexer, Settings);
if (indexer.Capabilities.Categories.SupportedCategories(Settings.SyncCategories.ToArray()).Any())
{
// Update the indexer if it still has categories that match
_readarrV1Proxy.UpdateIndexer(readarrIndexer, Settings);
}
else
{
// Else remove it, it no longer should be used
_readarrV1Proxy.RemoveIndexer(remoteIndexer.Id, Settings);
_appIndexerMapService.Delete(indexerMapping.Id);
}
}
}
else

@ -124,7 +124,17 @@ namespace NzbDrone.Core.Applications.Sonarr
if (!sonarrIndexer.Equals(remoteIndexer))
{
_sonarrV3Proxy.UpdateIndexer(sonarrIndexer, Settings);
if (indexer.Capabilities.Categories.SupportedCategories(Settings.SyncCategories.ToArray()).Any() || indexer.Capabilities.Categories.SupportedCategories(Settings.AnimeSyncCategories.ToArray()).Any())
{
// Update the indexer if it still has categories that match
_sonarrV3Proxy.UpdateIndexer(sonarrIndexer, Settings);
}
else
{
// Else remove it, it no longer should be used
_sonarrV3Proxy.RemoveIndexer(remoteIndexer.Id, Settings);
_appIndexerMapService.Delete(indexerMapping.Id);
}
}
}
else

@ -114,7 +114,7 @@ namespace NzbDrone.Core.Applications.Whisparr
var appMappings = _appIndexerMapService.GetMappingsForApp(Definition.Id);
var indexerMapping = appMappings.FirstOrDefault(m => m.IndexerId == indexer.Id);
var radarrIndexer = BuildWhisparrIndexer(indexer, indexer.Protocol, indexerMapping?.RemoteIndexerId ?? 0);
var whisparrIndexer = BuildWhisparrIndexer(indexer, indexer.Protocol, indexerMapping?.RemoteIndexerId ?? 0);
var remoteIndexer = _whisparrV3Proxy.GetIndexer(indexerMapping.RemoteIndexerId, Settings);
@ -122,9 +122,19 @@ namespace NzbDrone.Core.Applications.Whisparr
{
_logger.Debug("Remote indexer found, syncing with current settings");
if (!radarrIndexer.Equals(remoteIndexer))
if (!whisparrIndexer.Equals(remoteIndexer))
{
_whisparrV3Proxy.UpdateIndexer(radarrIndexer, Settings);
if (indexer.Capabilities.Categories.SupportedCategories(Settings.SyncCategories.ToArray()).Any())
{
// Update the indexer if it still has categories that match
_whisparrV3Proxy.UpdateIndexer(whisparrIndexer, Settings);
}
else
{
// Else remove it, it no longer should be used
_whisparrV3Proxy.RemoveIndexer(remoteIndexer.Id, Settings);
_appIndexerMapService.Delete(indexerMapping.Id);
}
}
}
else
@ -134,8 +144,8 @@ namespace NzbDrone.Core.Applications.Whisparr
if (indexer.Capabilities.Categories.SupportedCategories(Settings.SyncCategories.ToArray()).Any())
{
_logger.Debug("Remote indexer not found, re-adding {0} to Whisparr", indexer.Name);
radarrIndexer.Id = 0;
var newRemoteIndexer = _whisparrV3Proxy.AddIndexer(radarrIndexer, Settings);
whisparrIndexer.Id = 0;
var newRemoteIndexer = _whisparrV3Proxy.AddIndexer(whisparrIndexer, Settings);
_appIndexerMapService.Insert(new AppIndexerMap { AppId = Definition.Id, IndexerId = indexer.Id, RemoteIndexerId = newRemoteIndexer.Id });
}
else

Loading…
Cancel
Save