Hi Mary, Thanks for the explanation - I'll give this a shot. I'm assuming I can just make the change in the same pipeline...
I also appreciate the info about the links, however I don't think I can do the link because the linked document would be in another database. I keep the secondary doc in different databases because they use different schemas and it avoids problems with setting different fragment roots and range indexes on similarly named elements. So when I create or update the document, the pipeline calls a program that runs an xquery to transform the incoming doc into a new format and inserts or updates the results into the secondary database via an xdmp:invoke function call - nasty but necessary... Likewise when I delete the document it has to delete the document in the secondary database as well via an xdmp:invoke function call. If there's a better way to approach this I'm all ears... Tim -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Mary Holstege Sent: Thursday, April 23, 2009 10:16 AM To: General Mark Logic Developer Discussion Cc: 'Paul Rooney' Subject: Re: [MarkLogic Dev General] How to configure a CPF when deleting adocument? On Wed, 22 Apr 2009 16:41:08 -0700, Tim Meagher <[email protected]> wrote: > I am creating a CPF to perform an action when a document is deleted, but > I'm > not seeing the entry in the error log. Here is the part of my CPF XML > file > pipeline file that handles the deletion: > > > <state-transition> > <annotation>Delete Reference Set XML</annotation> > <state>http://marklogic.com/states/deleted</state> > <on-success>http://marklogic.com/states/final</on-success> > <on-failure>http://marklogic.com/states/error</on-failure> > <default-action> > <module>/citedrefs/reference-set-delete-cpf.xqy</module> > </default-action> > </state-transition> > > Your fundamental problem is that deletion is not a *state* transition, but a *status* transition. That it, it isn't just a normal advancement of processing inside your pipeline's state machine, but is something fundamental that happens to the document. Never fear, you can do this, but you have to change from using a state-transition element to using a status-transition element. The Status Change Handling pipeline has an example, but your transition should look something like this: <status-transition> <annotation>Delete Reference Set XML</annotation> <status>deleted</status> <priority>10000</priority> <execute> <module>/citedrefs/reference-set-delete-cpf.xqy</module> </execute> </status-transition> Now for the caveats and warnings: deletion processing is trickier than normal processing because it all happens in a pre-commit trigger (normal state transition actions happen in a post-commit trigger) because if we waited, the document would already be gone. This means that you have to be extra careful that your code is bulletproof with no thrown errors or infinite cascades of work: because all of that will occur in the same transaction that deleted the document in the first place. What the normal CPF deletion handling does for cleaning up linked documents is to perform deletion in two phases: marking related targets with the deleted status, and then actually deleting them. If your clean-up process is somewhat involved, you can look to these modules for a guide. On the other hand, another way to slice the onion is to leverage the normal deletion cleanup instead of replacing it. The standard deletion action in CPF is to delete all documents marked as having a dependent link to the source document. The conversion application makes use of this to remove the XHTML generated from a PDF file when that PDF is deleted. The secret is to set a link property on the document, for example: (This method is in the module http://marklogic.com/cpf/links at /MarkLogic/cpf/links.xqy) lnk:create( $dependent-uri, $source-uri, "source", "related", "strong" ) > 1. Should the cpf:success state should be used since the document will be > deleted? Any working examples out there? See Modules/MarkLogic/cpf/actions/link-coherency-action.xqy Yes, call cpf:success and cpf:failure according to the normal pattern. In this case it will be a no-op, but it is good practice to always build your actions in this style so that they function properly even if you modify your application to call them in a case where there is a document in hand (e.g. soft delete). > 2. Will the $cpf:document-uri contain the URI of the deleted document? Yes. > 3. Is there some default deletion trigger that needs to be replaced or > disabled? Yes and no. There is one, but if you are not making use of automatic link coherency then you can just override it. Setting the priority and using an execute block rather than a default-action block will guarantee that your action will be chosen instead of the default one. You want the default one if you make use of any of the standard CPF applications (such as conversion or entity enrichment) that ship with the server. If you do use those applications, then I would recommend that you make sure you incorporate the logic from the link-coherency-action into your action, or find a way to leverage the automatic link processing yourself so you don't need to have your own method. Regards //Mary [email protected] Principal Engineer Mark Logic Corporation _______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
