Skip to content

Instantly share code, notes, and snippets.

@JonnyHayes
Created October 13, 2015 20:20
Show Gist options
  • Save JonnyHayes/c57fe18e24dfe886b6c4 to your computer and use it in GitHub Desktop.
Save JonnyHayes/c57fe18e24dfe886b6c4 to your computer and use it in GitHub Desktop.
Method to transfer related content from one siteID to another in mura cms.
<cfset siteID = "en">
<cfset remoteSiteID = "nl">
<cfset $ = application.serviceFactory.getBean('$').init(siteID)>
<cfset pluginConfig = $.getBean('pluginManager').getConfig('MuraTranslations')>
<cfset translationManager = createObject("component", "plugins.#pluginConfig.getDirectory()#.cfcs.translationManager").init($.getBean('configBean'), pluginConfig)>
<cfif not structKeyExists(session, "rs")>
<cfquery name="rs">
select distinct contentID, siteID from tcontentrelated where siteID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#siteID#">
</cfquery>
<cfset session.rs = rs>
</cfif>
<cfset it = $.getBean("contentIterator")>
<cfset it.setQuery(session.rs, 20)>
<cfif isNumeric($.event('start'))>
<cfset it.setPage($.event('start'))>
</cfif>
<cfloop condition="#it.hasNext()#">
<cfset source = it.next()>
<cfset translation = translationManager.getTranslation()>
<cfset translation.setRemoteSiteID(remoteSiteID)>
<cfset translation.setLocalSiteID(siteID)>
<cfset translation.setLocalID(source.getContentID())>
<cfset parentMapping = translation.getLocal()>
<cfif len(parentMapping.getRemoteID())>
<cfset mappedRelatedContentIDs = "">
<cfset sourceRCIT = source.getRelatedContentIterator()>
<cfif sourceRCIT.hasNext()>
<cfloop condition="#sourceRCIT.hasNext()#">
<cfset sourceRCNode = sourceRCIT.next()>
<!--- find peer, add to rc list --->
<cfset translation = translationManager.getTranslation()>
<cfset translation.setRemoteSiteID(remoteSiteID)>
<cfset translation.setLocalSiteID(siteID)>
<cfset translation.setLocalID(sourceRCNode.getContentID())>
<cfset RCMapping = translation.getLocal()>
<cfif len(RCMapping.getRemoteID())>
<cfset mappedRelatedContentIDs = listAppend(mappedRelatedContentIDs, RCMapping.getRemoteID())>
</cfif>
</cfloop>
<cfif listLen(mappedRelatedContentIDs)>
<cfset destination = $.getBean('content').loadBy(contentID=parentMapping.getRemoteID(), siteID=remoteSiteID)>
<cfif not destination.getIsNew()>
<cfset destination.setRelatedContentID(mappedRelatedContentIDs)>
<cfset output = structNew()>
<cfset output.mappedRelatedContentIDs = mappedRelatedContentIDs>
<cfset output.sourceTitle = source.getTitle()>
<cfset output.sourceContentID = source.getContentID()>
<cfset output.sourceContentHistID = source.getContentHistID()>
<cfset output.destinationTitle = destination.getTitle()>
<cfset output.destinationContentID = destination.getContentID()>
<cfset output.destinationContentHistID = destination.getContentHistID()>
<cfdump var="#output#">
<cfset destination.save()>
</cfif>
</cfif>
</cfif>
</cfif>
</cfloop>
<cfoutput>
<cfloop from="1" to="#it.pageCount()#" index="i">
<a href="?start=#i#">#i#</a>&nbsp;
</cfloop>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment