source: products/qPloneSkinDump/trunk/skin_template/fixes.py @ 2111

Last change on this file since 2111 was 74, checked in by chervol, 18 years ago

initial plone2.0.5 branch import

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1from Acquisition import aq_base
2from Products.CMFCore.utils import getToolByName
3from Products.ZCatalog.ProgressHandler import ZLogHandler
4from plone.app.linkintegrity.handlers import referencedRelationship as li_relation
5
6portal_catalog = None
7portal_repository = None
8uid_catalog = None
9reference_catalog = None
10
11def fix_archivest(ob):
12    ''' Fix #7334 bug of CMFEdition.
13        Fixed in CMFEdition v1.1.5+
14    '''
15    if portal_repository.isVersionable(ob):
16        portal_repository.save(obj=ob, comment="")
17
18def fix_catalog(ob):
19    ob.reindexObject()
20
21def fix_linkintegrity(ob):
22    """Fix losed references."""
23    uobject = aq_base(ob)
24    if reference_catalog.isReferenceable(uobject):
25        ob_li_refs = reference_catalog.getReferences(ob, relationship=li_relation)
26        if ob_li_refs:
27            annotations = ob._getReferenceAnnotations()
28            uniqueUIDs = uid_catalog.uniqueValuesFor('UID')
29            # delete references to non-existent objects
30            [annotations._delObject(ref.id) for ref in ob_li_refs \
31             if not ref.targetUID in uniqueUIDs]
32       
33def fix_all(ob):
34    """ Recursive function for perform registered
35        actions for all internal objects
36    """
37    [a(ob) for a in perobject_actions]
38
39    if getattr(ob, 'is_folderish', None):
40        [fix_all(o) for o in ob.objectValues()]
41
42perobject_actions = [fix_archivest, fix_catalog, fix_linkintegrity]
43
44def fix(context):
45    ''' Main fix function: fix defects of importing:
46        imported objects - absence in catalogs, some other issues'''
47    global portal_repository, portal_catalog
48    global uid_catalog, reference_catalog
49    portal_catalog = getToolByName(context,'portal_catalog')
50    portal_repository = getToolByName(context,'portal_repository')
51    uid_catalog = getToolByName(context,'uid_catalog')
52    reference_catalog = getToolByName(context,'reference_catalog')
53
54    fix_all(context)
55
Note: See TracBrowser for help on using the repository browser.