Finding and deleting abandoned rules.

10 views
Skip to first unread message

Chris Roth

unread,
Feb 3, 2012, 2:15:27 PM2/3/12
to farcry-dev
I use an old school rule (Blairs I think) for rendering forms..
ruleForm. I need to do an overhaul of all our sites forms and since I
know they are all ruleForm based, I want to use the ruleForm table to
locate forms that are active and remove records in this table for
forms that no longer exist (It seems if a dmhtml page with a ruleForm
on it is deleted, the rule remains in the table).

What is the most efficient way to find the dmhtml objects the rule is
related to (if any) and then properly clean up abandoned rules?

Sean Coyne

unread,
Feb 3, 2012, 5:46:25 PM2/3/12
to farcr...@googlegroups.com
i usually run a query like (untested, sql server syntax, adjust as necessary for your db)

select left(c.label,35) as objectid, refObjects.typename, r.objectid as ruleObjectId from container c join container_aRules cr on c.objectid = cr.parentid join ruleForm r on cr.data = r.objectid left join refObjects on left(c.label,35) = refObjects.objectid;

That will give you a list of objectid's and the typename for objects that have (or had) a container with that rule, and the objectid of the rule.

If there is no typename value, then the object has probably been deleted since there was no record in refobjects.  You could then call the delete() method for the rule for each ruleObjectId you want to delete.

Something like (untested):

<cfset oRule = application.fapi.getcontenttype("ruleForm") />
<cfloop query="q">
  <cfif q.typename[q.currentrow] eq "">
    <cfset oRule.delete(q.ruleObjectid[q.currentrow] />
  </cfif>
</cfloop>


I would check that the page has been deleted first and be sure you actually want to remove those rules before deleting, but I hope you get the idea.  Also this wont work for "global" containers.  This will only match containers that have the ObjectID of the page in the label field.  

ex: <con:container label="#stobj.objectid#_myContainerName" />

Good luck

Sean Coyne

unread,
Feb 4, 2012, 8:51:35 AM2/4/12
to farcr...@googlegroups.com
oh you will want to change the query as follows:

select left(c.label,35) as objectid, refObjects.typename, r.objectid as ruleObjectId from container c join container_aRules cr on c.objectid = cr.parentid join ruleForm r on cr.data = r.objectid left join refObjects on left(c.label,35) = refObjects.objectid where cr.typename = 'ruleForm';

Otherwise you will get ALL rules, not just the ruleForm rules.

Chris Roth

unread,
Feb 9, 2012, 11:34:22 AM2/9/12
to farcry-dev
Thanks Sean, I'll try these out. Much appreciated.
Reply all
Reply to author
Forward
0 new messages