mirror of
https://github.com/Readarr/Readarr
synced 2026-01-03 22:28:23 +01:00
Fixed: Incorrectly looking up books by EditionId
This commit is contained in:
parent
13d8554e7e
commit
fe13823b43
11 changed files with 34 additions and 23 deletions
|
|
@ -47,8 +47,11 @@ public void Setup()
|
|||
|
||||
var edition = Builder<Edition>.CreateNew()
|
||||
.With(e => e.Book = book)
|
||||
.With(e => e.Monitored = true)
|
||||
.Build();
|
||||
|
||||
book.Editions = new List<Edition> { edition };
|
||||
|
||||
var rootFolder = Builder<RootFolder>.CreateNew()
|
||||
.With(r => r.IsCalibreLibrary = false)
|
||||
.Build();
|
||||
|
|
@ -85,6 +88,10 @@ public void Setup()
|
|||
Mocker.GetMock<IRootFolderService>()
|
||||
.Setup(s => s.GetBestRootFolder(It.IsAny<string>()))
|
||||
.Returns(rootFolder);
|
||||
|
||||
Mocker.GetMock<IEditionService>()
|
||||
.Setup(s => s.SetMonitored(edition))
|
||||
.Returns(new List<Edition> { edition });
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
|||
|
|
@ -165,6 +165,7 @@ private void VerifyUnmapped(List<BookFile> files)
|
|||
}
|
||||
}
|
||||
|
||||
[Ignore("Doesn't make sense now we link to edition")]
|
||||
[Test]
|
||||
public void delete_files_by_book_should_work_if_join_fails()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ protected override UpdateResult MergeEntity(Book local, Book target, Book remote
|
|||
|
||||
// Update book ids for trackfiles
|
||||
var files = _mediaFileService.GetFilesByBook(local.Id);
|
||||
files.ForEach(x => x.EditionId = target.Id);
|
||||
files.ForEach(x => x.EditionId = target.Editions.Value.Single(e => e.Monitored).Id);
|
||||
_mediaFileService.Update(files);
|
||||
|
||||
// Update book ids for history
|
||||
|
|
|
|||
|
|
@ -157,7 +157,8 @@ public static void Map()
|
|||
new SqlBuilder()
|
||||
.Join<Author, AuthorMetadata>((a, m) => a.AuthorMetadataId == m.Id)
|
||||
.Join<Author, Book>((l, r) => l.AuthorMetadataId == r.AuthorMetadataId)
|
||||
.Where<Book>(a => a.Id == f.EditionId)).SingleOrDefault(),
|
||||
.Join<Book, Edition>((l, r) => l.Id == r.BookId)
|
||||
.Where<Edition>(a => a.Id == f.EditionId)).SingleOrDefault(),
|
||||
t => t.Id > 0);
|
||||
|
||||
Mapper.Entity<QualityDefinition>("QualityDefinitions").RegisterModel()
|
||||
|
|
|
|||
|
|
@ -27,21 +27,21 @@ public class ExtraService : IExtraService,
|
|||
IHandle<AuthorRenamedEvent>
|
||||
{
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly IBookService _bookService;
|
||||
private readonly IEditionService _editionService;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly List<IManageExtraFiles> _extraFileManagers;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ExtraService(IMediaFileService mediaFileService,
|
||||
IBookService bookService,
|
||||
IEditionService editionService,
|
||||
IDiskProvider diskProvider,
|
||||
IConfigService configService,
|
||||
IEnumerable<IManageExtraFiles> extraFileManagers,
|
||||
Logger logger)
|
||||
{
|
||||
_mediaFileService = mediaFileService;
|
||||
_bookService = bookService;
|
||||
_editionService = editionService;
|
||||
_diskProvider = diskProvider;
|
||||
_configService = configService;
|
||||
_extraFileManagers = extraFileManagers.OrderBy(e => e.Order).ToList();
|
||||
|
|
@ -143,11 +143,11 @@ public void Handle(MediaCoversUpdatedEvent message)
|
|||
public void Handle(TrackFolderCreatedEvent message)
|
||||
{
|
||||
var author = message.Author;
|
||||
var book = _bookService.GetBook(message.BookFile.EditionId);
|
||||
var edition = _editionService.GetEdition(message.BookFile.EditionId);
|
||||
|
||||
foreach (var extraFileManager in _extraFileManagers)
|
||||
{
|
||||
extraFileManager.CreateAfterBookImport(author, book, message.AuthorFolder, message.BookFolder);
|
||||
extraFileManager.CreateAfterBookImport(author, edition.Book.Value, message.AuthorFolder, message.BookFolder);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ protected TExtraFile ImportFile(Author author, BookFile bookFile, string path, b
|
|||
return new TExtraFile
|
||||
{
|
||||
AuthorId = author.Id,
|
||||
BookId = bookFile.EditionId,
|
||||
BookId = bookFile.Edition.Value.BookId,
|
||||
BookFileId = bookFile.Id,
|
||||
RelativePath = author.Path.GetRelativePath(newFileName),
|
||||
Extension = extension
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ public override IEnumerable<ExtraFile> MoveFilesAfterRename(Author author, List<
|
|||
foreach (var filePath in distinctTrackFilePaths)
|
||||
{
|
||||
var metadataFilesForConsumer = GetMetadataFilesForConsumer(consumer, metadataFiles)
|
||||
.Where(m => m.BookId == filePath.EditionId)
|
||||
.Where(m => m.BookId == filePath.Edition.Value.BookId)
|
||||
.Where(m => m.Type == MetadataType.BookImage || m.Type == MetadataType.BookMetadata)
|
||||
.ToList();
|
||||
|
||||
|
|
@ -287,7 +287,7 @@ private MetadataFile ProcessBookMetadata(IMetadata consumer, Author author, Book
|
|||
new MetadataFile
|
||||
{
|
||||
AuthorId = author.Id,
|
||||
BookId = bookFile.EditionId,
|
||||
BookId = bookFile.Edition.Value.BookId,
|
||||
BookFileId = bookFile.Id,
|
||||
Consumer = consumer.GetType().Name,
|
||||
Type = MetadataType.BookMetadata,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public interface IMoveBookFiles
|
|||
|
||||
public class BookFileMovingService : IMoveBookFiles
|
||||
{
|
||||
private readonly IBookService _bookService;
|
||||
private readonly IEditionService _editionService;
|
||||
private readonly IUpdateBookFileService _updateBookFileService;
|
||||
private readonly IBuildFileNames _buildFileNames;
|
||||
private readonly IDiskTransferService _diskTransferService;
|
||||
|
|
@ -35,7 +35,7 @@ public class BookFileMovingService : IMoveBookFiles
|
|||
private readonly IConfigService _configService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public BookFileMovingService(IBookService bookService,
|
||||
public BookFileMovingService(IEditionService editionService,
|
||||
IUpdateBookFileService updateBookFileService,
|
||||
IBuildFileNames buildFileNames,
|
||||
IDiskTransferService diskTransferService,
|
||||
|
|
@ -46,7 +46,7 @@ public BookFileMovingService(IBookService bookService,
|
|||
IConfigService configService,
|
||||
Logger logger)
|
||||
{
|
||||
_bookService = bookService;
|
||||
_editionService = editionService;
|
||||
_updateBookFileService = updateBookFileService;
|
||||
_buildFileNames = buildFileNames;
|
||||
_diskTransferService = diskTransferService;
|
||||
|
|
@ -60,11 +60,11 @@ public BookFileMovingService(IBookService bookService,
|
|||
|
||||
public BookFile MoveBookFile(BookFile bookFile, Author author)
|
||||
{
|
||||
var book = _bookService.GetBook(bookFile.EditionId);
|
||||
var newFileName = _buildFileNames.BuildBookFileName(author, bookFile.Edition.Value, bookFile);
|
||||
var filePath = _buildFileNames.BuildBookFilePath(author, bookFile.Edition.Value, newFileName, Path.GetExtension(bookFile.Path));
|
||||
var edition = _editionService.GetEdition(bookFile.EditionId);
|
||||
var newFileName = _buildFileNames.BuildBookFileName(author, edition, bookFile);
|
||||
var filePath = _buildFileNames.BuildBookFilePath(author, edition, newFileName, Path.GetExtension(bookFile.Path));
|
||||
|
||||
EnsureBookFolder(bookFile, author, book, filePath);
|
||||
EnsureBookFolder(bookFile, author, edition.Book.Value, filePath);
|
||||
|
||||
_logger.Debug("Renaming book file: {0} to {1}", bookFile, filePath);
|
||||
|
||||
|
|
|
|||
|
|
@ -276,6 +276,7 @@ public List<ImportResult> Import(List<ImportDecision<LocalBook>> decisions, bool
|
|||
foreach (var bookImport in bookImports)
|
||||
{
|
||||
var book = bookImport.First().ImportDecision.Item.Book;
|
||||
var edition = book.Editions.Value.Single(x => x.Monitored);
|
||||
var author = bookImport.First().ImportDecision.Item.Author;
|
||||
|
||||
if (bookImport.Where(e => e.Errors.Count == 0).ToList().Count > 0 && author != null && book != null)
|
||||
|
|
@ -283,8 +284,8 @@ public List<ImportResult> Import(List<ImportDecision<LocalBook>> decisions, bool
|
|||
_eventAggregator.PublishEvent(new BookImportedEvent(
|
||||
author,
|
||||
book,
|
||||
allImportedTrackFiles.Where(s => s.EditionId == book.Id).ToList(),
|
||||
allOldTrackFiles.Where(s => s.EditionId == book.Id).ToList(),
|
||||
allImportedTrackFiles.Where(s => s.EditionId == edition.Id).ToList(),
|
||||
allOldTrackFiles.Where(s => s.EditionId == edition.Id).ToList(),
|
||||
replaceExisting,
|
||||
downloadClientItem));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,12 +86,13 @@ public List<BookFile> GetUnmappedFiles()
|
|||
|
||||
public void DeleteFilesByBook(int bookId)
|
||||
{
|
||||
Delete(x => x.EditionId == bookId);
|
||||
var fileIds = GetFilesByBook(bookId).Select(x => x.Id).ToList();
|
||||
Delete(x => fileIds.Contains(x.Id));
|
||||
}
|
||||
|
||||
public void UnlinkFilesByBook(int bookId)
|
||||
{
|
||||
var files = Query(x => x.EditionId == bookId);
|
||||
var files = GetFilesByBook(bookId);
|
||||
files.ForEach(x => x.EditionId = 0);
|
||||
SetFields(files, f => f.EditionId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ private string GetMessage(Author author, List<Book> books, QualityModel quality)
|
|||
|
||||
private string GetBookDownloadMessage(Author author, Book book, List<BookFile> tracks)
|
||||
{
|
||||
return string.Format("{0} - {1} ({2} Tracks Imported)",
|
||||
return string.Format("{0} - {1} ({2} Files Imported)",
|
||||
author.Name,
|
||||
book.Title,
|
||||
tracks.Count);
|
||||
|
|
@ -59,7 +59,7 @@ private string GetBookDownloadMessage(Author author, Book book, List<BookFile> t
|
|||
|
||||
private string GetBookIncompleteImportMessage(string source)
|
||||
{
|
||||
return string.Format("Readarr failed to Import all tracks for {0}",
|
||||
return string.Format("Readarr failed to Import all files for {0}",
|
||||
source);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue