Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions
plone.app.iterate.copier.ContentCopier Class Reference

List of all members.

Public Member Functions

def __init__
def copyTo
def merge

Public Attributes

 context

Private Member Functions

def _getBaseline
def _replaceBaseline
def _reassembleWorkingCopy
def _deleteWorkingCopyRelation
def _copyBaseline
 Checkout Support Methods.
def _handleReferences

Detailed Description

Definition at line 41 of file copier.py.


Constructor & Destructor Documentation

def plone.app.iterate.copier.ContentCopier.__init__ (   self,
  context 
)

Definition at line 46 of file copier.py.

00046 
00047     def __init__( self, context ):
00048         self.context = context

Here is the caller graph for this function:


Member Function Documentation

def plone.app.iterate.copier.ContentCopier._copyBaseline (   self,
  container 
) [private]

Checkout Support Methods.

Definition at line 153 of file copier.py.

00153 
00154     def _copyBaseline( self, container ):
00155         # copy the context from source to the target container
00156         source_container = aq_parent( aq_inner( self.context ) )
00157         clipboard = source_container.manage_copyObjects( [ self.context.getId() ] )
00158         result = container.manage_pasteObjects( clipboard )
00159 
00160         # get a reference to the working copy
00161         target_id = result[0]['new_id']
00162         target = container._getOb( target_id )
00163         return target
00164 
    

Here is the caller graph for this function:

Definition at line 143 of file copier.py.

00143 
00144     def _deleteWorkingCopyRelation( self ):
00145         # delete the wc reference keeping a reference to it for its annotations
00146         refs = self.context.getReferenceImpl( WorkingCopyRelation.relationship )
00147         wc_ref = refs[0]
00148         self.context.deleteReferences( WorkingCopyRelation.relationship )
00149         return wc_ref

Here is the caller graph for this function:

Definition at line 74 of file copier.py.

00074 
00075     def _getBaseline( self ):
00076         # follow the working copy's reference back to the baseline
00077         refs = self.context.getRefs( WorkingCopyRelation.relationship )
00078 
00079         if not len(refs) == 1:
00080             raise CheckinException( "Baseline count mismatch" )
00081 
00082         if not refs or refs[0] is None:
00083             raise CheckinException( "Baseline has disappeared" )
00084 
00085         baseline = refs[0]
00086         return baseline
00087 

Here is the caller graph for this function:

def plone.app.iterate.copier.ContentCopier._handleReferences (   self,
  baseline,
  wc,
  mode,
  wc_ref 
) [private]

Definition at line 165 of file copier.py.

00165 
00166     def _handleReferences( self, baseline, wc, mode, wc_ref ):
00167 
00168         annotations = IAnnotations( wc_ref )
00169         
00170         baseline_adapter = interfaces.ICheckinCheckoutReference( baseline )
00171         
00172         # handle forward references
00173         for relationship in baseline.getRelationships():
00174             # look for a named relation adapter first
00175             adapter = component.queryAdapter( baseline,
00176                                               interfaces.ICheckinCheckoutReference,
00177                                               relationship )
00178             
00179             if adapter is None: # default
00180                 adapter = baseline_adapter
00181                 
00182             references = baseline.getReferenceImpl( relationship )
00183 
00184             mode_method = getattr( adapter, mode )
00185             mode_method( baseline, wc, references, annotations )
00186 
00187         mode = mode + "BackReferences"
00188         
00189         # handle backward references
00190         for relationship in baseline.getBRelationships():
00191             adapter = component.queryAdapter( baseline,
00192                                               interfaces.ICheckinCheckoutReference,
00193                                               relationship )
00194             if adapter is None:
00195                 adapter = baseline_adapter
00196                 
00197             references = baseline.getBackReferenceImpl( relationship )
00198             
00199             mode_method = getattr( adapter, mode )
00200             mode_method( baseline, wc, references, annotations )

Here is the caller graph for this function:

def plone.app.iterate.copier.ContentCopier._reassembleWorkingCopy (   self,
  new_baseline,
  baseline 
) [private]

