New: Show missing root folder path in edit for Import List (cherry picked from commit ae196af2ad368d49fde2358f0987ed7650c7f29c) Closes #1998pull/4068/head
parent
af1e2fe2eb
commit
bfb86dafc9
@ -0,0 +1,82 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Common.Serializer;
|
||||||
|
using NzbDrone.Core.Datastore.Events;
|
||||||
|
using NzbDrone.Core.ImportLists;
|
||||||
|
using NzbDrone.Core.Localization;
|
||||||
|
using NzbDrone.Core.MediaFiles.Events;
|
||||||
|
using NzbDrone.Core.Music.Events;
|
||||||
|
using NzbDrone.Core.RootFolders;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.HealthCheck.Checks
|
||||||
|
{
|
||||||
|
[CheckOn(typeof(ModelEvent<RootFolder>))]
|
||||||
|
[CheckOn(typeof(ArtistsDeletedEvent))]
|
||||||
|
[CheckOn(typeof(ArtistMovedEvent))]
|
||||||
|
[CheckOn(typeof(TrackImportedEvent), CheckOnCondition.FailedOnly)]
|
||||||
|
[CheckOn(typeof(TrackImportFailedEvent), CheckOnCondition.SuccessfulOnly)]
|
||||||
|
public class ImportListRootFolderCheck : HealthCheckBase
|
||||||
|
{
|
||||||
|
private readonly IImportListFactory _importListFactory;
|
||||||
|
private readonly IDiskProvider _diskProvider;
|
||||||
|
|
||||||
|
public ImportListRootFolderCheck(IImportListFactory importListFactory, IDiskProvider diskProvider, ILocalizationService localizationService)
|
||||||
|
: base(localizationService)
|
||||||
|
{
|
||||||
|
_importListFactory = importListFactory;
|
||||||
|
_diskProvider = diskProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override HealthCheck Check()
|
||||||
|
{
|
||||||
|
var importLists = _importListFactory.All();
|
||||||
|
var missingRootFolders = new Dictionary<string, List<ImportListDefinition>>();
|
||||||
|
|
||||||
|
Console.WriteLine(importLists.ToArray().ToJson());
|
||||||
|
|
||||||
|
foreach (var importList in importLists)
|
||||||
|
{
|
||||||
|
var rootFolderPath = importList.RootFolderPath;
|
||||||
|
|
||||||
|
if (missingRootFolders.ContainsKey(rootFolderPath))
|
||||||
|
{
|
||||||
|
missingRootFolders[rootFolderPath].Add(importList);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_diskProvider.FolderExists(rootFolderPath))
|
||||||
|
{
|
||||||
|
missingRootFolders.Add(rootFolderPath, new List<ImportListDefinition> { importList });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (missingRootFolders.Any())
|
||||||
|
{
|
||||||
|
if (missingRootFolders.Count == 1)
|
||||||
|
{
|
||||||
|
var missingRootFolder = missingRootFolders.First();
|
||||||
|
|
||||||
|
return new HealthCheck(GetType(),
|
||||||
|
HealthCheckResult.Error,
|
||||||
|
string.Format(_localizationService.GetLocalizedString("ImportListRootFolderMissingRootHealthCheckMessage"), FormatRootFolder(missingRootFolder.Key, missingRootFolder.Value)),
|
||||||
|
"#import-list-missing-root-folder");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HealthCheck(GetType(),
|
||||||
|
HealthCheckResult.Error,
|
||||||
|
string.Format(_localizationService.GetLocalizedString("ImportListRootFolderMultipleMissingRootsHealthCheckMessage"), string.Join(" | ", missingRootFolders.Select(m => FormatRootFolder(m.Key, m.Value)))),
|
||||||
|
"#import-list-missing-root-folder");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HealthCheck(GetType());
|
||||||
|
}
|
||||||
|
|
||||||
|
private string FormatRootFolder(string rootFolderPath, List<ImportListDefinition> importLists)
|
||||||
|
{
|
||||||
|
return $"{rootFolderPath} ({string.Join(", ", importLists.Select(l => l.Name))})";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue