AnsweredAssumed Answered

Control version storage bloat with Javascript?

Question asked by sarnold on Oct 26, 2011
Latest reply on Oct 28, 2011 by sarnold
Hi All,

We are currently trailing Alfresco Community 4.0a with a view to using it in-house for document storage and management.

Firstly, none of this would be needed except that so far as I can see there is no way in Alfresco to limit the number of document versions that can be created.
So if I've missed something obvious please correct my understanding.

So I thought that perhaps we could put the "brakes" on an ever increasing file-store size by using a Javascript rule. Something along the lines of (in pseudo code):-

1. On document update check if document has the "versionable aspect":-
2. If it does then check the number if versions currently stored:-
3. If the number of versions is greater than say 10 then:-
4. Create a new document and fill it with lets say the most recent three versions of the document in question.
(we have to do it this way I guess because the javascript API appears to have NO mechanism for deleting a specific document version - true?)
5. Now delete the original
6. Then rename the new to match the original name.

So that's what I'm trying to do. If there is an easier way then please point me in the right direction.

My problem is I don't understand how to use document.versionHistory; and document.getVersion(); properly.

document.versionHistory returns an array like this:-

org.alfresco.repo.jscript.ScriptVersion@240f767d
org.alfresco.repo.jscript.ScriptVersion@732c1b09
org.alfresco.repo.jscript.ScriptVersion@54a326f1
org.alfresco.repo.jscript.ScriptVersion@2351c3a0
org.alfresco.repo.jscript.ScriptVersion@4d024f7d
org.alfresco.repo.jscript.ScriptVersion@52b0bf0a
org.alfresco.repo.jscript.ScriptVersion@51ce53ef
org.alfresco.repo.jscript.ScriptVersion@40e899de
org.alfresco.repo.jscript.ScriptVersion@66cddf1c
org.alfresco.repo.jscript.ScriptVersion@55f2dbfe
org.alfresco.repo.jscript.ScriptVersion@3b492cc7
org.alfresco.repo.jscript.ScriptVersion@411adb39
org.alfresco.repo.jscript.ScriptVersion@4a2e9c93
org.alfresco.repo.jscript.ScriptVersion@3a299cf1

(14 lines above one for each document version saved)

Disconcertingly every time the script is run the @hexadecimal numbers appear to all be totally different.

And if I try to retrieve a version of the document using say:-

document.getVersion("org.alfresco.repo.jscript.ScriptVersion@240f767d");

It just generates an error in the server side Javascript debugger saying that "org.alfresco.repo.jscript.ScriptVersion@240f767d" does not exist in version store "Workspace://SpaceStore/great-long-string-of-hex-digits"

Can someone give me just a few pointers on how I'm supposed to correctly use the Javascript 4.0 API to access and control document revisions?

Thanks!

Cheers Steve.

Update 1:

Using the Share Node browser I was able to verify that the store workspace being referenced by document.getVersion() was the node of the actual script and not the document.

I found that:-

space.getVersion("org.alfresco.repo.jscript.ScriptVersion@240f767d");

will execute without error. But:-

oldDoc = space.getVersion("org.alfresco.repo.jscript.ScriptVersion@240f767d");

Just assigns Null to oldDoc.

How does one use the getVersion API call?

Outcomes