From 6aa7ea0c6c587c01e8ec184a550d59ee2d888595 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 26 Jun 2017 19:12:49 +0000 Subject: [PATCH] More logging on import enex --- CliClient/app/import-enex.js | 36 ++++++++++++++++++++++++++---------- CliClient/app/main.js | 8 ++++++-- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/CliClient/app/import-enex.js b/CliClient/app/import-enex.js index 5350e88012..e91e3dfadc 100644 --- a/CliClient/app/import-enex.js +++ b/CliClient/app/import-enex.js @@ -89,23 +89,28 @@ async function saveNoteToStorage(note, fuzzyMatching = false) { let existingNote = fuzzyMatching ? await fuzzyMatch(note) : null; + let result = { + noteCreated: false, + noteUpdated: false, + resourcesCreated: 0, + }; + if (existingNote) { let diff = BaseModel.diffObjects(existingNote, note); delete diff.tags; delete diff.resources; delete diff.id; - // console.info('======================================'); - // console.info(note); - // console.info(existingNote); - // console.info(diff); - // console.info('======================================'); + // TODO: also save resources if (!Object.getOwnPropertyNames(diff).length) return; diff.id = existingNote.id; diff.type_ = existingNote.type_; - return Note.save(diff, { autoTimestamp: false }); + return Note.save(diff, { autoTimestamp: false }).then(() => { + result.noteUpdated = true; + return result; + }); } else { for (let i = 0; i < note.resources.length; i++) { let resource = note.resources[i]; @@ -119,12 +124,16 @@ async function saveNoteToStorage(note, fuzzyMatching = false) { if (existingResource) continue; await Resource.save(toSave, { isNew: true }); - await filePutContents(Resource.fullPath(toSave), resource.data); + await filePutContents(Resource.fullPath(toSave), resource.data) + result.resourcesCreated++; } return Note.save(note, { isNew: true, autoTimestamp: false, + }).then(() => { + result.noteCreated = true; + return result; }); } } @@ -138,7 +147,9 @@ function importEnex(parentFolderId, filePath, importOptions = null) { return new Promise((resolve, reject) => { let progressState = { loaded: 0, - imported: 0, + created: 0, + updated: 0, + resourcesCreated: 0, }; let stream = fs.createReadStream(filePath); @@ -188,8 +199,13 @@ function importEnex(parentFolderId, filePath, importOptions = null) { note.body = body; return saveNoteToStorage(note, importOptions.fuzzyMatching); - }).then(() => { - progressState.imported++; + }).then((result) => { + if (result.noteUpdated) { + progressState.updated++; + } else if (result.noteCreated) { + progressState.created++; + } + progressState.resourcesCreated += result.resourcesCreated; importOptions.onProgress(progressState); }); }); diff --git a/CliClient/app/main.js b/CliClient/app/main.js index 6ae44896bd..a09fb5411f 100644 --- a/CliClient/app/main.js +++ b/CliClient/app/main.js @@ -348,9 +348,13 @@ commands.push({ let options = { fuzzyMatching: args.options['fuzzy-matching'] === true, onProgress: (progressState) => { - let line = sprintf(_('Found: %d. Imported: %d.', progressState.loaded, progressState.imported)); + let line = []; + line.push(_('Found: %d.', progressState.loaded)); + line.push(_('Created: %d.', progressState.created)); + if (progressState.updated) line.push(_('Updated: %d.', progressState.updated)); + if (progressState.resourcesCreated) line.push(_('Resources: %d.', progressState.resourcesCreated)); redrawnCalled = true; - vorpal.ui.redraw(line); + vorpal.ui.redraw(line.join(' ')); }, onError: (error) => { let s = error.trace ? error.trace : error.toString();