mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
moveepisode is less side-effecty!
This commit is contained in:
parent
e256271c5c
commit
954a79639f
@ -53,8 +53,7 @@ public void Setup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Mocker.GetMock<IUpgradeMediaFiles>()
|
Mocker.GetMock<IUpgradeMediaFiles>()
|
||||||
.Setup(s => s.UpgradeEpisodeFile(It.IsAny<EpisodeFile>(), It.IsAny<LocalEpisode>()))
|
.Setup(s => s.UpgradeEpisodeFile(It.IsAny<EpisodeFile>(), It.IsAny<LocalEpisode>()));
|
||||||
.Returns(new EpisodeFile());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -60,8 +60,7 @@ private void GivenEpisodeFiles()
|
|||||||
private void GivenMovedFiles()
|
private void GivenMovedFiles()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<IMoveEpisodeFiles>()
|
Mocker.GetMock<IMoveEpisodeFiles>()
|
||||||
.Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), _series))
|
.Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), _series));
|
||||||
.Returns(_episodeFiles.First());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -93,7 +93,8 @@ public void Handle(EpisodeImportedEvent message)
|
|||||||
EpisodeId = episode.Id
|
EpisodeId = episode.Id
|
||||||
};
|
};
|
||||||
|
|
||||||
history.Data.Add("FileId", message.ImportedEpisode.Id.ToString());
|
//Won't have a value since we publish this event before saving to DB.
|
||||||
|
//history.Data.Add("FileId", message.ImportedEpisode.Id.ToString());
|
||||||
history.Data.Add("DroppedPath", message.DroppedEpisode.Path);
|
history.Data.Add("DroppedPath", message.DroppedEpisode.Path);
|
||||||
history.Data.Add("ImportedPath", message.ImportedEpisode.Path);
|
history.Data.Add("ImportedPath", message.ImportedEpisode.Path);
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ namespace NzbDrone.Core.MediaFiles
|
|||||||
{
|
{
|
||||||
public interface IMoveEpisodeFiles
|
public interface IMoveEpisodeFiles
|
||||||
{
|
{
|
||||||
EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, Series series);
|
string MoveEpisodeFile(EpisodeFile episodeFile, Series series);
|
||||||
EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode);
|
string MoveEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MoveEpisodeFiles : IMoveEpisodeFiles
|
public class MoveEpisodeFiles : IMoveEpisodeFiles
|
||||||
@ -38,27 +38,24 @@ public MoveEpisodeFiles(IEpisodeService episodeService,
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, Series series)
|
public string MoveEpisodeFile(EpisodeFile episodeFile, Series series)
|
||||||
{
|
{
|
||||||
var episodes = _episodeService.GetEpisodesByFileId(episodeFile.Id);
|
var episodes = _episodeService.GetEpisodesByFileId(episodeFile.Id);
|
||||||
var newFileName = _buildFileNames.BuildFilename(episodes, series, episodeFile);
|
var newFileName = _buildFileNames.BuildFilename(episodes, series, episodeFile);
|
||||||
var destinationFilename = _buildFileNames.BuildFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
|
var filePath = _buildFileNames.BuildFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
|
||||||
|
|
||||||
return MoveFile(episodeFile, destinationFilename);
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode)
|
public string MoveEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode)
|
||||||
{
|
{
|
||||||
var newFileName = _buildFileNames.BuildFilename(localEpisode.Episodes, localEpisode.Series, episodeFile);
|
var newFileName = _buildFileNames.BuildFilename(localEpisode.Episodes, localEpisode.Series, episodeFile);
|
||||||
var destinationFilename = _buildFileNames.BuildFilePath(localEpisode.Series, localEpisode.SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
|
var filePath = _buildFileNames.BuildFilePath(localEpisode.Series, localEpisode.SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
|
||||||
episodeFile = MoveFile(episodeFile, destinationFilename);
|
MoveFile(episodeFile, filePath);
|
||||||
|
return filePath;
|
||||||
_messageAggregator.PublishEvent(new EpisodeDownloadedEvent(localEpisode));
|
|
||||||
|
|
||||||
return episodeFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private EpisodeFile MoveFile(EpisodeFile episodeFile, string destinationFilename)
|
private void MoveFile(EpisodeFile episodeFile, string destinationFilename)
|
||||||
{
|
{
|
||||||
if (!_diskProvider.FileExists(episodeFile.Path))
|
if (!_diskProvider.FileExists(episodeFile.Path))
|
||||||
{
|
{
|
||||||
@ -85,10 +82,6 @@ private EpisodeFile MoveFile(EpisodeFile episodeFile, string destinationFilename
|
|||||||
_logger.Debug("Unable to apply folder permissions to: ", destinationFilename);
|
_logger.Debug("Unable to apply folder permissions to: ", destinationFilename);
|
||||||
_logger.TraceException(ex.Message, ex);
|
_logger.TraceException(ex.Message, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
episodeFile.Path = destinationFilename;
|
|
||||||
|
|
||||||
return episodeFile;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -68,11 +68,11 @@ public List<ImportDecision> Import(List<ImportDecision> decisions, bool newDownl
|
|||||||
|
|
||||||
if (newDownload)
|
if (newDownload)
|
||||||
{
|
{
|
||||||
episodeFile = _episodeFileUpgrader.UpgradeEpisodeFile(episodeFile, localEpisode);
|
episodeFile.Path = _episodeFileUpgrader.UpgradeEpisodeFile(episodeFile, localEpisode);
|
||||||
_messageAggregator.PublishEvent(new EpisodeImportedEvent(localEpisode, episodeFile));
|
_messageAggregator.PublishEvent(new EpisodeImportedEvent(localEpisode, episodeFile));
|
||||||
|
_messageAggregator.PublishEvent(new EpisodeDownloadedEvent(localEpisode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_mediaFileService.Add(episodeFile);
|
_mediaFileService.Add(episodeFile);
|
||||||
imported.Add(importDecision);
|
imported.Add(importDecision);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||||||
{
|
{
|
||||||
public interface IUpgradeMediaFiles
|
public interface IUpgradeMediaFiles
|
||||||
{
|
{
|
||||||
EpisodeFile UpgradeEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode);
|
string UpgradeEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UpgradeMediaFileService : IUpgradeMediaFiles
|
public class UpgradeMediaFileService : IUpgradeMediaFiles
|
||||||
@ -31,7 +31,7 @@ public UpgradeMediaFileService(IRecycleBinProvider recycleBinProvider,
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EpisodeFile UpgradeEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode)
|
public string UpgradeEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode)
|
||||||
{
|
{
|
||||||
var existingFiles = localEpisode.Episodes
|
var existingFiles = localEpisode.Episodes
|
||||||
.Where(e => e.EpisodeFileId > 0)
|
.Where(e => e.EpisodeFileId > 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user