Fix #1455746 [FileTypePlugin receives old database API object](https://bugs.launchpad.net/calibre/+bug/1455746)

This commit is contained in:
Kovid Goyal 2015-05-17 09:45:08 +05:30
parent 036fa88a5a
commit 191d204412
2 changed files with 6 additions and 6 deletions

View File

@ -113,7 +113,7 @@ def recursive_import(db, root, single_book_per_directory=True,
break
return duplicates
def add_catalog(cache, path, title):
def add_catalog(cache, path, title, dbapi=None):
from calibre.ebooks.metadata.book.base import Metadata
from calibre.ebooks.metadata.meta import get_metadata
from calibre.utils.date import utcnow
@ -142,11 +142,11 @@ def add_catalog(cache, path, title):
new_book_added = True
else:
cache._set_metadata(db_id, mi)
cache.add_format(db_id, fmt, stream) # Cant keep write lock since post-import hooks might run
cache.add_format(db_id, fmt, stream, dbapi=dbapi) # Cant keep write lock since post-import hooks might run
return db_id, new_book_added
def add_news(cache, path, arg):
def add_news(cache, path, arg, dbapi=None):
from calibre.ebooks.metadata.meta import get_metadata
from calibre.utils.date import utcnow
@ -173,7 +173,7 @@ def add_news(cache, path, arg):
mi.timestamp = utcnow()
db_id = cache._create_book_entry(mi, apply_import_tags=False)
cache.add_format(db_id, fmt, stream) # Cant keep write lock since post-import hooks might run
cache.add_format(db_id, fmt, stream, dbapi=dbapi) # Cant keep write lock since post-import hooks might run
if not hasattr(path, 'read'):
stream.close()

View File

@ -259,13 +259,13 @@ class LibraryDatabase(object):
return recursive_import(self, root, single_book_per_directory=single_book_per_directory, callback=callback, added_ids=added_ids)
def add_catalog(self, path, title):
book_id, new_book_added = add_catalog(self.new_api, path, title)
book_id, new_book_added = add_catalog(self.new_api, path, title, dbapi=self)
if book_id is not None and new_book_added:
self.data.books_added((book_id,))
return book_id
def add_news(self, path, arg):
book_id = add_news(self.new_api, path, arg)
book_id = add_news(self.new_api, path, arg, dbapi=self)
if book_id is not None:
self.data.books_added((book_id,))
return book_id