Back to index

plone3  3.1.7
update_discussion.py
Go to the documentation of this file.
00001 from Products.CMFCore.TypesTool import FactoryTypeInformation
00002 from Products.CMFDefault import DiscussionItem
00003 
00004 def update_discussion(self):
00005     """
00006      1. Install (if it isn't there already) a type information
00007         object for DiscussionItems, so that they can get actions,
00008         etc.  Erase the "(default)" workflow bound to it, to prevent
00009         showing the "Retract" options, etc.
00010 
00011      2. Update all DiscussionItems to use the new marking for
00012         'in_reply_to':
00013 
00014           - Items which are replies to the containing content object
00015             have None as their 'in_reply_to';
00016 
00017           - Items which are replies to sibling items have the sibling's
00018             ID as their 'in_reply_to'.
00019 
00020         The representation we are converting from was:
00021 
00022           - Items which are replies to the containing content object
00023             have the portal-relative pathstring of the content object
00024             as their 'in_reply_to';
00025 
00026           - Items which are replies to sibling items have the absolute
00027             path of the sibling as their 'in_reply_to'.
00028     """
00029 
00030     log = []
00031     a = log.append
00032     types_tool = self.portal_types
00033     if not getattr( types_tool, 'Discussion Item', None ):
00034 
00035         fti = FactoryTypeInformation(
00036                                 **DiscussionItem.factory_type_information[0] )
00037         types_tool._setObject( 'Discussion Item', fti )
00038         a( 'Added type object for DiscussionItem' )
00039 
00040         workflow_tool = self.portal_workflow
00041         workflow_tool.setChainForPortalTypes( ( 'Discussion Item', ), () )
00042         a( 'Erased workflow for DiscussionItem' )
00043 
00044     items = self.portal_catalog.searchResults( meta_type='Discussion Item' )
00045     a( 'DiscussionItems updated:' )
00046 
00047     for item in items:
00048 
00049         object = item.getObject()
00050         talkback = object.aq_parent
00051         path = item.getPath()
00052         in_reply_to = object.in_reply_to
00053 
00054         if in_reply_to is None: # we've been here already
00055             continue
00056 
00057         irt_elements = in_reply_to.split('/')
00058 
00059         if len( irt_elements ) == 1:
00060             if talkback._container.get( irt_elements[0] ):
00061                 # we've been here already
00062                 continue
00063 
00064         if irt_elements[0] == '': # absolute, so we are IRT a sibling
00065             sibling_id = irt_elements[ -1 ]
00066             if talkback._container.get( sibling_id, None ):
00067                 in_reply_to = sibling_id
00068             else:
00069                 in_reply_to = None
00070         else:
00071             in_reply_to = None
00072 
00073         object.in_reply_to = in_reply_to
00074         assert object.inReplyTo() # sanity check
00075         object.reindexObject()
00076 
00077         a( path )
00078 
00079     return '\n'.join(log)
00080