Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active April 27, 2018 19:12
Show Gist options
  • Save stevewithington/2534b948393445a75709 to your computer and use it in GitHub Desktop.
Save stevewithington/2534b948393445a75709 to your computer and use it in GitHub Desktop.
Mura CMS : Example of how to get the version history of all content items, and how to export version history as a CSV file.
<cfscript>
// Example of how to get a CSV report of all content items
// Drop this under a temp directory under the Mura webroot
// You could explicitly set this to any siteid you want, if desired
if ( !IsDefined('$') ) {
siteid = StructKeyExists(session, 'siteid') ? session.siteid : 'default';
$ = application.serviceFactory.getBean('$').init(siteid);
}
feedBean = $.getBean('feed').setMaxItems(0).setNextN(0);
it = feedBean.getIterator();
</cfscript>
<cfheader name="Content-Disposition" value="attachment;filename=versionhistory.csv">
<cfcontent type="text/csv">TITLE,STATUS,LASTUPDATE,LASTUPDATEBY
<cfoutput><cfif it.hasNext()><cfloop condition="#it.hasNext()#"><cfset item = it.next() /><cfset itHistory = item.getVersionHistoryIterator() /><cfloop condition="#itHistory.hasNext()#"><cfset hist = itHistory.next() />"#hist.getTitle()#","#hist.getStatus()#","#LSDateFormat(hist.getValue('lastupdate'))# #LSTimeFormat(hist.getValue('lastupdate'))#","#hist.getValue('lastupdateby')#"
</cfloop></cfloop></cfif></cfoutput>
<cfscript>
// Example of how to view the Version History of all content items
feedBean = $.getBean('feed').setMaxItems(0).setNextN(0);
it = feedBean.getIterator();
</cfscript>
<cfoutput>
<cfif it.hasNext()>
<ol>
<cfloop condition="#it.hasNext()#">
<cfset item = it.next() />
<li>
#item.getTitle()#
<ul>
<cfset itHistory = item.getVersionHistoryIterator() />
<cfloop condition="#itHistory.hasNext()#">
<cfset hist = itHistory.next() />
<li>
#hist.getStatus()# :
#LSDateFormat(hist.getValue('lastupdate'))# #LSTimeFormat(hist.getValue('lastupdate'))# :
#hist.getValue('lastupdateby')#
</li>
</cfloop>
</ul>
</li>
</cfloop>
</ol>
</cfif>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment