Hi,
I like to write a user macro to show data like the modifier and the published date from a specific older version of the page.
Example: The current version of the page is 56. Who had modified the version 10 and when?
Look for something like this:
$content.getModifier(10)
$content.getModificationDate(10)
Kind regards
Manfred
First of all, you have to initialize the pageManager, with this, you can check the pages and it's versions.
#set( $containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager') )
#set( $getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null) )
#set( $containerManager=$getInstanceMethod.invoke(null,null) )
#set( $containerContext=$containerManager.containerContext )
#set( $pageManager=$containerContext.getComponent('pageManager') )
Then, you have to load the older version of the page:
#set( $versions = $pageManager.getVersionHistorySummaries($content.getEntity()) )
Then, you can create a table, like this
<table>
<tr>
<td>Version number</td>
<td>Last Mod date</td>
<td>Last modifier</td>
</tr>
#set( $versions = $pageManager.getVersionHistorySummaries($content.getEntity()) )
#foreach( $version in $versions)
<tr>
<td>$version.getVersion()</td>
<td>$version.getLastModificationDate()</td>
<td>$version.getLastModifier().getName()</td>
</tr>
#end
</table>
Hope this helps
Regards, Dominic
Hi @Dominic Lagger ,
thank you for the tip, it was very helpful.
I need only the modifier and the modification date from a specific version.
I take your code with a few changes. Here the code for the modifacation date:
## @param pageversion:title=Seitenversion=int|default=1|desc=Version der Seite
#set ($parampageversion = $generalUtil.convertToInteger("$parampageversion"))
#set( $containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager') )
#set( $getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null) )
#set( $containerManager=$getInstanceMethod.invoke(null,null) )
#set( $containerContext=$containerManager.containerContext )
#set( $pageManager=$containerContext.getComponent('pageManager') )
#set( $versions = $pageManager.getVersionHistorySummaries($content.getEntity()) )
#set( $versions = $pageManager.getVersionHistorySummaries($content.getEntity()) )
#set ( $idx = $content.version )
#set ( $idx = $idx - $parampageversion )
$action.dateFormatter.formatGivenString("dd.MM.yyyy", $versions.get($idx).getLastModificationDate())
The parameter in the user macro determine the version of the page for which the user want to show the modification date.
I pick the modification date directly from the versions collection. For that I have to determine the index of the wanted version in the collection. Subtract the wanted version from the current version seems to work. Hope the collection comes always in descending order.
For the modifier from an old version the coding is the same. Except the last the line:
$versions.get($idx).getLastModifier().getFullName()
Thank you for your help Dominic
Regards
Manfred
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.