Merge branch 'master' into dev

This commit is contained in:
zadam 2023-02-10 10:41:12 +01:00
commit 8371703090
4 changed files with 61 additions and 12 deletions

View File

@ -163,6 +163,10 @@ class Becca {
.replace('_', '') .replace('_', '')
); );
if (!(camelCaseEntityName in this)) {
throw new Error(`Unknown entity name '${camelCaseEntityName}' (original argument '${entityName}')`);
}
return this[camelCaseEntityName][entityId]; return this[camelCaseEntityName][entityId];
} }

View File

@ -90,7 +90,7 @@ class ImageTypeWidget extends TypeWidget {
} }
async doRefresh(note) { async doRefresh(note) {
this.$imageView.prop("src", `api/images/${note.noteId}/${note.title}`); this.$imageView.prop("src", `api/images/${note.noteId}/${encodeURIComponent(note.title)}`);
} }
copyImageReferenceToClipboardEvent({ntxId}) { copyImageReferenceToClipboardEvent({ntxId}) {

View File

@ -148,13 +148,28 @@ class ConsistencyChecks {
AND notes.noteId IS NULL`, AND notes.noteId IS NULL`,
({branchId, parentNoteId}) => { ({branchId, parentNoteId}) => {
if (this.autoFix) { if (this.autoFix) {
const branch = becca.getBranch(branchId); // Delete the old branch and recreate it with root as parent.
branch.parentNoteId = 'root'; const oldBranch = becca.getBranch(branchId);
branch.save(); const noteId = oldBranch.noteId;
oldBranch.markAsDeleted("missing-parent");
let message = `Branch '${branchId}' was was missing parent note '${parentNoteId}', so it was deleted. `;
if (becca.getNote(noteId).getParentBranches().length === 0) {
const newBranch = new Branch({
parentNoteId: 'root',
noteId: noteId,
prefix: 'recovered'
}).save();
message += `${newBranch.branchId} was created in the root instead.`;
} else {
message += `There is one or more valid branches, so no new one will be created as a replacement.`;
}
this.reloadNeeded = true; this.reloadNeeded = true;
logFix(`Branch '${branchId}' was set to root parent since it was referencing missing parent note '${parentNoteId}'`); logFix(message);
} else { } else {
logError(`Branch '${branchId}' references missing parent note '${parentNoteId}'`); logError(`Branch '${branchId}' references missing parent note '${parentNoteId}'`);
} }
@ -467,10 +482,17 @@ class ConsistencyChecks {
const branches = branchIds.map(branchId => becca.getBranch(branchId)); const branches = branchIds.map(branchId => becca.getBranch(branchId));
for (const branch of branches) { for (const branch of branches) {
branch.parentNoteId = 'root'; // delete the old wrong branch
branch.save(); branch.markAsDeleted("parent-is-search");
logFix(`Child branch '${branch.branchId}' has been moved to root since it was a child of a search note '${parentNoteId}'`) // create a replacement branch in root parent
new Branch({
parentNoteId: 'root',
noteId: branch.noteId,
prefix: 'recovered'
}).save();
logFix(`Note '${branch.noteId}' has been moved to root since it was a child of a search note '${parentNoteId}'`)
} }
this.reloadNeeded = true; this.reloadNeeded = true;

View File

@ -100,15 +100,38 @@ function fillEntityChanges(entityName, entityPrimaryKey, condition = '') {
if (existingRows === 0) { if (existingRows === 0) {
createdCount++; createdCount++;
let hash;
let utcDateChanged;
let isSynced;
if (entityName.endsWith("_contents")) {
// FIXME: hacky, not sure if it might cause some problems
hash = "fake value";
utcDateChanged = dateUtils.utcNowDateTime();
isSynced = true; // contents are always synced
} else {
const entity = becca.getEntity(entityName, entityId); const entity = becca.getEntity(entityName, entityId);
if (entity) {
hash = entity?.generateHash() || "|deleted";
utcDateChanged = entity?.getUtcDateChanged() || dateUtils.utcNowDateTime();
isSynced = entityName !== 'options' || !!entity?.isSynced;
} else {
// entity might be null (not present in becca) when it's deleted
// FIXME: hacky, not sure if it might cause some problems
hash = "deleted";
utcDateChanged = dateUtils.utcNowDateTime();
isSynced = true; // deletable (the ones with isDeleted) entities are synced
}
}
addEntityChange({ addEntityChange({
entityName, entityName,
entityId, entityId,
hash: entity.generateHash(), hash: hash,
isErased: false, isErased: false,
utcDateChanged: entity.getUtcDateChanged(), utcDateChanged: utcDateChanged,
isSynced: entityName !== 'options' || !!entity.isSynced isSynced: isSynced
}); });
} }
} }