mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Add import_deck_configs()
This commit is contained in:
parent
7520afd9c5
commit
ffdd8b741e
1 changed files with 25 additions and 0 deletions
|
@ -39,6 +39,7 @@ struct Context<'a> {
|
|||
remapped_notetypes: HashMap<NotetypeId, NotetypeId>,
|
||||
remapped_notes: HashMap<NoteId, NoteId>,
|
||||
remapped_decks: HashMap<DeckId, DeckId>,
|
||||
remapped_deck_configs: HashMap<DeckConfigId, DeckConfigId>,
|
||||
data: ExchangeData,
|
||||
usn: Usn,
|
||||
/// Map of source media files, that do not already exist in the target.
|
||||
|
@ -99,6 +100,7 @@ impl Collection {
|
|||
ctx.prepare_media()?;
|
||||
ctx.import_notetypes()?;
|
||||
ctx.import_notes()?;
|
||||
ctx.import_deck_configs()?;
|
||||
ctx.import_decks()?;
|
||||
ctx.copy_media()?;
|
||||
Ok(())
|
||||
|
@ -149,6 +151,7 @@ impl<'a> Context<'a> {
|
|||
remapped_notetypes: HashMap::new(),
|
||||
remapped_notes: HashMap::new(),
|
||||
remapped_decks: HashMap::new(),
|
||||
remapped_deck_configs: HashMap::new(),
|
||||
used_media_entries: HashMap::new(),
|
||||
normalize_notes,
|
||||
})
|
||||
|
@ -324,12 +327,24 @@ impl<'a> Context<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
fn import_deck_configs(&mut self) -> Result<()> {
|
||||
// TODO: keep ids if possible?
|
||||
for mut config in mem::take(&mut self.data.deck_configs) {
|
||||
let old_id = mem::take(&mut config.id);
|
||||
self.target_col
|
||||
.add_deck_config_inner(&mut config, Some(self.usn))?;
|
||||
self.remapped_deck_configs.insert(old_id, config.id);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn import_decks(&mut self) -> Result<()> {
|
||||
// TODO: ensure alphabetical order, so parents are seen first
|
||||
let mut renamed_parents = Vec::new();
|
||||
|
||||
for mut deck in mem::take(&mut self.data.decks) {
|
||||
deck.maybe_reparent(&renamed_parents);
|
||||
self.remap_deck_config_id(&mut deck)?;
|
||||
if let Some(original) = self.get_deck_by_name(&deck)? {
|
||||
if original.is_filtered() {
|
||||
deck.uniquify_name(&mut renamed_parents);
|
||||
|
@ -345,6 +360,16 @@ impl<'a> Context<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn remap_deck_config_id(&mut self, deck: &mut Deck) -> Result<()> {
|
||||
if let Some(config_id) = self
|
||||
.remapped_deck_configs
|
||||
.get(&DeckConfigId(deck.normal()?.config_id))
|
||||
{
|
||||
deck.normal_mut()?.config_id = config_id.0;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn add_deck(&mut self, deck: &mut Deck) -> Result<()> {
|
||||
let old_id = mem::take(&mut deck.id);
|
||||
self.target_col.add_deck_inner(deck, self.usn)?;
|
||||
|
|
Loading…
Reference in a new issue