New: Store episode renames in History

Closes #1541
This commit is contained in:
Mark McDowall 2017-06-05 21:05:51 -07:00 committed by Mark McDowall
parent f293b9a44e
commit 9312f0a462
11 changed files with 92 additions and 5 deletions

View File

@ -36,6 +36,7 @@ namespace NzbDrone.Core.History
SeriesFolderImported = 2, SeriesFolderImported = 2,
DownloadFolderImported = 3, DownloadFolderImported = 3,
DownloadFailed = 4, DownloadFailed = 4,
EpisodeFileDeleted = 5 EpisodeFileDeleted = 5,
EpisodeFileRenamed = 6
} }
} }

View File

@ -32,6 +32,7 @@ namespace NzbDrone.Core.History
IHandle<EpisodeImportedEvent>, IHandle<EpisodeImportedEvent>,
IHandle<DownloadFailedEvent>, IHandle<DownloadFailedEvent>,
IHandle<EpisodeFileDeletedEvent>, IHandle<EpisodeFileDeletedEvent>,
IHandle<EpisodeFileRenamedEvent>,
IHandle<SeriesDeletedEvent> IHandle<SeriesDeletedEvent>
{ {
private readonly IHistoryRepository _historyRepository; private readonly IHistoryRepository _historyRepository;
@ -257,6 +258,34 @@ namespace NzbDrone.Core.History
} }
} }
public void Handle(EpisodeFileRenamedEvent message)
{
var sourcePath = message.OriginalPath;
var sourceRelativePath = message.Series.Path.GetRelativePath(message.OriginalPath);
var path = Path.Combine(message.Series.Path, message.EpisodeFile.RelativePath);
var relativePath = message.EpisodeFile.RelativePath;
foreach (var episode in message.EpisodeFile.Episodes.Value)
{
var history = new History
{
EventType = HistoryEventType.EpisodeFileRenamed,
Date = DateTime.UtcNow,
Quality = message.EpisodeFile.Quality,
SourceTitle = message.OriginalPath,
SeriesId = message.EpisodeFile.SeriesId,
EpisodeId = episode.Id,
};
history.Data.Add("SourcePath", sourcePath);
history.Data.Add("SourceRelativePath", sourceRelativePath);
history.Data.Add("Path", path);
history.Data.Add("RelativePath", relativePath);
_historyRepository.Insert(history);
}
}
public void Handle(SeriesDeletedEvent message) public void Handle(SeriesDeletedEvent message)
{ {
_historyRepository.DeleteForSeries(message.Series.Id); _historyRepository.DeleteForSeries(message.Series.Id);

View File

@ -0,0 +1,19 @@
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.MediaFiles.Events
{
public class EpisodeFileRenamedEvent : IEvent
{
public Series Series { get; private set; }
public EpisodeFile EpisodeFile { get; private set; }
public string OriginalPath { get; private set; }
public EpisodeFileRenamedEvent(Series series, EpisodeFile episodeFile, string originalPath)
{
Series = series;
EpisodeFile = episodeFile;
OriginalPath = originalPath;
}
}
}

View File

@ -125,6 +125,8 @@ namespace NzbDrone.Core.MediaFiles
renamed.Add(episodeFile); renamed.Add(episodeFile);
_logger.Debug("Renamed episode file: {0}", episodeFile); _logger.Debug("Renamed episode file: {0}", episodeFile);
_eventAggregator.PublishEvent(new EpisodeFileRenamedEvent(series, episodeFile, episodeFilePath));
} }
catch (SameFilenameException ex) catch (SameFilenameException ex)
{ {

View File

@ -787,6 +787,7 @@
<Compile Include="MediaFiles\EpisodeImport\Specifications\UnverifiedSceneNumberingSpecification.cs" /> <Compile Include="MediaFiles\EpisodeImport\Specifications\UnverifiedSceneNumberingSpecification.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\UpgradeSpecification.cs" /> <Compile Include="MediaFiles\EpisodeImport\Specifications\UpgradeSpecification.cs" />
<Compile Include="MediaFiles\Events\EpisodeFileAddedEvent.cs" /> <Compile Include="MediaFiles\Events\EpisodeFileAddedEvent.cs" />
<Compile Include="MediaFiles\Events\EpisodeFileRenamedEvent.cs" />
<Compile Include="MediaFiles\Events\EpisodeFileDeletedEvent.cs" /> <Compile Include="MediaFiles\Events\EpisodeFileDeletedEvent.cs" />
<Compile Include="MediaFiles\Events\EpisodeFolderCreatedEvent.cs" /> <Compile Include="MediaFiles\Events\EpisodeFolderCreatedEvent.cs" />
<Compile Include="MediaFiles\Events\EpisodeImportedEvent.cs" /> <Compile Include="MediaFiles\Events\EpisodeImportedEvent.cs" />

View File

@ -8,6 +8,7 @@
{{#if_eq eventType compare="downloadFailed"}}Download Failed{{/if_eq}} {{#if_eq eventType compare="downloadFailed"}}Download Failed{{/if_eq}}
{{#if_eq eventType compare="downloadFolderImported"}}Episode Imported{{/if_eq}} {{#if_eq eventType compare="downloadFolderImported"}}Episode Imported{{/if_eq}}
{{#if_eq eventType compare="episodeFileDeleted"}}Episode File Deleted{{/if_eq}} {{#if_eq eventType compare="episodeFileDeleted"}}Episode File Deleted{{/if_eq}}
{{#if_eq eventType compare="episodeFileRenamed"}}Episode File Renamed{{/if_eq}}
</h3> </h3>
</div> </div>

View File

@ -101,3 +101,22 @@
{{/with}} {{/with}}
</dl> </dl>
{{/if_eq}} {{/if_eq}}
{{#if_eq eventType compare="episodeFileRenamed"}}
<dl class="dl-horizontal">
<dt>Source Path:</dt>
<dd>{{sourceTitle}}</dd>
{{#with data}}
<dt>Source Relative Path:</dt>
<dd>{{sourceRelativePath}}</dd>
<dt>Path:</dt>
<dd>{{path}}</dd>
<dt>Relative Path:</dt>
<dd>{{relativePath}}</dd>
{{/with}}
</dl>
{{/if_eq}}

View File

@ -46,6 +46,10 @@ var Collection = PageableCollection.extend({
'deleted' : [ 'deleted' : [
'eventType', 'eventType',
'5' '5'
],
'renamed' : [
'eventType',
'6'
] ]
}, },

View File

@ -129,6 +129,13 @@ module.exports = Marionette.Layout.extend({
tooltip : 'Deleted', tooltip : 'Deleted',
icon : 'icon-sonarr-deleted', icon : 'icon-sonarr-deleted',
callback : this._setFilter callback : this._setFilter
},
{
key : 'renamed',
title : '',
tooltip : 'Renamed',
icon : 'icon-sonarr-rename',
callback : this._setFilter
} }
] ]
}; };

View File

@ -31,6 +31,10 @@ module.exports = NzbDroneCell.extend({
icon = 'icon-sonarr-deleted'; icon = 'icon-sonarr-deleted';
toolTip = 'Episode file deleted'; toolTip = 'Episode file deleted';
break; break;
case 'episodeFileRenamed':
icon = 'icon-sonarr-rename';
toolTip = 'Episode file renamed';
break;
default: default:
icon = 'icon-sonarr-unknown'; icon = 'icon-sonarr-unknown';
toolTip = 'unknown event'; toolTip = 'unknown event';