diff --git a/ftw/catalogdoctor/surgery.py b/ftw/catalogdoctor/surgery.py index 69fc011..6f56f12 100644 --- a/ftw/catalogdoctor/surgery.py +++ b/ftw/catalogdoctor/surgery.py @@ -269,6 +269,29 @@ def perform(self): self.change_catalog_length(-1) +class ReindexMissingUUID(Surgery): + """Reindex an uuid which is partially missing from the UID index. + + Simply reindexing the object restores the consistent catalog state. + """ + def perform(self): + if len(self.unhealthy_rid.paths) != 1: + raise CantPerformSurgery( + "Expected exactly one affected path, got: {}" + .format(", ".join(self.unhealthy_rid.paths))) + + path = list(self.unhealthy_rid.paths)[0] + + portal = api.portal.get() + obj = portal.unrestrictedTraverse(path, None) + if obj is None: + raise CantPerformSurgery( + "Missing object at {}".format(path)) + + obj.reindexObject() + self.surgery_log.append("Reindexed object in catalog.") + + class CatalogDoctor(object): """Performs surgery for an unhealthy_rid, if possible. @@ -291,6 +314,10 @@ class CatalogDoctor(object): 'in_uuid_unindex_not_in_catalog', 'in_uuid_unindex_not_in_uuid_index', ): RemoveOrphanedRid, + ( + 'in_catalog_not_in_uuid_index', + 'in_uuid_unindex_not_in_uuid_index', + ): ReindexMissingUUID, } def __init__(self, catalog, unhealthy_rid):