allow user to abort schema mod

This commit is contained in:
Damien Elmes 2011-04-11 21:14:22 +09:00
parent e339df5ef8
commit 13a484ea36
3 changed files with 10 additions and 5 deletions

View file

@ -11,6 +11,7 @@ from anki.hooks import runHook, runFilter
from anki.sched import Scheduler
from anki.media import MediaRegistry
from anki.consts import *
from anki.errors import AnkiError
import anki.latex # sets up hook
import anki.cards, anki.facts, anki.models, anki.template, anki.cram, \
@ -158,16 +159,18 @@ qconf=?, conf=?, data=?""",
self.load()
self.lock()
def modSchema(self):
def modSchema(self, check=True):
"Mark schema modified. Call this first so user can abort if necessary."
if not self.schemaChanged():
if check and not runFilter("modSchema", True):
raise AnkiError("abortSchemaMod")
# next sync will be full
self.emptyTrash()
runHook("modSchema")
self.scm = intTime()
def schemaChanged(self):
"True if schema changed since last sync, or syncing off."
return self.scm > self.lastSync
return not self.syncingEnabled() or self.scm > self.lastSync
def setDirty(self):
self.dty = True
@ -776,10 +779,10 @@ update facts set tags = :t, mod = :n where id = :id""", [fix(row) for row in res
def fixIntegrity(self):
"Fix possible problems and rebuild caches."
self.modSchema(check=False)
problems = []
self.save()
oldSize = os.stat(self.path)[stat.ST_SIZE]
self.modSchema()
# tags
self.db.execute("delete from tags")
self.updateFactTags()

View file

@ -154,8 +154,8 @@ insert or replace into models values (?, ?, ?, ?, ?, ?, ?)""",
def setSortIdx(self, idx):
assert idx >= 0 and idx < len(self.fields)
self.conf['sortf'] = idx
self.deck.modSchema()
self.conf['sortf'] = idx
self.deck.updateFieldCache(self.fids(), csum=False)
self.flush()

View file

@ -69,6 +69,8 @@ def test_delete():
assert deck.cardCount() == 1
# mark the schema as clean
deck.lastSync = deck.scm + 1
# and deck as syncable
deck.syncName = "abc"
# cards/facts should go in the deletion log instead
cid = f.cards()[0].id
deck.delCard(cid)