Related items is a really nice feature in FarCry, allowing you to cross relate pages, breaking free of the Site Tree navigation. However, using this feature can easily get you into a message if you delete a page that appears in the related items list of another.

FarCry doesn’t do a very good job of cleaning these relationships up, when pages are deleted. We have solved this internally at Enpresiv, by overriding the deleteData methods of the core types (dmHTML, and dmNews).

However, if you want a quick fix, the code below will remove any orphaned related data for both dmHTML and dmNews.

<cfset lTypes = 'dmHTML,dmNews' />

<cfloop list="#lTypes#" index="typesIndex">

	<cfquery name="qData" datasource="#application.dsn#">
		SELECT #typesIndex#_aRelatedIDs.data
		FROM #typesIndex#_aRelatedIDs
		LEFT JOIN refObjects ON #typesIndex#_aRelatedIDs.data = refObjects.objectId
		WHERE refObjects.typename IS NULL
	</cfquery>

	<cfdump var="#qData#" label="#typesIndex#" />

	<cfquery name="qDelete" datasource="#application.dsn#">
		DELETE FROM #typesIndex#_aRelatedIDs
		WHERE data IN ('#replaceNoCase(ValueList(qData.data),",","','","ALL")#')
	</cfquery>

</cfloop>

Post a Comment

*
*