Remove item from reference_catalog if it's UID is gone or purge broken reference_catalog in Plone

StackOverflow https://stackoverflow.com/questions/22517334

  •  17-06-2023
  •  | 
  •  

Question

I have the following situation with LinguaPlone

  • I have pages a1-en, a1-fi an a1-sv

  • a1-fi and a1-sv think a1-en is the canonical translation

  • a1-en isCanonical() returns False

  • This is because isCanonical() checks if there are "translation of" references for the current item

  • a1-en is one unlucky page, as there is actually "translation of" reference, but it is a broken reference where the item pointed by UID reference is gone. (It checks only references by UID, not if the actual content item exists).

Now, I need to fix this situation somehow to make a1-en believe that it is canonical page again. I need to remove this one corrupted reference from the reference_catalog from "sourceUID" index which is being checked.

Questions

  • Are there automatic ways to maintain reference_catalog and clear broken entries

  • If not is what is the manual way to fix this one broken entry in reference_catalog

Was it helpful?

Solution

Like this:

badCanonical = app.Plone.en.offering.restaurants
badCanonical.isCanonical()  # False - contains a corrupted translationOf link
badCanonical.getTranslations()   # Get list of what translations should exist
cat = app.Plone.reference_catalog
cat.getReferences(badCanonical, relationship="translationOf")  # Displays UID referring object not existing
# Delete forward relationships
for b in cat.getReferences(badCanonical, "translationOf"): cat._deleteReference(b)  
badCanonical.isCanonical()  # True - fixed
badCanonical.getTranslations() 

# Check that one of the translated versions still work
translated = app.Plone.sv["kalajoki-erbjuder"].restauranger
translated.isCanonical()
translated.getTranslations()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top