from Products.ZSQLCatalog.SQLCatalog import Query, SimpleQuery, ComplexQuery

portal = context.getPortalObject()
portal_catalog = portal.portal_catalog

portal_type_query = ComplexQuery(Query(portal_type='Data Stream'),
                                 Query(portal_type='Data Array'),
                                 Query(portal_type='Data Descriptor'),
                                 Query(portal_type='Data Ingestion'),
                                 Query(portal_type='Data Analysis'),
                                 logical_operator="OR")
kw_dict = {"query": portal_type_query,
           "reference": reference}
try:
  for document in portal_catalog(**kw_dict):
    if not document.getReference().endswith("_invalid"):
      document.setReference(document.getReference() + "_invalid")
      try:
        document.invalidate()
      except:
        pass # fails if it's already invalidated, draft or if it doens't allow invalidation (e.g. DI)
except Exception as e:
  context.logEntry("[ERROR] Error invalidating objects for reference '%s': %s" % (reference, str(e)))
