mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-25 15:22:42 +00:00
parent
0f1c315d2f
commit
4f5a0b7afd
7 changed files with 61 additions and 23 deletions
|
@ -81,12 +81,13 @@ private object SaveAll()
|
|||
}
|
||||
}
|
||||
|
||||
if (resource.MoveFiles && artistToMove.Any())
|
||||
if (artistToMove.Any())
|
||||
{
|
||||
_commandQueueManager.Push(new BulkMoveArtistCommand
|
||||
{
|
||||
DestinationRootFolder = resource.RootFolderPath,
|
||||
Artist = artistToMove
|
||||
Artist = artistToMove,
|
||||
MoveFiles = resource.MoveFiles
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -145,19 +145,17 @@ private void UpdateArtist(ArtistResource artistResource)
|
|||
var moveFiles = Request.GetBooleanQueryParameter("moveFiles");
|
||||
var artist = _artistService.GetArtist(artistResource.Id);
|
||||
|
||||
if (moveFiles)
|
||||
{
|
||||
var sourcePath = artist.Path;
|
||||
var destinationPath = artistResource.Path;
|
||||
var sourcePath = artist.Path;
|
||||
var destinationPath = artistResource.Path;
|
||||
|
||||
_commandQueueManager.Push(new MoveArtistCommand
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
SourcePath = sourcePath,
|
||||
DestinationPath = destinationPath,
|
||||
Trigger = CommandTrigger.Manual
|
||||
});
|
||||
}
|
||||
_commandQueueManager.Push(new MoveArtistCommand
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
SourcePath = sourcePath,
|
||||
DestinationPath = destinationPath,
|
||||
MoveFiles = moveFiles,
|
||||
Trigger = CommandTrigger.Manual
|
||||
});
|
||||
|
||||
var model = artistResource.ToModel(artist);
|
||||
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Music.Commands;
|
||||
using NzbDrone.Core.Music.Events;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
@ -29,9 +31,10 @@ public void Setup()
|
|||
|
||||
_command = new MoveArtistCommand
|
||||
{
|
||||
ArtistId = 1,
|
||||
ArtistId = _artist.Id,
|
||||
SourcePath = @"C:\Test\Music\Artist".AsOsAgnostic(),
|
||||
DestinationPath = @"C:\Test\Music2\Artist".AsOsAgnostic()
|
||||
DestinationPath = @"C:\Test\Music2\Artist".AsOsAgnostic(),
|
||||
MoveFiles = true
|
||||
};
|
||||
|
||||
_bulkCommand = new BulkMoveArtistCommand
|
||||
|
@ -40,11 +43,12 @@ public void Setup()
|
|||
{
|
||||
new BulkMoveArtist
|
||||
{
|
||||
ArtistId = 1,
|
||||
ArtistId = _artist.Id,
|
||||
SourcePath = @"C:\Test\Music\Artist".AsOsAgnostic()
|
||||
}
|
||||
},
|
||||
DestinationRootFolder = @"C:\Test\Music2".AsOsAgnostic()
|
||||
DestinationRootFolder = @"C:\Test\Music2".AsOsAgnostic(),
|
||||
MoveFiles = true
|
||||
};
|
||||
|
||||
Mocker.GetMock<IArtistService>()
|
||||
|
@ -143,5 +147,33 @@ public void should_skip_artist_folder_if_it_does_not_exist()
|
|||
Mocker.GetMock<IBuildFileNames>()
|
||||
.Verify(v => v.GetArtistFolder(It.IsAny<Artist>(), null), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_raise_artist_moved_event_when_move_files_false()
|
||||
{
|
||||
_command.MoveFiles = false;
|
||||
Subject.Execute(_command);
|
||||
|
||||
Mocker.GetMock<IEventAggregator>()
|
||||
.Verify(v => v.PublishEvent(It.Is<ArtistMovedEvent>(c => c.Artist.Id == _artist.Id)), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_raise_artist_moved_event_when_move_files_false_bulk()
|
||||
{
|
||||
_bulkCommand.MoveFiles = false;
|
||||
|
||||
var artistFolder = "Artist";
|
||||
var expectedPath = Path.Combine(_bulkCommand.DestinationRootFolder, artistFolder);
|
||||
|
||||
Mocker.GetMock<IBuildFileNames>()
|
||||
.Setup(s => s.GetArtistFolder(It.IsAny<Artist>(), null))
|
||||
.Returns(artistFolder);
|
||||
|
||||
Subject.Execute(_bulkCommand);
|
||||
|
||||
Mocker.GetMock<IEventAggregator>()
|
||||
.Verify(v => v.PublishEvent(It.Is<ArtistMovedEvent>(c => c.Artist.Id == _artist.Id)), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,6 +203,7 @@ public void UpdateMediaInfo(List<TrackFile> trackFiles)
|
|||
|
||||
public void Handle(ArtistMovedEvent message)
|
||||
{
|
||||
// TODO: Be more careful when arbitrary artist paths are allowed
|
||||
var files = _mediaFileRepository.GetFilesWithBasePath(message.SourcePath);
|
||||
|
||||
foreach (var file in files)
|
||||
|
|
|
@ -8,6 +8,7 @@ public class BulkMoveArtistCommand : Command
|
|||
{
|
||||
public List<BulkMoveArtist> Artist { get; set; }
|
||||
public string DestinationRootFolder { get; set; }
|
||||
public bool MoveFiles { get; set; }
|
||||
|
||||
public override bool SendUpdatesToClient => true;
|
||||
public override bool RequiresDiskAccess => true;
|
||||
|
|
|
@ -7,6 +7,7 @@ public class MoveArtistCommand : Command
|
|||
public int ArtistId { get; set; }
|
||||
public string SourcePath { get; set; }
|
||||
public string DestinationPath { get; set; }
|
||||
public bool MoveFiles { get; set; }
|
||||
|
||||
public override bool SendUpdatesToClient => true;
|
||||
public override bool RequiresDiskAccess => true;
|
||||
|
|
|
@ -34,7 +34,7 @@ public MoveArtistService(IArtistService artistService,
|
|||
_logger = logger;
|
||||
}
|
||||
|
||||
private void MoveSingleArtist(Artist artist, string sourcePath, string destinationPath, int? index = null, int? total = null)
|
||||
private void MoveSingleArtist(Artist artist, string sourcePath, string destinationPath, bool moveFiles, int? index = null, int? total = null)
|
||||
{
|
||||
if (!_diskProvider.FolderExists(sourcePath))
|
||||
{
|
||||
|
@ -53,9 +53,12 @@ private void MoveSingleArtist(Artist artist, string sourcePath, string destinati
|
|||
|
||||
try
|
||||
{
|
||||
_diskTransferService.TransferFolder(sourcePath, destinationPath, TransferMode.Move);
|
||||
if (moveFiles)
|
||||
{
|
||||
_diskTransferService.TransferFolder(sourcePath, destinationPath, TransferMode.Move);
|
||||
|
||||
_logger.ProgressInfo("{0} moved successfully to {1}", artist.Name, artist.Path);
|
||||
_logger.ProgressInfo("{0} moved successfully to {1}", artist.Name, artist.Path);
|
||||
}
|
||||
|
||||
_eventAggregator.PublishEvent(new ArtistMovedEvent(artist, sourcePath, destinationPath));
|
||||
}
|
||||
|
@ -78,7 +81,8 @@ private void RevertPath(int artistId, string path)
|
|||
public void Execute(MoveArtistCommand message)
|
||||
{
|
||||
var artist = _artistService.GetArtist(message.ArtistId);
|
||||
MoveSingleArtist(artist, message.SourcePath, message.DestinationPath);
|
||||
|
||||
MoveSingleArtist(artist, message.SourcePath, message.DestinationPath, message.MoveFiles);
|
||||
}
|
||||
|
||||
public void Execute(BulkMoveArtistCommand message)
|
||||
|
@ -94,7 +98,7 @@ public void Execute(BulkMoveArtistCommand message)
|
|||
var artist = _artistService.GetArtist(s.ArtistId);
|
||||
var destinationPath = Path.Combine(destinationRootFolder, _filenameBuilder.GetArtistFolder(artist));
|
||||
|
||||
MoveSingleArtist(artist, s.SourcePath, destinationPath, index, artistToMove.Count);
|
||||
MoveSingleArtist(artist, s.SourcePath, destinationPath, message.MoveFiles, index, artistToMove.Count);
|
||||
}
|
||||
|
||||
_logger.ProgressInfo("Finished moving {0} artist to '{1}'", artistToMove.Count, destinationRootFolder);
|
||||
|
|
Loading…
Reference in a new issue