[CPS-devel] transtyping documents to folderish documents

Florent Guillaume fg at nuxeo.com
Sat Jun 3 20:42:47 CEST 2006


If you change the class of an object, you have to make sure its  
container is also re-persisted, because in the ZODB the container of  
a persistent object has a reference to its child that includes the  
class.

Florent

On 2 Jun 2006, at 15:12, Jean-Marc Orliaguet wrote:

> Jean-Marc Orliaguet wrote:
>> Julien Anguenot wrote:
>>> Salut Jean-Marc,
>>>
>>> Jean-Marc Orliaguet wrote:
>>>
>>>> I'm about to migrate a couple of documents from "documentish" to
>>>> folderish (FolderishProxyDocument)
>>>>
>>>> CPS uses isinstance(ProxyFolderishDocument) in some places, so  
>>>> changing
>>>> to portal type to folderish is not enough.
>>>>
>>>> instances must be changed too.
>>>>
>>>> the current script does:
>>>>
>>>>     for brain in brains:
>>>>        ob = brain.getObject()
>>>>        if ob is None:
>>>>            continue
>>>>
>>>>        if isinstance(ob, ProxyFolderishDocument):
>>>>            continue
>>>>
>>>>        ob.__class__ = ProxyFolderishDocument
>>>>        ob._p_changed = 1 # trigger persistence
>>>>        ob.proxyChanged()
>>>>
>>>>        # + some workflow history stuff omitted here
>>>>
>>>> anything more to think about ?
>>>>
>>>
>>> You may need to update the workflow related annotations on the  
>>> object as
>>> well and ensure it's compatible with the folferish workflow your  
>>> objects
>>> are gonna follow after this migration. I guess you will need to  
>>> update
>>> your workflow associations as well to specify a folderish workflow
>>> instead of the former one.
>>>
>>> Keep us posted about the result.
>>>
>>>     J.
>>>
>>>
>
> sorry, I sent the one that didn't work. here is the correct one.
>
> ciao.
> /JM
>
> from Acquisition import aq_base
>
> from Products.CMFCore.utils import getToolByName
> from Products.CPSCore.ProxyBase import ProxyFolderishDocument
>
> def upgrade_personal_pages(self):
>     ctool = getToolByName(self, 'portal_catalog')
>
>     nchanged = 0
>
>     brains = ctool.searchResults(portal_type=('Chalmers personal  
> page',))
>     for brain in brains:
>         ob = brain.getObject()
>         if ob is None:
>             continue
>
>         if isinstance(ob, ProxyFolderishDocument):
>             continue
>
>         ob.__class__ = ProxyFolderishDocument
>         ob._p_changed = 1 # trigger persistence
>         ob.proxyChanged()
>
>         workflow_history = getattr(aq_base(ob), 'workflow_history',  
> None)
>         if workflow_history is None:
>             continue
>
>         changed = 0
>         for wf_id, wfh in workflow_history.items():
>             if wf_id != 'workspace_content_wf':
>                 continue
>
>             new_wfh = ()
>             for wf in wfh:
>                 new_wf = {}
>                 for k, v in wf.items():
>                     if k == 'workflow_id':
>                         if v == 'workspace_content_wf':
>                             v = 'workspace_folderish_content_wf'
>                     new_wf[k] = v
>                 new_wfh += new_wf,
>
>             workflow_history['workspace_folderish_content_wf'] =  
> new_wfh
>
>             workflow_history._p_changed = 1 # trigger persistence
>             changed = 1
>
>         if changed:
>             path = '/'.join(ob.getPhysicalPath())
>             nchanged += 1
>
>     return '%s personal pages migrated to folderish documents' %  
> nchanged
>
> _______________________________________________
> cps-devel mailing list
> http://lists.nuxeo.com/mailman/listinfo/cps-devel

-- 
Florent Guillaume, Nuxeo (Paris, France)   Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   fg at nuxeo.com





More information about the cps-devel mailing list

This list archive provided by Nuxeo, the leaders of open source ECM. Check out the Nuxeo 5 open source, standards-based ECM project.