[Framework-Team] Re: new workflows
Alex Clark
aclark at aclark.net
Thu Mar 1 20:56:21 UTC 2007
Martin, are you looking at this or do you want me to
(creating the migration if/when it is needed/wanted) ?
On Wed, Feb 28, 2007 at 03:50:21PM +0100, Raphael Ritz wrote:
> Martin Aspeli schrieb:
>
> [..]
>
>
> >I need to look at this in more detail, but we'd need to find a way of
> >doing it at a lower level. Hell, I'd copy the XML-parsing code and
> >make it more defensive if necessary. :)
> >
> >My hope (without looking at the code in detail) was that the logic
> >that parses the Definition.xml file and creates states, transitions
> >and so on is in a separate function to the logic that parses the main
> >workflows.xml file (which points to workflows to install, but also
> >does type mapping and what not). If we could invoke this logic
> >separately, we could make sure it was only ever called on XML files
> >corresponding to non-existant workflows.
> >
>
> I just looked into this a bit more and indeed it isn't that hard ;-)
>
> The following at least works for me as a script to be run via
>
> zopectl run <scriptname>
>
> on a Zope instance with a Plone site called 'plone'
>
> -------code starts -----
>
> from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
> from Products.DCWorkflow.exportimport import \
> WorkflowDefinitionConfigurator, _initDCWorkflow
>
> new_workflow_ids = ('wf1','wf2')
>
> site = app.plone
>
> wft = site.portal_workflow
>
> for wf_id in new_workflow_ids:
> if wf_id in wft.objectIds():
> print "%s already there; doing nothing" % wf_id
> continue
>
> body =
> open('/extra2/sites/bccnappdev/Products/BCCNApplications/profiles/default/workflows/reviewer_comments/definition.xml','r').read()
> # this needs to point to the right definition file(s) of course
> encoding = 'utf-8'
>
> wft._setObject(wf_id, DCWorkflowDefinition(wf_id))
> wf = wft[wf_id]
> wfdc = WorkflowDefinitionConfigurator(wf)
>
> ( workflow_id
> , title
> , state_variable
> , initial_state
> , states
> , transitions
> , variables
> , worklists
> , permissions
> , scripts
> ) = wfdc.parseWorkflowXML(body, encoding)
>
> _initDCWorkflow( wf
> , title
> , state_variable
> , initial_state
> , states
> , transitions
> , variables
> , worklists
> , permissions
> , scripts
> , site # not sure what to pass here
> # the site or the wft?
> # (does it matter at all?)
> )
> print "Added %s" % wf_id
>
> import transaction
> transaction.commit()
>
> ------ code ends ---------------
>
> From here it shouldn't be hard to turn this into a migration step
> in case we want one.
>
> Raphael
>
>
> _______________________________________________
> Framework-Team mailing list
> Framework-Team at lists.plone.org
> http://lists.plone.org/mailman/listinfo/framework-team
--
Alex Clark
More information about the Framework-Team
mailing list