generate extra templates when recovering notetype
This commit is contained in:
parent
e6e9cb348e
commit
9334272a27
@ -40,6 +40,8 @@ database-check-revlog-properties =
|
|||||||
[one] Fixed { $count } review entry with invalid properties.
|
[one] Fixed { $count } review entry with invalid properties.
|
||||||
*[other] Fixed { $count } review entries with invalid properties.
|
*[other] Fixed { $count } review entries with invalid properties.
|
||||||
}
|
}
|
||||||
|
# "db-check" is always in English
|
||||||
|
database-check-notetypes-recovered = One or more notetypes were missing. The notes that used them have been given new notetypes starting with "db-check", but field names and card design have been lost, so you may be better off restoring from an automatic backup.
|
||||||
|
|
||||||
## Progress info
|
## Progress info
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@ use crate::{
|
|||||||
err::{AnkiError, DBErrorKind, Result},
|
err::{AnkiError, DBErrorKind, Result},
|
||||||
i18n::{tr_args, I18n, TR},
|
i18n::{tr_args, I18n, TR},
|
||||||
notetype::{
|
notetype::{
|
||||||
all_stock_notetypes, AlreadyGeneratedCardInfo, CardGenContext, NoteType, NoteTypeKind,
|
all_stock_notetypes, AlreadyGeneratedCardInfo, CardGenContext, NoteType, NoteTypeID,
|
||||||
|
NoteTypeKind,
|
||||||
},
|
},
|
||||||
timestamp::{TimestampMillis, TimestampSecs},
|
timestamp::{TimestampMillis, TimestampSecs},
|
||||||
};
|
};
|
||||||
@ -27,6 +28,7 @@ pub struct CheckDatabaseOutput {
|
|||||||
templates_missing: usize,
|
templates_missing: usize,
|
||||||
card_ords_duplicated: usize,
|
card_ords_duplicated: usize,
|
||||||
field_count_mismatch: usize,
|
field_count_mismatch: usize,
|
||||||
|
notetypes_recovered: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
@ -42,6 +44,13 @@ impl CheckDatabaseOutput {
|
|||||||
pub fn to_i18n_strings(&self, i18n: &I18n) -> Vec<String> {
|
pub fn to_i18n_strings(&self, i18n: &I18n) -> Vec<String> {
|
||||||
let mut probs = Vec::new();
|
let mut probs = Vec::new();
|
||||||
|
|
||||||
|
if self.notetypes_recovered > 0 {
|
||||||
|
probs.push(i18n.trn(
|
||||||
|
TR::DatabaseCheckNotetypesRecovered,
|
||||||
|
tr_args!["count"=>self.revlog_properties_invalid],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
if self.card_position_too_high > 0 {
|
if self.card_position_too_high > 0 {
|
||||||
probs.push(i18n.trn(
|
probs.push(i18n.trn(
|
||||||
TR::DatabaseCheckNewCardHighDue,
|
TR::DatabaseCheckNewCardHighDue,
|
||||||
@ -237,7 +246,8 @@ impl Collection {
|
|||||||
let nt = match self.get_notetype(ntid)? {
|
let nt = match self.get_notetype(ntid)? {
|
||||||
None => {
|
None => {
|
||||||
let first_note = self.storage.get_note(group.peek().unwrap().1)?.unwrap();
|
let first_note = self.storage.get_note(group.peek().unwrap().1)?.unwrap();
|
||||||
self.recover_notetype(stamp, first_note.fields.len())?
|
out.notetypes_recovered += 1;
|
||||||
|
self.recover_notetype(stamp, first_note.fields.len(), ntid)?
|
||||||
}
|
}
|
||||||
Some(nt) => nt,
|
Some(nt) => nt,
|
||||||
};
|
};
|
||||||
@ -283,7 +293,10 @@ impl Collection {
|
|||||||
self.add_notetype_inner(&mut nt, usn)?;
|
self.add_notetype_inner(&mut nt, usn)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if out.card_ords_duplicated > 0 || out.field_count_mismatch > 0 || out.templates_missing > 0
|
if out.card_ords_duplicated > 0
|
||||||
|
|| out.field_count_mismatch > 0
|
||||||
|
|| out.templates_missing > 0
|
||||||
|
|| out.notetypes_recovered > 0
|
||||||
{
|
{
|
||||||
self.storage.set_schema_modified()?;
|
self.storage.set_schema_modified()?;
|
||||||
}
|
}
|
||||||
@ -330,8 +343,12 @@ impl Collection {
|
|||||||
&mut self,
|
&mut self,
|
||||||
stamp: TimestampMillis,
|
stamp: TimestampMillis,
|
||||||
field_count: usize,
|
field_count: usize,
|
||||||
|
previous_id: NoteTypeID,
|
||||||
) -> Result<Arc<NoteType>> {
|
) -> Result<Arc<NoteType>> {
|
||||||
debug!(self.log, "create recovery notetype");
|
debug!(self.log, "create recovery notetype");
|
||||||
|
let extra_cards_required = self
|
||||||
|
.storage
|
||||||
|
.highest_card_ordinal_for_notetype(previous_id)?;
|
||||||
let mut basic = all_stock_notetypes(&self.i18n).remove(0);
|
let mut basic = all_stock_notetypes(&self.i18n).remove(0);
|
||||||
let mut field = 3;
|
let mut field = 3;
|
||||||
while basic.fields.len() < field_count {
|
while basic.fields.len() < field_count {
|
||||||
@ -339,6 +356,11 @@ impl Collection {
|
|||||||
field += 1;
|
field += 1;
|
||||||
}
|
}
|
||||||
basic.name = format!("db-check-{}-{}", stamp, field_count);
|
basic.name = format!("db-check-{}-{}", stamp, field_count);
|
||||||
|
let qfmt = basic.templates[0].config.q_format.clone();
|
||||||
|
let afmt = basic.templates[0].config.a_format.clone();
|
||||||
|
for n in 0..extra_cards_required {
|
||||||
|
basic.add_template(&format!("Card {}", n + 2), &qfmt, &afmt);
|
||||||
|
}
|
||||||
self.add_notetype(&mut basic)?;
|
self.add_notetype(&mut basic)?;
|
||||||
Ok(Arc::new(basic))
|
Ok(Arc::new(basic))
|
||||||
}
|
}
|
||||||
|
7
rslib/src/storage/notetype/highest_card_ord.sql
Normal file
7
rslib/src/storage/notetype/highest_card_ord.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
select coalesce(max(ord), 0)
|
||||||
|
from cards
|
||||||
|
where nid in (
|
||||||
|
select id
|
||||||
|
from notes
|
||||||
|
where mid = ?
|
||||||
|
)
|
@ -328,6 +328,13 @@ and ord in ",
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn highest_card_ordinal_for_notetype(&self, ntid: NoteTypeID) -> Result<u16> {
|
||||||
|
self.db
|
||||||
|
.prepare(include_str!("highest_card_ord.sql"))?
|
||||||
|
.query_row(&[ntid], |row| row.get(0))
|
||||||
|
.map_err(Into::into)
|
||||||
|
}
|
||||||
|
|
||||||
// Upgrading/downgrading/legacy
|
// Upgrading/downgrading/legacy
|
||||||
|
|
||||||
pub(crate) fn get_all_notetypes_as_schema11(
|
pub(crate) fn get_all_notetypes_as_schema11(
|
||||||
|
Loading…
Reference in New Issue
Block a user