How to purge Document History with resetArchive

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to purge Document History with resetArchive

Tronicek
Hi,

i've succeed to purge History of a single document using velocity:
$xwiki.getDocument('XWiki.123123').getDocument().resetArchive($context.context)

There's a problem in trying to purge history of more than one/two documents:
#set($sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className=’XWiki.XWikiUsers’")
#set($allUsers = $xwiki.searchDocuments($sql))
#foreach ($user in $allUsers)
  $xwiki.getDocument($user).getDocument().resetArchive($context.context)
#end

How can i avoid to get the message 'a different object with the same identifier value was already associated with the session'. Can you give me an advice, please?

I've had a bug in a scheduled job. As a result the user documents got updates each day. I have to reset the History of more than 1500 users to recover database space.

Thanks,
Rudolf

The error stack:
10:50:17,930 ERROR [STDERR] Caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'resetArchive' in  class com.xpn.xwiki.doc.XWikiDocument threw
exception com.xpn.xwiki.XWikiException: Error number 3211 in 3: Exception while updating archive XWiki.140004
Wrapped Exception: Error number 0 in 3: Exception while hibernate execute
Wrapped Exception: a different object with the same identifier value was already associated with the session: [com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo#com.xpn.xwiki.doc.rcs.XWikiRCS
NodeId@1610f1f[docId=-590464723,version=75.1]] @ ENitAdmin.PurgeHistoryTest[10,51]
10:50:17,930 ERROR [STDERR]     at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:286)
10:50:17,930 ERROR [STDERR]     at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:203)
10:50:17,930 ERROR [STDERR]     at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:294)
10:50:17,930 ERROR [STDERR]     at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:74)
10:50:17,930 ERROR [STDERR]     at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:88)
10:50:17,930 ERROR [STDERR]     at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:74)
10:50:17,930 ERROR [STDERR]     at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:88)
10:50:17,930 ERROR [STDERR]     at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:318)
10:50:17,930 ERROR [STDERR]     at org.xwiki.velocity.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:178)
10:50:17,930 ERROR [STDERR]     ... 86 more
10:50:17,930 ERROR [STDERR] Caused by: com.xpn.xwiki.XWikiException: Error number 3211 in 3: Exception while updating archive XWiki.140004
Wrapped Exception: Error number 0 in 3: Exception while hibernate execute
Wrapped Exception: a different object with the same identifier value was already associated with the session: [com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo#com.xpn.xwiki.doc.rcs.XWikiRCS
NodeId@1610f1f[docId=-590464723,version=75.1]]
10:50:17,930 ERROR [STDERR]     at com.xpn.xwiki.store.XWikiHibernateVersioningStore.updateXWikiDocArchive(XWikiHibernateVersioningStore.java:267)
10:50:17,930 ERROR [STDERR]     at com.xpn.xwiki.store.XWikiHibernateVersioningStore$2.doInHibernate(XWikiHibernateVersioningStore.java:247)
10:50:17,930 ERROR [STDERR]     at com.xpn.xwiki.store.XWikiHibernateBaseStore.execute(XWikiHibernateBaseStore.java:1032)
10:50:17,930 ERROR [STDERR]     at com.xpn.xwiki.store.XWikiHibernateBaseStore.executeWrite(XWikiHibernateBaseStore.java:1084)
10:50:17,930 ERROR [STDERR]     at com.xpn.xwiki.store.XWikiHibernateVersioningStore.resetRCSArchive(XWikiHibernateVersioningStore.java:238)
10:50:17,930 ERROR [STDERR]     at com.xpn.xwiki.doc.XWikiDocument.resetArchive(XWikiDocument.java:4312)
10:50:17,930 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:50:17,930 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
10:50:17,946 ERROR [STDERR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
10:50:17,946 ERROR [STDERR]     at java.lang.reflect.Method.invoke(Method.java:597)
10:50:17,946 ERROR [STDERR]     at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:295)
10:50:17,946 ERROR [STDERR]     at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:245)
10:50:17,946 ERROR [STDERR]     ... 94 more