How to find the last time a confluence page was modified/added
Asked by Adolfo Casari:

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.


Answers:
author: Stephen Deutsch
body: 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 )&lt;table&gt;  &lt;tr&gt;    &lt;th&gt;Page&lt;/th&gt;    &lt;th&gt;Last Modifier&lt;/th&gt;    &lt;th&gt;Modified Date&lt;/th&gt;  &lt;/tr&gt;  #set ( $inString = $action.getHelper().renderConfluenceMacro("{recently-updated:spaces=${spaceKey}|types=page,blogpost|max=1}") )  #foreach ( $line in $inString.split('&lt;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 )  &lt;tr&gt;    &lt;td&gt;$pageName&lt;/td&gt;    &lt;td&gt;$lastModifier&lt;/td&gt;    &lt;td&gt;$lastModifiedDate&lt;/td&gt;  &lt;/tr&gt;&lt;/table&gt;
```

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 )&lt;table&gt;  &lt;tr&gt;    &lt;th&gt;Page&lt;/th&gt;    &lt;th&gt;Last Modifier&lt;/th&gt;    &lt;th&gt;Modified Date&lt;/th&gt;  &lt;/tr&gt;  #set ( $inString = $action.getHelper().renderConfluenceMacro("{recently-updated:spaces=${spaceKey}|types=page|max=1}") )  #foreach ( $line in $inString.split('&lt;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 )  &lt;tr&gt;    &lt;td&gt;$pageName&lt;/td&gt;    &lt;td&gt;$lastModifier&lt;/td&gt;    &lt;td&gt;$lastModifiedDate&lt;/td&gt;  &lt;/tr&gt;&lt;/table&gt;
```

comments: author: Adolfo Casari
body: Thanks. This got me in the right way.