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) {
"rev": next_rev.join('-'),
"status": flag
});
selected_node.children.unshift({
"rev": next_rev.join('-'),
"status": flag,
"children": []
});
return revs_info;
};
......@@ -648,8 +650,7 @@ jIO.addStorageType('revision', function (spec, my) {
* @param {object} command The JIO command
*/
that.remove = function (command) {
var f = {}, del_rev, option, i,
revision_found = false, revision_count = 0, correct_revision;
var f = {}, del_rev, option, new_doc, revs_info, new_id;
option = command.cloneOption();
if (option["max_retry"] === 0) {
option["max_retry"] = 3;
......@@ -658,19 +659,113 @@ jIO.addStorageType('revision', function (spec, my) {
f.removeDocument = function (docid, doctree) {
if (command.getOption("keep_revision_history") !== true) {
if (command.getAttachmentId() === undefined){
// update tree
priv.postToDocumentTree(doctree, command.getDoc(), true);
// remove revision
that.addJob(
"remove",
priv.substorage,
docid,
option,
function (response) {
if (typeof command.getAttachmentId() === undefined ){
priv.postToDocumentTree(doctree, command.getDoc(),
true
// put tree
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 {
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) {
that.error({
......@@ -683,6 +778,7 @@ jIO.addStorageType('revision', function (spec, my) {
return;
}
);
}
} else {
// keep history = update document tree only
}
......@@ -722,15 +818,15 @@ jIO.addStorageType('revision', function (spec, my) {
return;
} else {
// revision provided
if (priv.isRevisionALeaf( response, del_rev) === true){
if (typeof command.getAttachmentId() === "string"){
f.removeDocument(command.getDocId()+"."+del_rev+"/"+
command.getAttachmentId(), response);
f.removeDocument(command.getDocId()+"."+del_rev+
"/"+command.getAttachmentId(), response);
} else {
// loop leaves
if (priv.isRevisionALeaf(del_rev,
priv.getLeavesFromDocumentTree(response)) === true){
f.removeDocument(command.getDocId()+"."+
del_rev, response);
f.removeDocument(command.getDocId()+"."+ del_rev,
response
);
}
} else {
that.error({
"status": 409,
......@@ -742,7 +838,6 @@ jIO.addStorageType('revision', function (spec, my) {
return;
}
}
}
},
function (err) {
that.error({
......
......@@ -1424,7 +1424,8 @@ test ("Remove", function(){
o.rev = "3-"+generateRevisionHash(o.doc_myremove1, o.revisions);
// 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)");
o.jio.remove({"_id":"remove1/remove2","_rev":o.old_rev}, o.f);
o.tick(o);
......@@ -1452,8 +1453,8 @@ test ("Remove", function(){
// 7. check if document is updated
deepEqual(localstorage.getItem(
"jio/localstorage/urevrem/arevrem/remove1."+o.rev
), {"_id": "remove1."+o.rev}, "Check document");
), {"_id": "remove1."+o.rev, "title":"myRemove1"}, "Check document");
/*
// add another attachment
o.attmt_myremove2 = {
"remove3": {
......@@ -1540,11 +1541,11 @@ test ("Remove", function(){
o.spy (o,"status", 409, "409 - Removing document (no revision)");
o.jio.remove({"_id":"remove1"}, o.f);
o.tick(o);
*/
o.jio.stop();
});
/*
module ( "Jio Revision Storage + Local Storage" );
test ("Scenario", function(){
......@@ -1680,6 +1681,7 @@ test ("Scenario", function(){
ok ( o.jio, "Close application");
});
*/
/*
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