fix: Restore compare by name for CFs

This is still needed if there already exist CFs in Radarr/Sonarr with
the same name.
pull/151/head
Robert Dailey 2 years ago
parent b13656dca5
commit 4ae54d8f54

@ -1,4 +1,5 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using Common.Extensions;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using TrashLib.Services.CustomFormat.Models; using TrashLib.Services.CustomFormat.Models;
using TrashLib.Services.CustomFormat.Models.Cache; using TrashLib.Services.CustomFormat.Models.Cache;
@ -72,10 +73,10 @@ internal class JsonTransactionStep : IJsonTransactionStep
private static JObject? FindServiceCf(IReadOnlyCollection<JObject> serviceCfs, ProcessedCustomFormatData guideCf) private static JObject? FindServiceCf(IReadOnlyCollection<JObject> serviceCfs, ProcessedCustomFormatData guideCf)
{ {
return FindServiceCf(serviceCfs, guideCf.CacheEntry?.CustomFormatId); return FindServiceCf(serviceCfs, guideCf.CacheEntry?.CustomFormatId, guideCf.Name);
} }
private static JObject? FindServiceCf(IReadOnlyCollection<JObject> serviceCfs, int? cfId) private static JObject? FindServiceCf(IReadOnlyCollection<JObject> serviceCfs, int? cfId, string? cfName = null)
{ {
JObject? match = null; JObject? match = null;
@ -85,6 +86,12 @@ internal class JsonTransactionStep : IJsonTransactionStep
match = serviceCfs.FirstOrDefault(rcf => cfId == rcf.Value<int>("id")); match = serviceCfs.FirstOrDefault(rcf => cfId == rcf.Value<int>("id"));
} }
// If we don't find by ID, search by name (if a name was given)
if (match is null && cfName is not null)
{
match = serviceCfs.FirstOrDefault(rcf => cfName.EqualsIgnoreCase(rcf.Value<string>("name")));
}
return match; return match;
} }

Loading…
Cancel
Save