User macro to get all versions of a page
Asked by Dominic Lagger:

Hello community

I would like to create a user macro, which shows me a change history of all subpages.  
For that, I first tried to get a change history for just one page. But that doesn't semm possible.

I found this documentation: [public interface Versioned](https://docs.atlassian.com/DAC/javadoc/confluence/4.0/reference/com/atlassian/confluence/core/Versioned.html?)  
But as you can see, you can only access to the latest version.

![version_user_macro.png](/t5/image/serverpage/image-id/75393i97CCCDB9DA14773D/image-dimensions/517x227?v=v2 "version_user_macro.png")

++**Question**++

Is there any way to get all versions in a list?  
Then I could extract informations like versionnummer, date, comment, editor.  
And then I could display that as normal table.

Thanks for any help.

Regards, Dominic


Answers:
author: Dominic Lagger
body: I think I found a solution by my own.

There is a function for the [pageManager](https://docs.atlassian.com/ConfluenceServer/javadoc/latest/com/atlassian/confluence/pages/PageManager.html).

To get the pageManager, this is the script

```
#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') )
```

And now I can get all Versions with "getVersionHistorySummaries"

```
#set( $allVersions=$pageManager.getVersionHistorySummaries($content) )
```

And now, I can make my table like this:

```
<table>
 <tr>
  <th>Datum</th>
  <th>Version</th>
  <th>Beschreibung</th>
  <th>Link</th>
  <th>Bearbeiter</th>
 </tr>
 #foreach( $version in $allVersions )
 <tr>
  <td>$version.getLastModificationDate()</td>
  <td>$version.getVersion()</td>
  #if($version.getVersionComment())
   <td>$version.getVersionComment()</td>
  #else
   <td></td>
  #end
  <td>$version.getVersion()</td>
  #set( $allContributers=$version.getContributorSet() )
  <td>
  #foreach( $user in $allContributers)
   $user.getFullName()
  #end
  </td>
 </tr>
#end
</table>
```

And now, I have to iterate over all subpages, which should also be possible somehow :)

Regards, Dominic


author: Sven Schatter _Lively Apps_
body: Hi Dominic,

since I know you're a PocketQuery user, you could try using this Query:

```
SELECT *
FROM CONTENT
WHERE CONTENTID = :@pageid
OR PREVVER = :@pageid
ORDER BY VERSION
```

Of course you probably want to write a custom template as well that renders the user keys into actual user links, etc. but I think this should get you the data you need.

Best regards,  
Sven

comments: author: Dominic Lagger
body: Hi Sven

This is also a great idea! I didn't think of using PocketQuery for that! Nice!

I also found a solution with the confluence API.

But I will try this one, too. Thanks a lot

Regards, Dominic


author: DTS Infra Admin
body: [@Dominic Lagger](/t5/user/viewprofilepage/user-id/601600)

Can you tell the solution using API?

Thanks


author: Dominic Lagger
body: Do you mean for the pocketquery?

I would do it like this:

You have to loop over all children from a page with a given pageid

```
GET /rest/api/content/{id}/child
```

And for every result you have to call the API again, for getting all childs of childs.

With that, use some template and converter action and you should be able to get it done. I have not implemented it via API nor via the PocketQuery SQL. But both would work I think.

Hope this helped


author: Mike Bowen
body: Hi [@Dominic Lagger](/t5/user/viewprofilepage/user-id/601600)

Do you mean a report like this?

![list showing versions last updated date and person.png](https://community.atlassian.com/t5/image/serverpage/image-id/75404i1558FE83138374BC/image-size/large?v=v2&px=999 "list showing versions last updated date and person.png")

-Mike

comments: author: Dominic Lagger
body: Hi Mike

Do you already have such a user macro or is this a plugin?

I'm not sure whether this is the thing I'm looking for. Because there you just have the pages with the version numbers.

I'm looking for a table with, where every version of a page is one row with version comment and change date.

For example, you have 3 subpages, every subpage has 5 versions. Then my table should show 15 rows with every version and every version comment.


author: Mike Bowen
body: Hi Dominic,

I am using a plugin called QC Document for Confluence Cloud.

It can't do what you require there with 15 rows. It is more for pulling the latest version from a page.

You do seem to have a lot more control using Confluence Server, I do wish I had more access to the data using the query tool.

Cheers,

Mike


author: Sven Schatter _Lively Apps_
body: Indeed you do have much more control over Confluence Server than over Cloud. This is typical for all On-Premise vs SaaS software. However this also comes with all the costs of running and maintaining the software, which shouldn't be underestimated.


author: Sven Schatter _Lively Apps_
body: Also regarding PocketQuery (if that's what you mean by query tool), It's still early days but we are actually working on a Cloud version! ;)

Of course in this case it wouldn't actually help, because you don't have direct access to the database of Confluence Cloud, but you could still use it for the REST API and build a custom report that way. :)


Tags: confluence-server

server

user-macro