Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
API migration to remove deprecated calls
zadameaab82551fb8
diff --git a/db/migrations/0213__migrate_scripts.js b/db/migrations/0213__migrate_scripts.jsnew file mode 100644index 0000000000..eed005c1c1--- /dev/null+++ b/db/migrations/0213__migrate_scripts.js@@ -0,0 +1,48 @@+module.exports = () => {+ const beccaLoader = require("../../src/becca/becca_loader");+ const becca = require("../../src/becca/becca");+ const cls = require("../../src/services/cls");+ const log = require("../../src/services/log");++ cls.init(() => {+ beccaLoader.load();++ for (const note of Object.values(becca.notes)) {+ try {+ if (!note.isJavaScript()) {+ continue;+ }++ if (!note.mime?.endsWith('env=frontend') && !note.mime?.endsWith('env=backend')) {+ continue;+ }++ const origContent = note.getContent().toString();+ const fixedContent = origContent+ .replaceAll("runOnServer", "runOnBackend")+ .replaceAll("api.refreshTree()", "")+ .replaceAll("addTextToActiveTabEditor", "addTextToActiveContextEditor")+ .replaceAll("getActiveTabNote", "getActiveContextNote")+ .replaceAll("getActiveTabTextEditor", "getActiveContextTextEditor")+ .replaceAll("getActiveTabNotePath", "getActiveContextNotePath")+ .replaceAll("getDateNote", "getDayNote")+ .replaceAll("utils.unescapeHtml", "unescapeHtml")+ .replaceAll("sortNotesByTitle", "sortNotes")+ .replaceAll("CollapsibleWidget", "RightPanelWidget")+ .replaceAll("TabAwareWidget", "NoteContextAwareWidget")+ .replaceAll("TabCachingWidget", "NoteContextAwareWidget")+ .replaceAll("NoteContextCachingWidget", "NoteContextAwareWidget");++ if (origContent !== fixedContent) {+ log.info(`Replacing legacy API calls for note '${note.noteId}'`);++ note.saveNoteRevision();+ note.setContent(fixedContent);+ }+ }+ catch (e) {+ log.error(`Error during migration to 213 for note '${note.noteId}': ${e.message} ${e.stack}`);+ }+ }+ });+};diff --git a/src/services/app_info.js b/src/services/app_info.jsindex 4a8f501583..3f5f02f3b9 100644--- a/src/services/app_info.js+++ b/src/services/app_info.js@@ -4,7 +4,7 @@ const build = require('./build');const packageJson = require('../../package');const {TRILIUM_DATA_DIR} = require('./data_dir');-const APP_DB_VERSION = 212;+const APP_DB_VERSION = 213;const SYNC_VERSION = 29;const CLIPPER_PROTOCOL_VERSION = "1.0";