allow importing scheduling-inclusive v1 imports into v2

This commit is contained in:
Damien Elmes 2019-12-06 19:03:57 +10:00
parent 15a9a6005e
commit 9d6523e4dc

View file

@ -31,17 +31,15 @@ class Anki2Importer(Importer):
def _prepareFiles(self): def _prepareFiles(self):
importingV2 = self.file.endswith(".anki21") importingV2 = self.file.endswith(".anki21")
if importingV2 and self.col.schedVer() == 1: self.mustResetLearning = False
raise Exception("V2 scheduler must be enabled to import this file.")
self.dst = self.col self.dst = self.col
self.src = Collection(self.file) self.src = Collection(self.file)
if not importingV2 and self.col.schedVer() != 1: if not importingV2 and self.col.schedVer() != 1:
# if v2 scheduler enabled, can't import v1 decks that include scheduling # any scheduling included?
if self.src.db.scalar("select 1 from cards where queue != 0 limit 1"): if self.src.db.scalar("select 1 from cards where queue != 0 limit 1"):
self.src.close(save=False) self.mustResetLearning = True
raise Exception("V2 scheduler can not import V1 decks with scheduling included.")
def _import(self): def _import(self):
self._decks = {} self._decks = {}
@ -290,6 +288,8 @@ class Anki2Importer(Importer):
###################################################################### ######################################################################
def _importCards(self): def _importCards(self):
if self.mustResetLearning:
self.src.changeSchedulerVer(2)
# build map of (guid, ord) -> cid and used id cache # build map of (guid, ord) -> cid and used id cache
self._cards = {} self._cards = {}
existing = {} existing = {}