mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
be explicit about modSchema()'s check flag
- remove gui code that adds exceptions for syncing - use check=False for all syncing and upgrade code
This commit is contained in:
parent
519bf5fec7
commit
6e7e08ebd0
7 changed files with 19 additions and 30 deletions
|
@ -171,7 +171,7 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
|
||||||
self.load()
|
self.load()
|
||||||
self.lock()
|
self.lock()
|
||||||
|
|
||||||
def modSchema(self, check=True):
|
def modSchema(self, check):
|
||||||
"Mark schema modified. Call this first so user can abort if necessary."
|
"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):
|
if check and not runFilter("modSchema", True):
|
||||||
|
@ -197,7 +197,7 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
|
||||||
self.models.beforeUpload()
|
self.models.beforeUpload()
|
||||||
self.tags.beforeUpload()
|
self.tags.beforeUpload()
|
||||||
self.decks.beforeUpload()
|
self.decks.beforeUpload()
|
||||||
self.modSchema()
|
self.modSchema(check=False)
|
||||||
self.ls = self.scm
|
self.ls = self.scm
|
||||||
# ensure db is compacted before upload
|
# ensure db is compacted before upload
|
||||||
self.db.execute("vacuum")
|
self.db.execute("vacuum")
|
||||||
|
|
|
@ -344,7 +344,7 @@ class DeckManager(object):
|
||||||
def remConf(self, id):
|
def remConf(self, id):
|
||||||
"Remove a configuration and update all decks using it."
|
"Remove a configuration and update all decks using it."
|
||||||
assert int(id) != 1
|
assert int(id) != 1
|
||||||
self.col.modSchema()
|
self.col.modSchema(check=True)
|
||||||
del self.dconf[str(id)]
|
del self.dconf[str(id)]
|
||||||
for g in self.all():
|
for g in self.all():
|
||||||
# ignore cram decks
|
# ignore cram decks
|
||||||
|
|
|
@ -147,7 +147,7 @@ class ModelManager(object):
|
||||||
|
|
||||||
def rem(self, m):
|
def rem(self, m):
|
||||||
"Delete model, and all its cards/notes."
|
"Delete model, and all its cards/notes."
|
||||||
self.col.modSchema()
|
self.col.modSchema(check=True)
|
||||||
current = self.current()['id'] == m['id']
|
current = self.current()['id'] == m['id']
|
||||||
# delete notes/cards
|
# delete notes/cards
|
||||||
self.col.remCards(self.col.db.list("""
|
self.col.remCards(self.col.db.list("""
|
||||||
|
@ -241,7 +241,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
|
|
||||||
def setSortIdx(self, m, idx):
|
def setSortIdx(self, m, idx):
|
||||||
assert idx >= 0 and idx < len(m['flds'])
|
assert idx >= 0 and idx < len(m['flds'])
|
||||||
self.col.modSchema()
|
self.col.modSchema(check=True)
|
||||||
m['sortf'] = idx
|
m['sortf'] = idx
|
||||||
self.col.updateFieldCache(self.nids(m))
|
self.col.updateFieldCache(self.nids(m))
|
||||||
self.save(m)
|
self.save(m)
|
||||||
|
@ -249,7 +249,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
def addField(self, m, field):
|
def addField(self, m, field):
|
||||||
# only mod schema if model isn't new
|
# only mod schema if model isn't new
|
||||||
if m['id']:
|
if m['id']:
|
||||||
self.col.modSchema()
|
self.col.modSchema(check=True)
|
||||||
m['flds'].append(field)
|
m['flds'].append(field)
|
||||||
self._updateFieldOrds(m)
|
self._updateFieldOrds(m)
|
||||||
self.save(m)
|
self.save(m)
|
||||||
|
@ -259,7 +259,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
self._transformFields(m, add)
|
self._transformFields(m, add)
|
||||||
|
|
||||||
def remField(self, m, field):
|
def remField(self, m, field):
|
||||||
self.col.modSchema()
|
self.col.modSchema(check=True)
|
||||||
# save old sort field
|
# save old sort field
|
||||||
sortFldName = m['flds'][m['sortf']]['name']
|
sortFldName = m['flds'][m['sortf']]['name']
|
||||||
idx = m['flds'].index(field)
|
idx = m['flds'].index(field)
|
||||||
|
@ -282,7 +282,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
self.renameField(m, field, None)
|
self.renameField(m, field, None)
|
||||||
|
|
||||||
def moveField(self, m, field, idx):
|
def moveField(self, m, field, idx):
|
||||||
self.col.modSchema()
|
self.col.modSchema(check=True)
|
||||||
oldidx = m['flds'].index(field)
|
oldidx = m['flds'].index(field)
|
||||||
if oldidx == idx:
|
if oldidx == idx:
|
||||||
return
|
return
|
||||||
|
@ -303,7 +303,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
self._transformFields(m, move)
|
self._transformFields(m, move)
|
||||||
|
|
||||||
def renameField(self, m, field, newName):
|
def renameField(self, m, field, newName):
|
||||||
self.col.modSchema()
|
self.col.modSchema(check=True)
|
||||||
pat = r'{{(.*)([:#^/]|[^:#/^}][^:}]*?:|)%s}}'
|
pat = r'{{(.*)([:#^/]|[^:#/^}][^:}]*?:|)%s}}'
|
||||||
def wrap(txt):
|
def wrap(txt):
|
||||||
def repl(match):
|
def repl(match):
|
||||||
|
@ -347,7 +347,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
def addTemplate(self, m, template):
|
def addTemplate(self, m, template):
|
||||||
"Note: should col.genCards() afterwards."
|
"Note: should col.genCards() afterwards."
|
||||||
if m['id']:
|
if m['id']:
|
||||||
self.col.modSchema()
|
self.col.modSchema(check=True)
|
||||||
m['tmpls'].append(template)
|
m['tmpls'].append(template)
|
||||||
self._updateTemplOrds(m)
|
self._updateTemplOrds(m)
|
||||||
self.save(m)
|
self.save(m)
|
||||||
|
@ -370,7 +370,7 @@ having count() < 2
|
||||||
limit 1""" % ids2str(cids)):
|
limit 1""" % ids2str(cids)):
|
||||||
return False
|
return False
|
||||||
# ok to proceed; remove cards
|
# ok to proceed; remove cards
|
||||||
self.col.modSchema()
|
self.col.modSchema(check=True)
|
||||||
self.col.remCards(cids)
|
self.col.remCards(cids)
|
||||||
# shift ordinals
|
# shift ordinals
|
||||||
self.col.db.execute("""
|
self.col.db.execute("""
|
||||||
|
@ -414,7 +414,7 @@ select id from notes where mid = ?)""" % " ".join(map),
|
||||||
# - newModel should be self if model is not changing
|
# - newModel should be self if model is not changing
|
||||||
|
|
||||||
def change(self, m, nids, newModel, fmap, cmap):
|
def change(self, m, nids, newModel, fmap, cmap):
|
||||||
self.col.modSchema()
|
self.col.modSchema(check=True)
|
||||||
assert newModel['id'] == m['id'] or (fmap and cmap)
|
assert newModel['id'] == m['id'] or (fmap and cmap)
|
||||||
if fmap:
|
if fmap:
|
||||||
self._changeNotes(nids, newModel, fmap)
|
self._changeNotes(nids, newModel, fmap)
|
||||||
|
|
|
@ -88,7 +88,7 @@ def _upgrade(col, ver):
|
||||||
d['collapsed'] = False
|
d['collapsed'] = False
|
||||||
col.decks.save(d)
|
col.decks.save(d)
|
||||||
if ver < 4:
|
if ver < 4:
|
||||||
col.modSchema()
|
col.modSchema(check=False)
|
||||||
clozes = []
|
clozes = []
|
||||||
for m in col.models.all():
|
for m in col.models.all():
|
||||||
if not "{{cloze:" in m['tmpls'][0]['qfmt']:
|
if not "{{cloze:" in m['tmpls'][0]['qfmt']:
|
||||||
|
@ -103,7 +103,7 @@ def _upgrade(col, ver):
|
||||||
col.db.execute("update cards set odue = 0 where queue = 2")
|
col.db.execute("update cards set odue = 0 where queue = 2")
|
||||||
col.db.execute("update col set ver = 5")
|
col.db.execute("update col set ver = 5")
|
||||||
if ver < 6:
|
if ver < 6:
|
||||||
col.modSchema()
|
col.modSchema(check=False)
|
||||||
import anki.models
|
import anki.models
|
||||||
for m in col.models.all():
|
for m in col.models.all():
|
||||||
m['css'] = anki.models.defaultModel['css']
|
m['css'] = anki.models.defaultModel['css']
|
||||||
|
@ -117,13 +117,13 @@ def _upgrade(col, ver):
|
||||||
col.models.save(m)
|
col.models.save(m)
|
||||||
col.db.execute("update col set ver = 6")
|
col.db.execute("update col set ver = 6")
|
||||||
if ver < 7:
|
if ver < 7:
|
||||||
col.modSchema()
|
col.modSchema(check=False)
|
||||||
col.db.execute(
|
col.db.execute(
|
||||||
"update cards set odue = 0 where (type = 1 or queue = 2) "
|
"update cards set odue = 0 where (type = 1 or queue = 2) "
|
||||||
"and not odid")
|
"and not odid")
|
||||||
col.db.execute("update col set ver = 7")
|
col.db.execute("update col set ver = 7")
|
||||||
if ver < 8:
|
if ver < 8:
|
||||||
col.modSchema()
|
col.modSchema(check=False)
|
||||||
col.db.execute(
|
col.db.execute(
|
||||||
"update cards set due = due / 1000 where due > 4294967296")
|
"update cards set due = due / 1000 where due > 4294967296")
|
||||||
col.db.execute("update col set ver = 8")
|
col.db.execute("update col set ver = 8")
|
||||||
|
@ -149,7 +149,7 @@ def _upgrade(col, ver):
|
||||||
update cards set left = left + left*1000 where queue = 1""")
|
update cards set left = left + left*1000 where queue = 1""")
|
||||||
col.db.execute("update col set ver = 10")
|
col.db.execute("update col set ver = 10")
|
||||||
if ver < 11:
|
if ver < 11:
|
||||||
col.modSchema()
|
col.modSchema(check=False)
|
||||||
for d in col.decks.all():
|
for d in col.decks.all():
|
||||||
if d['dyn']:
|
if d['dyn']:
|
||||||
order = d['order']
|
order = d['order']
|
||||||
|
|
|
@ -183,7 +183,7 @@ class Syncer(object):
|
||||||
if ret['status'] != "ok":
|
if ret['status'] != "ok":
|
||||||
# roll back and force full sync
|
# roll back and force full sync
|
||||||
self.col.rollback()
|
self.col.rollback()
|
||||||
self.col.modSchema()
|
self.col.modSchema(False)
|
||||||
self.col.save()
|
self.col.save()
|
||||||
return "sanityCheckFailed"
|
return "sanityCheckFailed"
|
||||||
# finalize
|
# finalize
|
||||||
|
|
|
@ -69,7 +69,6 @@ class AnkiQt(QMainWindow):
|
||||||
|
|
||||||
def setupUI(self):
|
def setupUI(self):
|
||||||
self.col = None
|
self.col = None
|
||||||
self.hideSchemaMsg = False
|
|
||||||
self.setupAppMsg()
|
self.setupAppMsg()
|
||||||
self.setupKeys()
|
self.setupKeys()
|
||||||
self.setupThreads()
|
self.setupThreads()
|
||||||
|
@ -265,7 +264,6 @@ To import into a password protected profile, please open the profile before atte
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def loadCollection(self):
|
def loadCollection(self):
|
||||||
self.hideSchemaMsg = True
|
|
||||||
cpath = self.pm.collectionPath()
|
cpath = self.pm.collectionPath()
|
||||||
try:
|
try:
|
||||||
self.col = Collection(cpath, log=True)
|
self.col = Collection(cpath, log=True)
|
||||||
|
@ -287,7 +285,6 @@ Debug info:
|
||||||
return
|
return
|
||||||
self.unloadProfile()
|
self.unloadProfile()
|
||||||
raise
|
raise
|
||||||
self.hideSchemaMsg = False
|
|
||||||
self.progress.setupDB(self.col.db)
|
self.progress.setupDB(self.col.db)
|
||||||
self.maybeEnableUndo()
|
self.maybeEnableUndo()
|
||||||
self.moveToState("deckBrowser")
|
self.moveToState("deckBrowser")
|
||||||
|
@ -903,12 +900,6 @@ and if the problem comes up again, please ask on the support site."""))
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def onSchemaMod(self, arg):
|
def onSchemaMod(self, arg):
|
||||||
# if triggered in sync, make sure we don't use the gui
|
|
||||||
if not self.inMainThread():
|
|
||||||
return True
|
|
||||||
# if from the full sync menu, ignore
|
|
||||||
if self.hideSchemaMsg:
|
|
||||||
return True
|
|
||||||
return askUser(_("""\
|
return askUser(_("""\
|
||||||
The requested change will require a full upload of the database when \
|
The requested change will require a full upload of the database when \
|
||||||
you next synchronize your collection. If you have reviews or other changes \
|
you next synchronize your collection. If you have reviews or other changes \
|
||||||
|
|
|
@ -105,10 +105,8 @@ Not currently enabled; click the sync button in the main window to enable."""))
|
||||||
self.prof['autoSync'] = self.form.syncOnProgramOpen.isChecked()
|
self.prof['autoSync'] = self.form.syncOnProgramOpen.isChecked()
|
||||||
self.prof['syncMedia'] = self.form.syncMedia.isChecked()
|
self.prof['syncMedia'] = self.form.syncMedia.isChecked()
|
||||||
if self.form.fullSync.isChecked():
|
if self.form.fullSync.isChecked():
|
||||||
self.mw.hideSchemaMsg = True
|
self.mw.col.modSchema(check=False)
|
||||||
self.mw.col.modSchema()
|
|
||||||
self.mw.col.setMod()
|
self.mw.col.setMod()
|
||||||
self.mw.hideSchemaMsg = False
|
|
||||||
|
|
||||||
# Backup
|
# Backup
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
Loading…
Reference in a new issue