Commit 96a9d8c5 authored by Vincent Bechu's avatar Vincent Bechu

erp5_officejs: fix storage only during the first sync

parent 7e0db3ad
......@@ -11,8 +11,7 @@
return RSVP.all([
gadget.getSetting("portal_type"),
gadget.getSetting("erp5_attachment_synchro", undefined),
gadget.getSetting("default_view_reference", "jio_view"),
gadget.getSetting("storage_attachment_issue", false)
gadget.getSetting("default_view_reference", "jio_view")
]);
})
.push(function (result) {
......@@ -81,7 +80,6 @@
if (extended_attachment_url === "/{+id}/Document_downloadForOnlyOfficeApp") {
configuration = {
type: "fix_local",
is_fixed: result[3],
sub_storage: configuration
};
}
......
......@@ -273,7 +273,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>960.32726.32486.40567</string> </value>
<value> <string>960.32732.49023.25992</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -291,7 +291,7 @@
</tuple>
<state>
<tuple>
<float>1499160764.83</float>
<float>1499161889.04</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -3,11 +3,39 @@
(function (jIO, Blob, Rusha, RSVP, URI) {
"use strict";
var rusha = new Rusha(), stringify = jIO.util.stringify;
function repairDocumentSignature(storage, signature_document) {
/* The aim is deleted corrupted data to have fresh one from server
And clear signature for inexistant document
This can be consider like a HACK
*/
return storage._sub_storage.allDocs({
select_list: ["content_type"]
})
.push(function (result) {
var i, promise_list = [], doc_list = result.data.rows;
for (i = 0; i < result.data.total_rows; i += 1) {
if (doc_list[i].value.content_type !== undefined &&
!doc_list[i].value.content_type.startsWith("application/x-asc")) {
promise_list.push(
storage._sub_storage.remove(doc_list[i].id)
);
}
}
return RSVP.all(promise_list);
})
.push(function () {
signature_document.is_fixed = true;
return storage._local_storage.put(
storage._signature_hash, signature_document
);
});
}
function CompatibilityStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage);
this._is_fixed = spec.is_fixed;
this._replicate_storage = this._sub_storage.__storage;
this._local_storage = this._replicate_storage._local_sub_storage;
this._signature_hash = this._replicate_storage._signature_hash;
}
CompatibilityStorage.prototype.get = function () {
......@@ -31,31 +59,25 @@
};
CompatibilityStorage.prototype.repair = function () {
var context = this;
var storage = this, signature_doc;
// Here fix the local storage for some cases.
if (!context._is_fixed) {
return context._sub_storage.allDocs({
select_list: ["content_type"]
})
.push(function (result) {
var i, promise_list = [], doc_list = result.data.rows;
for (i = 0; i < result.data.total_rows; i += 1) {
if (doc_list[i].value.content_type !== undefined &&
!doc_list[i].value.content_type.startsWith("application/x-asc")) {
promise_list.push(
context._sub_storage.remove(doc_list[i].id)
);
return storage._local_storage.get(this._signature_hash)
.push(undefined, function (error) {
if (error.status_code === 404) {
return {is_fixed: false};
}
})
.push(function (doc) {
if (!doc.is_fixed) {
return repairDocumentSignature(storage, doc);
}
return RSVP.all(promise_list);
})
.push(function () {
return context._sub_storage.repair.apply(
context._sub_storage, arguments
return storage._sub_storage.repair.apply(
storage._sub_storage, arguments
);
});
}
};
CompatibilityStorage.prototype.allAttachments = function (doc_id) {
......
......@@ -229,7 +229,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>960.25570.27528.1382</string> </value>
<value> <string>960.33037.19706.64802</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -247,7 +247,7 @@
</tuple>
<state>
<tuple>
<float>1499160625.83</float>
<float>1499179222.51</float>
<string>UTC</string>
</tuple>
</state>
......
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