Ticket #9672: patch_factory.py

File patch_factory.py, 2.3 KB (added by hazmat, 2 years ago)

patch to for portal factory sanity ( redux sans debug w/ fix )

Line 
1"""
2
3Make Archetypes content factory aware, by not having it indexed at all while
4. This prevents lots of spurious transactions in. It does potentially cause
5breakage for reference browser usage.
6
7
8"""
9from Acquisition import aq_inner, aq_parent
10
11def isFactoryContained( obj ):
12    return aq_parent(aq_inner(obj)).meta_type == 'TempFolder'
13
14def referenceAfterAdd( self, item, container ):
15    if isFactoryContained( self ):
16        return
17    return self.referenceAfterAdd( item, container )
18
19def uncatalogUID( self, aq, uc=None ):
20    if isFactoryContained( self ):
21        return
22    return self.at_uncatalogUID( aq, uc )
23   
24def uncatalogRefs( self, aq, uc=None, rc=None ):
25    if isFactoryContained( self ):
26        return
27    return self.at_uncatalogRefs( aq, uc, rc )
28
29def reindexObject( self, idxs=() ):
30    if isFactoryContained( self ):
31        return
32    return self.at_reindexObject( idxs )
33
34def reindexObjectSecurity( self, skip_self=False ):
35    if isFactoryContained( self ):
36        return
37    return self.at_reindexObjectSecurity( skip_self )
38
39def unindexObject( self ):
40    if isFactoryContained( self ):
41        return
42    return self.at_unindexObject()
43
44def indexObject( self ):
45    if isFactoryContained( self ):
46        return
47    return self.at_indexObject()
48
49def applyPatches( ):
50    from Products.Archetypes.CatalogMultiplex import CatalogMultiplex
51    from Products.Archetypes.Referenceable import Referenceable
52
53    Referenceable.referenceAfterAdd = Referenceable.manage_afterAdd
54    Referenceable.manage_afterAdd = referenceAfterAdd
55   
56    Referenceable.at_uncatalogUID = Referenceable._uncatalogUID
57    Referenceable._uncatalogUID = uncatalogUID
58   
59    Referenceable.at_uncatalogRefs = Referenceable._uncatalogRefs
60    Referenceable._uncatalogRefs = uncatalogRefs
61   
62    CatalogMultiplex.at_indexObject = CatalogMultiplex.indexObject
63    CatalogMultiplex.indexObject = indexObject
64
65    CatalogMultiplex.at_reindexObject = CatalogMultiplex.reindexObject
66    CatalogMultiplex.reindexObject = reindexObject   
67
68    CatalogMultiplex.at_unindexObject = CatalogMultiplex.unindexObject
69    CatalogMultiplex.unindexObject = unindexObject
70
71    CatalogMultiplex.at_reindexObjectSecurity = CatalogMultiplex.reindexObjectSecurity
72    CatalogMultiplex.reindexObjectSecurity= reindexObjectSecurity
73   
74