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 @@ ...@@ -11,8 +11,7 @@
return RSVP.all([ return RSVP.all([
gadget.getSetting("portal_type"), gadget.getSetting("portal_type"),
gadget.getSetting("erp5_attachment_synchro", undefined), gadget.getSetting("erp5_attachment_synchro", undefined),
gadget.getSetting("default_view_reference", "jio_view"), gadget.getSetting("default_view_reference", "jio_view")
gadget.getSetting("storage_attachment_issue", false)
]); ]);
}) })
.push(function (result) { .push(function (result) {
...@@ -81,7 +80,6 @@ ...@@ -81,7 +80,6 @@
if (extended_attachment_url === "/{+id}/Document_downloadForOnlyOfficeApp") { if (extended_attachment_url === "/{+id}/Document_downloadForOnlyOfficeApp") {
configuration = { configuration = {
type: "fix_local", type: "fix_local",
is_fixed: result[3],
sub_storage: configuration sub_storage: configuration
}; };
} }
......
...@@ -273,7 +273,7 @@ ...@@ -273,7 +273,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>960.32726.32486.40567</string> </value> <value> <string>960.32732.49023.25992</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -291,7 +291,7 @@ ...@@ -291,7 +291,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1499160764.83</float> <float>1499161889.04</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -3,11 +3,39 @@ ...@@ -3,11 +3,39 @@
(function (jIO, Blob, Rusha, RSVP, URI) { (function (jIO, Blob, Rusha, RSVP, URI) {
"use strict"; "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) { function CompatibilityStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage); 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 () { CompatibilityStorage.prototype.get = function () {
...@@ -31,31 +59,25 @@ ...@@ -31,31 +59,25 @@
}; };
CompatibilityStorage.prototype.repair = function () { CompatibilityStorage.prototype.repair = function () {
var context = this; var storage = this, signature_doc;
// Here fix the local storage for some cases. // Here fix the local storage for some cases.
if (!context._is_fixed) { return storage._local_storage.get(this._signature_hash)
return context._sub_storage.allDocs({ .push(undefined, function (error) {
select_list: ["content_type"] if (error.status_code === 404) {
}) return {is_fixed: false};
.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)
);
} }
})
.push(function (doc) {
if (!doc.is_fixed) {
return repairDocumentSignature(storage, doc);
} }
return RSVP.all(promise_list);
}) })
.push(function () { .push(function () {
return context._sub_storage.repair.apply( return storage._sub_storage.repair.apply(
context._sub_storage, arguments storage._sub_storage, arguments
); );
}); });
}
}; };
CompatibilityStorage.prototype.allAttachments = function (doc_id) { CompatibilityStorage.prototype.allAttachments = function (doc_id) {
......
...@@ -229,7 +229,7 @@ ...@@ -229,7 +229,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>960.25570.27528.1382</string> </value> <value> <string>960.33037.19706.64802</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -247,7 +247,7 @@ ...@@ -247,7 +247,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1499160625.83</float> <float>1499179222.51</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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