Definition at line 117 of file copier.py.

00117 
00118     def _reassembleWorkingCopy( self, new_baseline, baseline ):
00119         # reattach the source's workflow history, try avoid a dangling ref 
00120         try:
00121             new_baseline.workflow_history = PersistentMapping( baseline.workflow_history.items() )
00122         except AttributeError:
00123             # No workflow apparently.  Oh well.
00124             pass
00125 
00126         # reset wf state security directly
00127         workflow_tool = getToolByName(self.context, 'portal_workflow')
00128         wfs = workflow_tool.getWorkflowsFor( self.context )
00129         for wf in wfs:
00130             if not isinstance( wf, DCWorkflowDefinition ):
00131                 continue
00132             wf.updateRoleMappingsFor( new_baseline )
00133 
00134         # reattach the source's uid, this will update wc refs to point back to the new baseline
00135         new_baseline._setUID( baseline.UID() )
00136 
00137         # reattach the source's history id, to get the previous version ancestry
00138         histid_handler = getToolByName( self.context, 'portal_historyidhandler')
00139         huid = histid_handler.getUid( baseline )
00140         histid_handler.setUid( new_baseline, huid, check_uniqueness=False )
00141 
00142         return new_baseline

Here is the call graph for this function:

Here is the caller graph for this function:

def plone.app.iterate.copier.ContentCopier._replaceBaseline (   self,
  baseline 
) [private]

Definition at line 88 of file copier.py.

00088 
00089     def _replaceBaseline( self, baseline ):
00090         # move the working copy object to the baseline, returns the new baseline
00091         baseline_id = baseline.getId()
00092         
00093         # delete the baseline from the folder to make room for the committed working copy
00094         baseline_container = aq_parent( aq_inner( baseline ) )
00095         baseline_container._delOb( baseline_id )
00096 
00097         # delete the working copy from the its container
00098         wc_container =  aq_parent( aq_inner( self.context ) )
00099 
00100         # trick out the at machinery to not delete references
00101         self.context._v_cp_refs = 1
00102         self.context._v_is_cp = 0
00103         
00104         wc_container.manage_delObjects( [self.context.getId()] )
00105         
00106         # move the working copy back to the baseline container
00107         working_copy = aq_base( self.context )
00108         working_copy.setId( baseline_id )
00109         baseline_container._setOb( baseline_id, working_copy )
00110 
00111         new_baseline = baseline_container._getOb( baseline_id )
00112         
00113         # reregister our references with the reference machinery after moving
00114         Referenceable.manage_afterAdd( new_baseline, new_baseline, baseline_container)
00115         
00116         return new_baseline

Here is the caller graph for this function:

def plone.app.iterate.copier.ContentCopier.copyTo (   self,
  container 
)

Definition at line 49 of file copier.py.

00049 
00050     def copyTo( self, container ):
00051         wc = self._copyBaseline( container )
00052         wc_ref = wc.addReference( self.context,
00053                                   relationship = WorkingCopyRelation.relationship,
00054                                   referenceClass = WorkingCopyRelation )
00055         self._handleReferences( self.context, wc, "checkout", wc_ref )
00056         return wc, wc_ref
    

Here is the call graph for this function:

Definition at line 57 of file copier.py.

00057 
00058     def merge( self ):
00059         baseline = self._getBaseline()
00060 
00061         # delete the working copy reference to the baseline
00062         wc_ref = self._deleteWorkingCopyRelation()
00063         
00064         # reassemble references on the new baseline         
00065         self._handleReferences( baseline, self.context, "checkin", wc_ref )
00066 
00067         # move the working copy to the baseline container, deleting the baseline 
00068         new_baseline = self._replaceBaseline( baseline )
00069 
00070         # patch the working copy with baseline info not preserved during checkout
00071         self._reassembleWorkingCopy( new_baseline, baseline )
00072 
00073         return new_baseline

Here is the call graph for this function:


Member Data Documentation

Definition at line 47 of file copier.py.


The documentation for this class was generated from the following file: