How can I sort Confluence spaces/pages by date modified?

I'm working on auditing our Confluence instance with the goal of archiving older spaces/pages to improve search/indexing performance and streamline the user experience. I've tried building a Search Macro to find, say, pages >1 year old, but I am unable to use a wildcard in the query to capture all items in a date range without it tanking. E.g., if I add "*" to the query, the system throws an "Invalid query params" error rendering the macro, but if I try leaving it blank, it will not let me save the macro.

Is there a way to execute this sort of search anymore or has this been nerfed with the removal of access to wikimarkup? Thanks in advance!

2 answers

This widget could not be displayed.

I have not the answer to your problem especially, but here is a macro that can help you eventually.

It posts a table of pages which are not recently updated. The number of days you wish are configurable.

Example: I made a page which is the first in hierarchy on every space, so every user that visits the space, sees directly the pages, which are not recently updated, with the author named and the last modified date.

 

Source:

http://blog.networkedcollaboration.com/2012/02/06/tracking-old-pages-in-confluence/

 

"In order to keep track of content in Confluence, and maybe give page authors a bit of a friendly nudge to update pages  , here’s how to create a simple user macro that lists pages in a Confluence space that have not been updated for a while."

 

## Macro title: Old Pages
## Macro has a body: Y or N (N)
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Andrew Frayling
## Date created: 05/02/2012
## Installed by: <your name>

## Macro to display pages that have not been updated for x days
## @param numdays:title=Number of Days|type=int|desc=Enter number of days to compare|required=true|multiple=false|default=7

#set ( $allPagesInSpace = $pageManager.getPages($space, true) )

## default value handler, set default to 7 days
#set ( $numdays = $paramnumdays )
#if(!$numdays)
#set ( $numdays = "7" )
#else
#set ( $numdays = $paramnumdays )
#end

## cast the number of days to an Integer
#set ( $Integer = 0 )
#set ( $intnumdays = $Integer.parseInt($numdays) )

## negative sign the number of days
#set ( $negativeDays = (-1 * $intnumdays) )

## get a calendar object so we can calculate the
## date we wish to compare with the page modification date
## e.g. $compareDate.add(6, -7) for pages modified over a week ago
#set ( $compareDate = $action.dateFormatter.getCalendar() )
$compareDate.setTime($content.getCurrentDate())
$compareDate.add(6, $negativeDays)

<p>Pages last updated before <strong>$action.dateFormatter.format($compareDate.getTime())</strong></p>

<table>
<tr>
<th>Page</th><th>Last Updated Date</th><th>Updated By</th>
</tr>

## loop through all the pages in the current space
#foreach($page in $allPagesInSpace)

## get a calendar object and for each page in space set it to last modification date
#set ($pagedate = $action.dateFormatter.getCalendar())
$pagedate.setTime($page.getLastModificationDate())

## only display pages last modified before the compare date
#if ($pagedate.before($compareDate))
<tr>
<td>#contentLink2($page true false)</td>
<td>$action.dateFormatter.format($page.getLastModificationDate())</td>
<td>#usernameLink($page.lastModifierName)</td>
</tr>
#end
#end
## end looping through pages in the current space

</table>

HI JD! I love this user macro you shared! I am using it to implement "wiki gardening" at my office. I have been trying to modify it so that, rather than "allPagesInSpace", it would only search the page on which I place it and all children (descendant) pages. I can't seem to get the thing to work, though, always get "unable to render" or something. I am trying to fgiure it out, but thought you might have some tips. Thx : )

I changed this line:

#set ( $allPagesInSpace = $pageManager.getPages($space, true) )

to this:

#set ( $allDescendants = $content.getDescendants() )

That now makes the user macro behave as I wish, it only searches the descendants of whatever page it is placed on. Hooray!

The next improvements I would like to make, but don't know how:

1) define a default sort for the results:

  1. created date, old>new
  2. modified date, old>new
  3. creating user, alphabetical
  4. modifying user, alphabetical

2) make #set include the parent page, i.e., the page on which the macro is placed, in the search, too.

Here is the updated user macro (updated lines are BOLDED):

## Macro title: Old Pages
## Macro has a body: Y or N (N)
## Body processing: Selected body processing option
## Output: Selected output option

## Macro to display pages that have not been updated for x days
## @param numdays:title=Number of Days|type=int|desc=Enter number of days to compare|required=true|multiple=false|default=7

#set ( $allDescendants = $content.getDescendants() )

## default value handler, set default to 7 days
#set ( $numdays = $paramnumdays )
#if(!$numdays)
#set ( $numdays = "7" )
#else
#set ( $numdays = $paramnumdays )
#end

## cast the number of days to an Integer
#set ( $Integer = 0 )
#set ( $intnumdays = $Integer.parseInt($numdays) )

## negative sign the number of days
#set ( $negativeDays = (-1 * $intnumdays) )

## get a calendar object so we can calculate the
## date we wish to compare with the page modification date
## e.g. $compareDate.add(6, -7) for pages modified over a week ago
#set ( $compareDate = $action.dateFormatter.getCalendar() )
$compareDate.setTime($content.getCurrentDate())
$compareDate.add(6, $negativeDays)

<p>Pages last updated before <strong>$action.dateFormatter.format($compareDate.getTime())</strong></p>

<table>
<tr>
<th>Page</th><th>Created</th><th>Created By</th><th>Last Updated</th><th>Last Updated By</th>
</tr>

## loop through all the pages in the current space
#foreach($page in $allDescendants)

## get a calendar object and for each page in space set it to last modification date
#set ($pagedate = $action.dateFormatter.getCalendar())
$pagedate.setTime($page.getLastModificationDate())

## only display pages last modified before the compare date
#if ($pagedate.before($compareDate))
<tr>
<td>#contentLink2($page true false)</td>
<td>$action.dateFormatter.format($page.getCreationDate())</td>
<td>#usernameLink($page.creatorName)</td>
<td>$action.dateFormatter.format($page.getLastModificationDate())</td>
<td>#usernameLink($page.lastModifierName)</td>
</tr>
#end
#end
## end looping through pages in the current space

</table>

 

Hi all,

Can we customize it a little bit. Actually i was trying to create a macro which can help me find the list of all the pages which were edited or created during some time frame.

If we get the modifier name along with that, that would be better.

So need assistance related that. 

 

Thanks and regards

Sandeep Anand

This widget could not be displayed.

Everyone, this is exactly what I am looking for (also), but am a "nub" e.g. "newbie" to Confluence.  Where is the best tutorial for creating a macro.

THNX in advance for your response.

o.k..  let the snickering begin :)

I came across this answer looking for something else, but what I found may come in useful to others.

 

on the parent page if you add a list of child pages you can sort the list of contents by 'creation date', 'modified date' or 'title'. This solution wouldn't change the ordering of your left side menu but it does provide a similar solution to what was required here?

 

EDIT: the above also doesnt require a macro

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

199 views 2 4
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you