Fixed: Update file paths correctly when moving artist

Fixes #1088
pull/1689/head
ta264 5 years ago committed by Qstick
parent 0f1c315d2f
commit 4f5a0b7afd

@ -81,12 +81,13 @@ namespace Lidarr.Api.V1.Artist
}
}
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 @@ namespace Lidarr.Api.V1.Artist
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 FizzWare.NBuilder;
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 @@ namespace NzbDrone.Core.Test.MusicTests
_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 @@ namespace NzbDrone.Core.Test.MusicTests
{
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 @@ namespace NzbDrone.Core.Test.MusicTests
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 @@ namespace NzbDrone.Core.MediaFiles
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 @@ namespace NzbDrone.Core.Music.Commands
{
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 @@ namespace NzbDrone.Core.Music.Commands
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 @@ namespace NzbDrone.Core.Music
_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 @@ namespace NzbDrone.Core.Music
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 @@ namespace NzbDrone.Core.Music
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 @@ namespace NzbDrone.Core.Music
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…
Cancel
Save