User macro to get all versions of a page

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.
December 6, 2019

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
But as you can see, you can only access to the latest version.

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

3 answers

2 accepted

1 vote
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.
December 6, 2019

I think I found a solution by my own.

There is a function for the pageManager.

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

0 votes
Answer accepted
Sven Schatter _Lively Apps_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
December 6, 2019

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

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.
December 6, 2019

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

DTS Infra Admin April 26, 2020

@Dominic Lagger 

Can you tell the solution using API?

 

Thanks

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.
April 27, 2020

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

0 votes
Mike Bowen
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.
December 6, 2019

Hi @Dominic Lagger 

Do you mean a report like this? 

list showing versions last updated date and person.png

-Mike

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.
December 6, 2019

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.

Mike Bowen
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.
December 6, 2019

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

Sven Schatter _Lively Apps_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
December 6, 2019

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.

Like Mike Bowen likes this
Sven Schatter _Lively Apps_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
December 6, 2019

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. :)

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events