handle uuid conflicts
This commit is contained in:
@@ -50,10 +50,6 @@ class Item {
|
||||
}
|
||||
}
|
||||
|
||||
alternateUUID() {
|
||||
this.uuid = Neeto.crypto.generateUUID();
|
||||
}
|
||||
|
||||
setDirty(dirty) {
|
||||
this.dirty = dirty;
|
||||
|
||||
|
||||
@@ -98,11 +98,12 @@ class DBManager {
|
||||
}, null)
|
||||
}
|
||||
|
||||
deleteItem(item) {
|
||||
deleteItem(item, callback) {
|
||||
this.openDatabase((db) => {
|
||||
var request = db.transaction("items", "readwrite").objectStore("items").delete(item.uuid);
|
||||
request.onsuccess = function(event) {
|
||||
console.log("Successfully deleted item", item.uuid);
|
||||
callback(true);
|
||||
};
|
||||
}, null)
|
||||
}
|
||||
|
||||
@@ -221,8 +221,10 @@ class AccountMenu {
|
||||
items: items
|
||||
}
|
||||
|
||||
// auth params are only needed when encrypted with a standard file key
|
||||
data["auth_params"] = authManager.getAuthParams();
|
||||
if(ek) {
|
||||
// auth params are only needed when encrypted with a standard file key
|
||||
data["auth_params"] = authManager.getAuthParams();
|
||||
}
|
||||
|
||||
return makeTextFile(JSON.stringify(data, null, 2 /* pretty print */));
|
||||
}
|
||||
|
||||
@@ -22,6 +22,18 @@ class ModelManager {
|
||||
})
|
||||
}
|
||||
|
||||
alternateUUIDForItem(item, callback) {
|
||||
// we need to clone this item and give it a new uuid, then delete item with old uuid from db (you can't mofidy uuid's in our indexeddb setup)
|
||||
var newItem = this.createItem(item);
|
||||
newItem.uuid = Neeto.crypto.generateUUID();
|
||||
this.removeItemLocally(item, function(){
|
||||
this.addItem(newItem);
|
||||
newItem.setDirty(true);
|
||||
newItem.markAllReferencesDirty();
|
||||
callback();
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
allItemsMatchingTypes(contentTypes) {
|
||||
return this.items.filter(function(item){
|
||||
return (_.includes(contentTypes, item.content_type) || _.includes(contentTypes, "*")) && !item.dummy;
|
||||
@@ -213,7 +225,7 @@ class ModelManager {
|
||||
item.removeAllRelationships();
|
||||
}
|
||||
|
||||
removeItemLocally(item) {
|
||||
removeItemLocally(item, callback) {
|
||||
_.pull(this.items, item);
|
||||
|
||||
item.isBeingRemovedLocally();
|
||||
@@ -227,7 +239,7 @@ class ModelManager {
|
||||
_.pull(this._extensions, item);
|
||||
}
|
||||
|
||||
this.dbManager.deleteItem(item);
|
||||
this.dbManager.deleteItem(item, callback);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -50,7 +50,7 @@ class SyncManager {
|
||||
this.modelManager.removeItemLocally(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(callback) {
|
||||
callback({success: true});
|
||||
}
|
||||
@@ -202,18 +202,25 @@ class SyncManager {
|
||||
}
|
||||
|
||||
console.log("Handle unsaved", unsaved);
|
||||
for(var mapping of unsaved) {
|
||||
var itemResponse = mapping.item;
|
||||
var item = this.modelManager.findItem(itemResponse.uuid);
|
||||
var error = mapping.error;
|
||||
if(error.tag == "uuid_conflict") {
|
||||
item.alternateUUID();
|
||||
item.setDirty(true);
|
||||
item.markAllReferencesDirty();
|
||||
}
|
||||
}
|
||||
|
||||
this.sync(null, {additionalFields: ["created_at", "updated_at"]});
|
||||
var i = 0;
|
||||
var handleNext = function() {
|
||||
if (i < unsaved.length) {
|
||||
var mapping = unsaved[i];
|
||||
var itemResponse = mapping.item;
|
||||
var item = this.modelManager.findItem(itemResponse.uuid);
|
||||
var error = mapping.error;
|
||||
if(error.tag == "uuid_conflict") {
|
||||
// uuid conflicts can occur if a user attempts to import an old data archive with uuids form the old account into a new account
|
||||
this.modelManager.alternateUUIDForItem(item, handleNext);
|
||||
}
|
||||
++i;
|
||||
} else {
|
||||
this.sync(null, {additionalFields: ["created_at", "updated_at"]});
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
handleNext();
|
||||
}
|
||||
|
||||
handleItemsResponse(responseItems, omitFields) {
|
||||
|
||||
Reference in New Issue
Block a user