Commit 12f16a47 authored by Sven Franck's avatar Sven Franck

bug fix remove attachment

parent f75085c4
...@@ -272,11 +272,13 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -272,11 +272,13 @@ jIO.addStorageType('revision', function (spec, my) {
"rev": next_rev.join('-'), "rev": next_rev.join('-'),
"status": flag "status": flag
}); });
selected_node.children.unshift({ selected_node.children.unshift({
"rev": next_rev.join('-'), "rev": next_rev.join('-'),
"status": flag, "status": flag,
"children": [] "children": []
}); });
return revs_info; return revs_info;
}; };
...@@ -648,8 +650,7 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -648,8 +650,7 @@ jIO.addStorageType('revision', function (spec, my) {
* @param {object} command The JIO command * @param {object} command The JIO command
*/ */
that.remove = function (command) { that.remove = function (command) {
var f = {}, del_rev, option, i, var f = {}, del_rev, option, new_doc, revs_info, new_id;
revision_found = false, revision_count = 0, correct_revision;
option = command.cloneOption(); option = command.cloneOption();
if (option["max_retry"] === 0) { if (option["max_retry"] === 0) {
option["max_retry"] = 3; option["max_retry"] = 3;
...@@ -658,19 +659,113 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -658,19 +659,113 @@ jIO.addStorageType('revision', function (spec, my) {
f.removeDocument = function (docid, doctree) { f.removeDocument = function (docid, doctree) {
if (command.getOption("keep_revision_history") !== true) { if (command.getOption("keep_revision_history") !== true) {
if (command.getAttachmentId() === undefined){
// update tree
priv.postToDocumentTree(doctree, command.getDoc(), true);
// remove revision
that.addJob( that.addJob(
"remove", "remove",
priv.substorage, priv.substorage,
docid, docid,
option, option,
function (response) { function (response) {
if (typeof command.getAttachmentId() === undefined ){
priv.postToDocumentTree(doctree, command.getDoc(), // put tree
true that.addJob(
"put",
priv.substorage,
doctree,
command.cloneOption(),
function (response) {
that.success({
"ok":true,
"id":docid,
"rev":revs_info[0].rev
});
},
function (err){
that.error({
"status": 409,
"statusText": "Conflict",
"error": "conflict",
"message": "Document update conflict.",
"reason": "Cannot update document tree"
});
return;
}
);
},
function (err) {
that.error({
"status": 404,
"statusText": "Not Found",
"error": "not_found",
"message": "File not found",
"reason": "Document was not found"
});
return;
}
); );
} else { } else {
priv.postToDocumentTree(doctree, command.getDoc()); // get previsous document
that.addJob(
"get",
priv.substorage,
command.getDocId()+"."+del_rev,
option,
function (response) {
// update tree
revs_info = priv.postToDocumentTree(doctree,
command.getDoc());
new_doc = response;
delete new_doc._attachments;
new_doc._id = new_doc._id+"."+revs_info[0].rev;
// post new document version
that.addJob(
"post",
priv.substorage,
new_doc,
command.cloneOption(),
function (response) {
// put tree
doctree._id = command.getDocId()+
priv.doctree_suffix;
that.addJob(
"put",
priv.substorage,
doctree,
command.cloneOption(),
function (response) {
that.success({
"ok":true,
"id":new_doc._id,
"rev":revs_info[0].rev
});
},
function (err) {
err.message =
"Cannot save document revision tree";
that.error(err);
} }
);
},
function (err){
that.error({
"status": 409,
"statusText": "Conflict",
"error": "conflict",
"message": "Document update conflict.",
"reason": "Cannot update document"
});
return;
}
);
}, },
function (err) { function (err) {
that.error({ that.error({
...@@ -683,6 +778,7 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -683,6 +778,7 @@ jIO.addStorageType('revision', function (spec, my) {
return; return;
} }
); );
}
} else { } else {
// keep history = update document tree only // keep history = update document tree only
} }
...@@ -722,15 +818,15 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -722,15 +818,15 @@ jIO.addStorageType('revision', function (spec, my) {
return; return;
} else { } else {
// revision provided // revision provided
if (priv.isRevisionALeaf( response, del_rev) === true){
if (typeof command.getAttachmentId() === "string"){ if (typeof command.getAttachmentId() === "string"){
f.removeDocument(command.getDocId()+"."+del_rev+"/"+ f.removeDocument(command.getDocId()+"."+del_rev+
command.getAttachmentId(), response); "/"+command.getAttachmentId(), response);
} else { } else {
// loop leaves f.removeDocument(command.getDocId()+"."+ del_rev,
if (priv.isRevisionALeaf(del_rev, response
priv.getLeavesFromDocumentTree(response)) === true){ );
f.removeDocument(command.getDocId()+"."+ }
del_rev, response);
} else { } else {
that.error({ that.error({
"status": 409, "status": 409,
...@@ -742,7 +838,6 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -742,7 +838,6 @@ jIO.addStorageType('revision', function (spec, my) {
return; return;
} }
} }
}
}, },
function (err) { function (err) {
that.error({ that.error({
......
...@@ -1424,7 +1424,8 @@ test ("Remove", function(){ ...@@ -1424,7 +1424,8 @@ test ("Remove", function(){
o.rev = "3-"+generateRevisionHash(o.doc_myremove1, o.revisions); o.rev = "3-"+generateRevisionHash(o.doc_myremove1, o.revisions);
// 4. remove existing attachment with revision // 4. remove existing attachment with revision
o.spy (o, "value", {"ok": true, "id": "remove1", "rev": o.rev},
o.spy (o, "value", {"ok": true, "id": "remove1."+o.rev, "rev": o.rev},
"Remove existing attachment (revision)"); "Remove existing attachment (revision)");
o.jio.remove({"_id":"remove1/remove2","_rev":o.old_rev}, o.f); o.jio.remove({"_id":"remove1/remove2","_rev":o.old_rev}, o.f);
o.tick(o); o.tick(o);
...@@ -1452,8 +1453,8 @@ test ("Remove", function(){ ...@@ -1452,8 +1453,8 @@ test ("Remove", function(){
// 7. check if document is updated // 7. check if document is updated
deepEqual(localstorage.getItem( deepEqual(localstorage.getItem(
"jio/localstorage/urevrem/arevrem/remove1."+o.rev "jio/localstorage/urevrem/arevrem/remove1."+o.rev
), {"_id": "remove1."+o.rev}, "Check document"); ), {"_id": "remove1."+o.rev, "title":"myRemove1"}, "Check document");
/*
// add another attachment // add another attachment
o.attmt_myremove2 = { o.attmt_myremove2 = {
"remove3": { "remove3": {
...@@ -1540,11 +1541,11 @@ test ("Remove", function(){ ...@@ -1540,11 +1541,11 @@ test ("Remove", function(){
o.spy (o,"status", 409, "409 - Removing document (no revision)"); o.spy (o,"status", 409, "409 - Removing document (no revision)");
o.jio.remove({"_id":"remove1"}, o.f); o.jio.remove({"_id":"remove1"}, o.f);
o.tick(o); o.tick(o);
*/
o.jio.stop(); o.jio.stop();
}); });
/*
module ( "Jio Revision Storage + Local Storage" ); module ( "Jio Revision Storage + Local Storage" );
test ("Scenario", function(){ test ("Scenario", function(){
...@@ -1680,6 +1681,7 @@ test ("Scenario", function(){ ...@@ -1680,6 +1681,7 @@ test ("Scenario", function(){
ok ( o.jio, "Close application"); ok ( o.jio, "Close application");
}); });
*/
/* /*
module ('Jio DAVStorage'); module ('Jio DAVStorage');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment