parent
cc23f2e653
commit
e2cff7d9fa
@ -0,0 +1,17 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Recyclarr.Config.Parsing.PostProcessing.Deprecations;
|
||||
|
||||
namespace Recyclarr.Config.Parsing.PostProcessing;
|
||||
|
||||
public class ConfigDeprecationPostProcessor(ConfigDeprecations deprecations) : IConfigPostProcessor
|
||||
{
|
||||
[SuppressMessage("ReSharper", "WithExpressionModifiesAllMembers")]
|
||||
public RootConfigYaml Process(RootConfigYaml config)
|
||||
{
|
||||
return config with
|
||||
{
|
||||
Radarr = config.Radarr?.ToDictionary(x => x.Key, x => deprecations.CheckAndTransform(x.Value)),
|
||||
Sonarr = config.Sonarr?.ToDictionary(x => x.Key, x => deprecations.CheckAndTransform(x.Value))
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
namespace Recyclarr.Config.Parsing.PostProcessing.Deprecations;
|
||||
|
||||
public class CfQualityProfilesDeprecationCheck(ILogger log) : IConfigDeprecationCheck
|
||||
{
|
||||
public bool CheckIfNeeded(ServiceConfigYaml include)
|
||||
{
|
||||
return
|
||||
include.CustomFormats is not null &&
|
||||
include.CustomFormats.Any(x => x.QualityProfiles is {Count: > 0});
|
||||
}
|
||||
|
||||
public ServiceConfigYaml Transform(ServiceConfigYaml include)
|
||||
{
|
||||
log.Warning(
|
||||
"DEPRECATED: The `quality_profiles` element under `custom_formats` nodes was " +
|
||||
"detected in your config. This has been renamed to `assign_scores_to`. " +
|
||||
"See: https://recyclarr.dev/wiki/upgrade-guide/v8.0/#assign-scores-to");
|
||||
|
||||
// CustomFormats is checked for null in the CheckIfNeeded() method, which is called first.
|
||||
var cfs = include.CustomFormats!.Select(x => x with
|
||||
{
|
||||
AssignScoresTo = [..x.AssignScoresTo ?? [], ..x.QualityProfiles ?? []],
|
||||
QualityProfiles = null
|
||||
});
|
||||
|
||||
return include with
|
||||
{
|
||||
CustomFormats = cfs.ToList()
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Recyclarr.Config.Parsing.PostProcessing.Deprecations;
|
||||
|
||||
public class ConfigDeprecations(IOrderedEnumerable<IConfigDeprecationCheck> deprecationChecks)
|
||||
{
|
||||
[SuppressMessage("SonarLint", "S3267: Loops should be simplified with LINQ expressions", Justification =
|
||||
"The 'Where' condition must happen after each Transform() call instead of all at once")]
|
||||
public T CheckAndTransform<T>(T include) where T : ServiceConfigYaml
|
||||
{
|
||||
foreach (var check in deprecationChecks)
|
||||
{
|
||||
if (check.CheckIfNeeded(include))
|
||||
{
|
||||
include = (T) check.Transform(include);
|
||||
}
|
||||
}
|
||||
|
||||
return include;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
namespace Recyclarr.Config.Parsing.PostProcessing.Deprecations;
|
||||
|
||||
public interface IConfigDeprecationCheck
|
||||
{
|
||||
ServiceConfigYaml Transform(ServiceConfigYaml include);
|
||||
bool CheckIfNeeded(ServiceConfigYaml include);
|
||||
}
|
Loading…
Reference in new issue