plone.app.linkintegrity/master: Merge pull request #56 from plone/allow_inconsistent_refcata

GitHub <jenkins-z4DKO/[email protected]>
Newsgroups gmane.comp.web.zope.plone.cvs
Message-ID <[email protected]>
Repository: plone.app.linkintegrity
Branch: refs/heads/master
Date: 2017-07-17T10:46:05+02:00
Author: Philip Bauer (pbauer) <[email protected]>
Commit: https://github.com/plone/plone.app.linkintegrity/commit/fc6d90f7811913bbf804c03fce44ecb448d46e73

Merge pull request #56 from plone/allow_inconsistent_refcatalog

Do not fail on invalid objects in referenec_catalog. Fixes #32 and #48

Files changed:
M CHANGES.rst
M plone/app/linkintegrity/upgrades.py

diff --git a/CHANGES.rst b/CHANGES.rst
index e2cc5fa..2a0912a 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -14,7 +14,8 @@ New features:
 
 Bug fixes:
 
-- *add item here*
+- Do not fail on invalid objects in referenec_catalog. Fixes #32 and #48
+  [pbauer]
 
 
 3.3.1 (2017-06-01)
diff --git a/plone/app/linkintegrity/upgrades.py b/plone/app/linkintegrity/upgrades.py
index 56d47bf..0a93b8d 100644
--- a/plone/app/linkintegrity/upgrades.py
+++ b/plone/app/linkintegrity/upgrades.py
@@ -5,6 +5,9 @@
 from Products.CMFCore.utils import getToolByName
 from zope.lifecycleevent import modified
 
+import logging
+log = logging.getLogger(__name__)
+
 
 def migrate_linkintegrity_relations(context):
     """Migrate linkintegrity-relation from reference_catalog to zc.relation.
@@ -17,6 +20,10 @@ def migrate_linkintegrity_relations(context):
                 continue
             source_obj = uuidToObject(brain.sourceUID)
             target_obj = uuidToObject(brain.targetUID)
+            if source_obj is None or target_obj is None:
+                # reference_catalog may be inconsistent
+                log.info('Cannot delete relation since the relation_catalog is inconsistent.')   # noqa: E501
+                continue
             # Delete old reference
             reference_catalog.deleteReference(
                 source_obj, target_obj, relationship=referencedRelationship)



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.