Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get the modifier and published date from an older version of a page

Manfred Mütze May 2, 2020

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

1 answer

1 accepted

0 votes
Answer accepted
Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 3, 2020

Hi @Manfred Mütze 

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

Manfred Mütze May 3, 2020

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

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events