Fixed: Prevent books being added with AuthorMetadataId 0

(cherry picked from commit 0c227d0f21e3803c6293fd5988e48ea010483cad)
pull/1147/head
ta264 3 years ago
parent 1571ef4172
commit 59c1bf0b1f

@ -63,6 +63,11 @@ namespace NzbDrone.Core.Books
public Book AddBook(Book newBook, bool doRefresh = true)
{
if (newBook.AuthorMetadataId == 0)
{
throw new InvalidOperationException("Cannot insert book with AuthorMetadataId = 0");
}
_bookRepository.Upsert(newBook);
var editions = newBook.Editions.Value;
@ -244,6 +249,11 @@ namespace NzbDrone.Core.Books
public void InsertMany(List<Book> books)
{
if (books.Any(x => x.AuthorMetadataId == 0))
{
throw new InvalidOperationException("Cannot insert book with AuthorMetadataId = 0");
}
_bookRepository.InsertMany(books);
}

@ -374,6 +374,12 @@ namespace NzbDrone.Core.MediaFiles.BookImport
if (dbBook == null)
{
_logger.Debug($"Adding remote book {book}");
if (book.AuthorMetadataId == 0)
{
throw new InvalidOperationException("Cannot insert book with AuthorMetadataId = 0");
}
try
{
book.Added = DateTime.UtcNow;

@ -747,6 +747,7 @@ namespace NzbDrone.Core.MetadataSource.Goodreads
book.Author = author;
book.AuthorMetadata = book.Author.Value.Metadata.Value;
book.AuthorMetadataId = author.AuthorMetadataId;
book.CleanTitle = book.Title.CleanAuthorName();
}
@ -833,6 +834,7 @@ namespace NzbDrone.Core.MetadataSource.Goodreads
book.Author = author;
book.AuthorMetadata = book.Author.Value.Metadata.Value;
book.AuthorMetadataId = author.AuthorMetadataId;
book.CleanTitle = book.Title.CleanAuthorName();
book.SeriesLinks = MapSearchSeries(resource.Title, resource.BookTitleBare);

Loading…
Cancel
Save