mirror of
https://github.com/Readarr/Readarr
synced 2026-01-05 07:03:13 +01:00
Fixed: Ensure correct book edition is in the database before importing book
This commit is contained in:
parent
8bc44f2a29
commit
6a61702a91
1 changed files with 51 additions and 0 deletions
|
|
@ -109,6 +109,14 @@ public List<ImportResult> Import(List<ImportDecision<LocalBook>> decisions, bool
|
|||
continue;
|
||||
}
|
||||
|
||||
var edition = EnsureEditionAdded(decisionList);
|
||||
|
||||
if (edition == null)
|
||||
{
|
||||
// failed to add the edition, carry on with next one
|
||||
continue;
|
||||
}
|
||||
|
||||
// if (replaceExisting)
|
||||
// {
|
||||
// RemoveExistingTrackFiles(author, book);
|
||||
|
|
@ -394,11 +402,54 @@ private Book EnsureBookAdded(List<ImportDecision<LocalBook>> decisions)
|
|||
decision.Item.Book = dbBook;
|
||||
decision.Item.Edition = edition;
|
||||
}
|
||||
|
||||
book = dbBook;
|
||||
}
|
||||
|
||||
return book;
|
||||
}
|
||||
|
||||
private Edition EnsureEditionAdded(List<ImportDecision<LocalBook>> decisions)
|
||||
{
|
||||
var book = decisions.First().Item.Book;
|
||||
var edition = decisions.First().Item.Edition;
|
||||
|
||||
if (edition.Id == 0)
|
||||
{
|
||||
var dbEdition = _editionService.GetEditionByForeignEditionId(edition.ForeignEditionId);
|
||||
|
||||
if (dbEdition == null)
|
||||
{
|
||||
_logger.Debug($"Adding remote edition {edition}");
|
||||
try
|
||||
{
|
||||
edition.BookId = book.Id;
|
||||
edition.Monitored = false;
|
||||
_editionService.InsertMany(new List<Edition> { edition });
|
||||
|
||||
dbEdition = _editionService.GetEditionByForeignEditionId(edition.ForeignEditionId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(e, "Failed to add edition {0}", edition);
|
||||
RejectBook(decisions);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Populate the new DB book
|
||||
foreach (var decision in decisions)
|
||||
{
|
||||
decision.Item.Edition = dbEdition;
|
||||
}
|
||||
|
||||
edition = dbEdition;
|
||||
}
|
||||
}
|
||||
|
||||
return edition;
|
||||
}
|
||||
|
||||
private void RejectBook(List<ImportDecision<LocalBook>> decisions)
|
||||
{
|
||||
foreach (var decision in decisions)
|
||||
|
|
|
|||
Loading…
Reference in a new issue