| 1 |
from Acquisition import aq_base |
|---|
| 2 |
from Products.CMFCore.utils import getToolByName |
|---|
| 3 |
from Products.ZCatalog.ProgressHandler import ZLogHandler |
|---|
| 4 |
from plone.app.linkintegrity.handlers import referencedRelationship as li_relation |
|---|
| 5 |
|
|---|
| 6 |
portal_catalog = None |
|---|
| 7 |
portal_repository = None |
|---|
| 8 |
uid_catalog = None |
|---|
| 9 |
reference_catalog = None |
|---|
| 10 |
|
|---|
| 11 |
def 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 |
|
|---|
| 18 |
def fix_catalog(ob): |
|---|
| 19 |
ob.reindexObject() |
|---|
| 20 |
|
|---|
| 21 |
def 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 |
|
|---|
| 30 |
[annotations._delObject(ref.id) for ref in ob_li_refs \ |
|---|
| 31 |
if not ref.targetUID in uniqueUIDs] |
|---|
| 32 |
|
|---|
| 33 |
def 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 |
|
|---|
| 42 |
perobject_actions = [fix_archivest, fix_catalog, fix_linkintegrity] |
|---|
| 43 |
|
|---|
| 44 |
def 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 |
|
|---|