From 612c279dfdc67e17da6d927d4ce6943b0cdb58ae Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 7 Sep 2015 10:37:32 +0530 Subject: [PATCH] Copy to Library: Fix author sort/link values not being copied when copying a book with an author not present in the destination library. Fixes #1492685 [Preserve Author fields in Copy or Move to library](https://bugs.launchpad.net/calibre/+bug/1492685) --- src/calibre/gui2/actions/copy_to_library.py | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/actions/copy_to_library.py b/src/calibre/gui2/actions/copy_to_library.py index ef2a745c0f..012f4773b5 100644 --- a/src/calibre/gui2/actions/copy_to_library.py +++ b/src/calibre/gui2/actions/copy_to_library.py @@ -166,9 +166,30 @@ class Worker(Thread): # {{{ self.duplicate_ids[x] = (mi.title, mi.authors) continue + new_authors = {k for k, v in newdb.new_api.get_item_ids('authors', mi.authors).iteritems() if v is None} new_book_id = newdb.import_book(mi, paths, notify=False, import_hooks=False, apply_import_tags=tweaks['add_new_book_tags_when_importing_books'], preserve_uuid=self.delete_after) + if new_authors: + author_id_map = self.db.new_api.get_item_ids('authors', new_authors) + sort_map, link_map = {}, {} + for author, aid in author_id_map.iteritems(): + if aid is not None: + adata = self.db.new_api.author_data((aid,)).get(aid) + if adata is not None: + aid = newdb.new_api.get_item_id('authors', author) + if aid is not None: + asv = adata.get('sort') + if asv: + sort_map[aid] = asv + alv = adata.get('link') + if alv: + link_map[aid] = alv + if sort_map: + newdb.new_api.set_sort_for_authors(sort_map, update_books=False) + if link_map: + newdb.new_api.set_link_for_authors(link_map) + co = self.db.conversion_options(x, 'PIPE') if co is not None: newdb.set_conversion_options(new_book_id, 'PIPE', co) @@ -490,5 +511,3 @@ class CopyToLibraryAction(InterfaceAction): warning_dialog(self.gui, _('Not allowed'), _('You cannot use other libraries while using the environment' ' variable CALIBRE_OVERRIDE_DATABASE_PATH.'), show=True) - -