mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
allow user to abort schema mod
This commit is contained in:
parent
e339df5ef8
commit
13a484ea36
3 changed files with 10 additions and 5 deletions
11
anki/deck.py
11
anki/deck.py
|
@ -11,6 +11,7 @@ from anki.hooks import runHook, runFilter
|
||||||
from anki.sched import Scheduler
|
from anki.sched import Scheduler
|
||||||
from anki.media import MediaRegistry
|
from anki.media import MediaRegistry
|
||||||
from anki.consts import *
|
from anki.consts import *
|
||||||
|
from anki.errors import AnkiError
|
||||||
|
|
||||||
import anki.latex # sets up hook
|
import anki.latex # sets up hook
|
||||||
import anki.cards, anki.facts, anki.models, anki.template, anki.cram, \
|
import anki.cards, anki.facts, anki.models, anki.template, anki.cram, \
|
||||||
|
@ -158,16 +159,18 @@ qconf=?, conf=?, data=?""",
|
||||||
self.load()
|
self.load()
|
||||||
self.lock()
|
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 not self.schemaChanged():
|
||||||
|
if check and not runFilter("modSchema", True):
|
||||||
|
raise AnkiError("abortSchemaMod")
|
||||||
# next sync will be full
|
# next sync will be full
|
||||||
self.emptyTrash()
|
self.emptyTrash()
|
||||||
runHook("modSchema")
|
|
||||||
self.scm = intTime()
|
self.scm = intTime()
|
||||||
|
|
||||||
def schemaChanged(self):
|
def schemaChanged(self):
|
||||||
"True if schema changed since last sync, or syncing off."
|
"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):
|
def setDirty(self):
|
||||||
self.dty = True
|
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):
|
def fixIntegrity(self):
|
||||||
"Fix possible problems and rebuild caches."
|
"Fix possible problems and rebuild caches."
|
||||||
|
self.modSchema(check=False)
|
||||||
problems = []
|
problems = []
|
||||||
self.save()
|
self.save()
|
||||||
oldSize = os.stat(self.path)[stat.ST_SIZE]
|
oldSize = os.stat(self.path)[stat.ST_SIZE]
|
||||||
self.modSchema()
|
|
||||||
# tags
|
# tags
|
||||||
self.db.execute("delete from tags")
|
self.db.execute("delete from tags")
|
||||||
self.updateFactTags()
|
self.updateFactTags()
|
||||||
|
|
|
@ -154,8 +154,8 @@ insert or replace into models values (?, ?, ?, ?, ?, ?, ?)""",
|
||||||
|
|
||||||
def setSortIdx(self, idx):
|
def setSortIdx(self, idx):
|
||||||
assert idx >= 0 and idx < len(self.fields)
|
assert idx >= 0 and idx < len(self.fields)
|
||||||
self.conf['sortf'] = idx
|
|
||||||
self.deck.modSchema()
|
self.deck.modSchema()
|
||||||
|
self.conf['sortf'] = idx
|
||||||
self.deck.updateFieldCache(self.fids(), csum=False)
|
self.deck.updateFieldCache(self.fids(), csum=False)
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,8 @@ def test_delete():
|
||||||
assert deck.cardCount() == 1
|
assert deck.cardCount() == 1
|
||||||
# mark the schema as clean
|
# mark the schema as clean
|
||||||
deck.lastSync = deck.scm + 1
|
deck.lastSync = deck.scm + 1
|
||||||
|
# and deck as syncable
|
||||||
|
deck.syncName = "abc"
|
||||||
# cards/facts should go in the deletion log instead
|
# cards/facts should go in the deletion log instead
|
||||||
cid = f.cards()[0].id
|
cid = f.cards()[0].id
|
||||||
deck.delCard(cid)
|
deck.delCard(cid)
|
||||||
|
|
Loading…
Reference in a new issue