diff --git a/anki/deck.py b/anki/deck.py index 90991afac..3ce58f4d9 100644 --- a/anki/deck.py +++ b/anki/deck.py @@ -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() diff --git a/anki/models.py b/anki/models.py index 6b675a5b3..39d06f9be 100644 --- a/anki/models.py +++ b/anki/models.py @@ -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() diff --git a/tests/test_cards.py b/tests/test_cards.py index 730473353..54f9a2c5c 100644 --- a/tests/test_cards.py +++ b/tests/test_cards.py @@ -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)