I am building a user macro that list all spaces. I would like to highlight those spaces where there has been no user action since X number of days, where user action means page updates or new pages.
I tried:
#set ( $spaceModificationDate = $space.getLastModificationDate() )
But this doesn't work, it shows an older date even when there has been more recent page updates in a space.
What would be the right way to find the latest date a page was updated or added in a space?
I would also like to know the user that performed that action.
Thanks in advance.
Hi Adolfo,
I don't know if it's the right way to do it, but I just hijacked the results from the activity stream macro to get the latest page or blogpost update in a space. I'm sure you can adapt it for your needs.
## @noparams
#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 ( $contentEntityManager = $containerContext.getComponent('contentEntityManager') )
#set ( $Integer = 0 )
#set ( $count = 0 )
#set ( $spaceKey = $space.key )
<table>
<tr>
<th>Page</th>
<th>Last Modifier</th>
<th>Modified Date</th>
</tr>
#set ( $inString = $action.getHelper().renderConfluenceMacro("{recently-updated:spaces=${spaceKey}|types=page,blogpost|max=1}") )
#foreach ( $line in $inString.split('<a href="') )
#set ( $count = $count + 1 )
#foreach ( $part in $line.split('"') )
#set ( $string = $part )
#break
#end
#if ( $count == 2 )
#break
#end
#end
#if ( $string.contains("/display/") )
#set ( $slashCount = $string.length() - $string.replace("/", "").length() )
#if ( $slashCount == 6 )
## Then this must be a blog post!
#set ( $splitString = $string.split("/") )
#set ( $index = 0 )
#foreach ( $section in $splitString )
#set ( $index = $index + 1 )
#if ( $index == 3 )
#set ( $spaceName = $section )
#end
#if ( $index == 4 )
#set ( $year = $Integer.parseInt($section) )
#end
#if ( $index == 5 )
#set ( $month = $Integer.parseInt($section) - 1 )
#end
#if ( $index == 6 )
#set ( $day = $Integer.parseInt($section) )
#end
#if ( $index == 7 )
#set ( $pageNameEncoded = $section )
#set ( $pageName = $generalUtil.urlDecode($pageNameEncoded) )
#end
#end
#set ( $blogPostCalendarObject = $action.dateFormatter.getCalendar() )
$blogPostCalendarObject.set($year, $month, $day)
#set ( $lastUpdatedPage = $pageManager.getBlogPost($spaceName, $pageName, $blogPostCalendarObject) )
#else
## Otherwise it is a regular page
#set ( $splitString = $string.split("/") )
#set ( $index = 0 )
#foreach ( $section in $splitString )
#set ( $index = $index + 1 )
#if ( $index == 3 )
#set ( $spaceName = $section )
#end
#if ( $index == 4 )
#set ( $pageNameEncoded = $section )
#set ( $pageName = $generalUtil.urlDecode($pageNameEncoded) )
#end
#end
#set ( $lastUpdatedPage = $pageManager.getPage($spaceName, $pageName) )
#end
#end
#if ( $string.contains("/pages/") )
#foreach ( $part in $string.split("=") )
#set ( $pageId = $part )
#end
#set ( $long = $generalUtil.getSystemStartupTime() )
#set ( $pageId = $long.parseLong($pageId) )
#set ( $lastUpdatedPage = $contentEntityManager.getById($pageId) )
#set ( $pageName = $lastUpdatedPage.title )
#end
#set ( $lastModifier = $lastUpdatedPage.lastModifier.name )
#set ( $lastModifiedDate = $lastUpdatedPage.lastModificationDate )
<tr>
<td>$pageName</td>
<td>$lastModifier</td>
<td>$lastModifiedDate</td>
</tr>
</table>Or it is simpler for only pages:
## @noparams
#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 ( $contentEntityManager = $containerContext.getComponent('contentEntityManager') )
#set ( $count = 0 )
#set ( $spaceKey = $space.key )
<table>
<tr>
<th>Page</th>
<th>Last Modifier</th>
<th>Modified Date</th>
</tr>
#set ( $inString = $action.getHelper().renderConfluenceMacro("{recently-updated:spaces=${spaceKey}|types=page|max=1}") )
#foreach ( $line in $inString.split('<a href="') )
#set ( $count = $count + 1 )
#foreach ( $part in $line.split('"') )
#set ( $string = $part )
#break
#end
#if ( $count == 2 )
#break
#end
#end
#if ( $string.contains("/display/") )
#set ( $splitString = $string.split("/") )
#set ( $index = 0 )
#foreach ( $section in $splitString )
#set ( $index = $index + 1 )
#if ( $index == 3 )
#set ( $spaceName = $section )
#end
#if ( $index == 4 )
#set ( $pageNameEncoded = $section )
#set ( $pageName = $generalUtil.urlDecode($pageNameEncoded) )
#end
#end
#set ( $lastUpdatedPage = $pageManager.getPage($spaceName, $pageName) )
#end
#if ( $string.contains("/pages/") )
#foreach ( $part in $string.split("=") )
#set ( $pageId = $part )
#end
#set ( $long = $generalUtil.getSystemStartupTime() )
#set ( $pageId = $long.parseLong($pageId) )
#set ( $lastUpdatedPage = $contentEntityManager.getById($pageId) )
#set ( $pageName = $lastUpdatedPage.title )
#end
#set ( $lastModifier = $lastUpdatedPage.lastModifier.name )
#set ( $lastModifiedDate = $lastUpdatedPage.lastModificationDate )
<tr>
<td>$pageName</td>
<td>$lastModifier</td>
<td>$lastModifiedDate</td>
</tr>
</table>
Thanks. This got me in the right way.
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.