How to Set the Release Date on Masa CMS Content En Masse With the Feed API

November 29, 2023


A little while ago we had a Mura site (which has recently been upgraded to Masa) with a bunch of blog articles and other content where the "Release Date" field was left empty by accident. Obviously this is not a great idea. Having a release date helps with sorting and filtering data, not to mention it has SEO benefits.  

It was too much content to edit manually, and doing mass edits directly in the database can be dangerous. So we used the Mura scope and Feed API to collect all the content with no Release Date, and set it to the date said content was created (which might not be 100% accurate but for this purpose it was close enough).

Here's the code snippet:

 

<cfset $ = application.serviceFactory.getBean( "muraScope" ).init( "site name goes here" ) />
<cfset iterArticlesWithNoReleaseDate = $.getFeed( "content" )
.where()
.prop( "ReleaseDate" )
.isEQ( "null" )
.maxItems( 1000 ).getIterator() />
<cfloop condition="iterArticlesWithNoReleaseDate.hasNext()">
<cfset objArticle = iterArticlesWithNoReleaseDate.next() />
<cfset objArticle.setReleaseDate( objArticle.getCreated() ) />
<cfset objArticle.save() />
<!--- just in case something goes wrong --->
<cfdump var="#objArticle.getErrors()#" />
</cfloop>
<cfoutput>done.</cfoutput>

 

Obviously use this at your own risk. We didn't include much error logging or validation. How much of that you need will depend on the content in your site. I'd also recommend making a Site Bundle before applying such changes, just to be safe.

Hope that helps.
-nolan