make sure we reset odue when rescheduling as new

if we fail to do this for a relearning card, it sticks around
until it causes problems later
This commit is contained in:
Damien Elmes 2013-11-17 16:03:58 +09:00
parent 4bf63b6ad0
commit ae8074ec01
4 changed files with 20 additions and 13 deletions

View file

@ -4,19 +4,10 @@
import pprint import pprint
import time import time
from anki.hooks import runHook
from anki.utils import intTime, timestampID, joinFields from anki.utils import intTime, timestampID, joinFields
from anki.consts import * 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 # Cards
########################################################################## ##########################################################################
@ -83,7 +74,7 @@ class Card(object):
self.usn = self.col.usn() self.usn = self.col.usn()
# bug check # bug check
if self.queue == 2 and self.odue and not self.col.decks.isDyn(self.did): if self.queue == 2 and self.odue and not self.col.decks.isDyn(self.did):
warn() runHook("odueInvalid")
assert self.due < 4294967296 assert self.due < 4294967296
self.col.db.execute( self.col.db.execute(
""" """
@ -114,7 +105,7 @@ insert or replace into cards values
self.usn = self.col.usn() self.usn = self.col.usn()
# bug checks # bug checks
if self.queue == 2 and self.odue and not self.col.decks.isDyn(self.did): if self.queue == 2 and self.odue and not self.col.decks.isDyn(self.did):
warn() runHook("odueInvalid")
assert self.due < 4294967296 assert self.due < 4294967296
self.col.db.execute( self.col.db.execute(
"""update cards set """update cards set

View file

@ -741,6 +741,16 @@ select id from cards where nid not in (select id from notes)""")
ngettext("Deleted %d card with missing note.", ngettext("Deleted %d card with missing note.",
"Deleted %d cards with missing note.", cnt) % cnt) "Deleted %d cards with missing note.", cnt) % cnt)
self.remCards(ids) 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 # tags
self.tags.registerNotes() self.tags.registerNotes()
# field cache # field cache

View file

@ -1334,7 +1334,7 @@ and (queue=0 or (queue=2 and due<=?))""",
def forgetCards(self, ids): def forgetCards(self, ids):
"Put cards at the end of the new queue." "Put cards at the end of the new queue."
self.col.db.execute( 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) "and queue >= 0 and id in "+ids2str(ids), 2500)
pmax = self.col.db.scalar( pmax = self.col.db.scalar(
"select max(due) from cards where type=0") or 0 "select max(due) from cards where type=0") or 0

View file

@ -863,6 +863,12 @@ Difference to correct time: %s.""") % diffText
def setupHooks(self): def setupHooks(self):
addHook("modSchema", self.onSchemaMod) addHook("modSchema", self.onSchemaMod)
addHook("remNotes", self.onRemNotes) 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 # Log note deletion
########################################################################## ##########################################################################