diff --git a/anki/cards.py b/anki/cards.py index ee9f7b8c1..5d8e2fb18 100644 --- a/anki/cards.py +++ b/anki/cards.py @@ -4,19 +4,10 @@ import pprint import time +from anki.hooks import runHook from anki.utils import intTime, timestampID, joinFields from anki.consts import * -# temporary -_warned = False -def warn(): - global _warned - if _warned: - return - import sys - sys.stderr.write("Ignore the above, please download the fix assertion addon.") - _warned = True - # Cards ########################################################################## @@ -83,7 +74,7 @@ class Card(object): self.usn = self.col.usn() # bug check if self.queue == 2 and self.odue and not self.col.decks.isDyn(self.did): - warn() + runHook("odueInvalid") assert self.due < 4294967296 self.col.db.execute( """ @@ -114,7 +105,7 @@ insert or replace into cards values self.usn = self.col.usn() # bug checks if self.queue == 2 and self.odue and not self.col.decks.isDyn(self.did): - warn() + runHook("odueInvalid") assert self.due < 4294967296 self.col.db.execute( """update cards set diff --git a/anki/collection.py b/anki/collection.py index 706c0ff78..fba9d5899 100644 --- a/anki/collection.py +++ b/anki/collection.py @@ -741,6 +741,16 @@ select id from cards where nid not in (select id from notes)""") ngettext("Deleted %d card with missing note.", "Deleted %d cards with missing note.", cnt) % cnt) self.remCards(ids) + # cards with odue set when it shouldn't be + ids = self.db.list(""" +select id from cards where odue > 0 and (type=1 or queue=2) and not odid""") + if ids: + cnt = len(ids) + problems.append( + ngettext("Fixed %d card with invalid properties.", + "Fixed %d cards with invalid properties.", cnt) % cnt) + self.db.execute("update cards set odue=0 where id in "+ + ids2str(ids)) # tags self.tags.registerNotes() # field cache diff --git a/anki/sched.py b/anki/sched.py index 2f52e557e..189dd1582 100644 --- a/anki/sched.py +++ b/anki/sched.py @@ -1334,7 +1334,7 @@ and (queue=0 or (queue=2 and due<=?))""", def forgetCards(self, ids): "Put cards at the end of the new queue." self.col.db.execute( - "update cards set type=0,queue=0,ivl=0,due=0,factor=? where odid=0 " + "update cards set type=0,queue=0,ivl=0,due=0,odue=0,factor=? where odid=0 " "and queue >= 0 and id in "+ids2str(ids), 2500) pmax = self.col.db.scalar( "select max(due) from cards where type=0") or 0 diff --git a/aqt/main.py b/aqt/main.py index 395346e72..63fee896f 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -863,6 +863,12 @@ Difference to correct time: %s.""") % diffText def setupHooks(self): addHook("modSchema", self.onSchemaMod) addHook("remNotes", self.onRemNotes) + addHook("odueInvalid", self.onOdueInvalid) + + def onOdueInvalid(self): + showWarning(_("""\ +Invalid property found on card. Please use Tools>Check Database, \ +and if the problem comes up again, please ask on the support site.""")) # Log note deletion ##########################################################################