Skip to content

Commit

Permalink
fixup! Add an upgrade step to update the dexterity indexer behavior name
Browse files Browse the repository at this point in the history
  • Loading branch information
ale-rt committed Sep 8, 2022
1 parent 48ba330 commit 4b0a612
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 8 additions & 5 deletions plone/app/upgrade/v60/betas.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,22 @@ def rename_dexteritytextindexer_behavior(context):
"""Rename collective.dexteritytextindexer behavior to plone.textindexer"""
portal_types = getToolByName(context, "portal_types")

# Gather the FTIs that have the obsolete behavior
# Gather the FTIs that have the obsolete behavior,
# it can appear with the name or the interface identifier
old_behaviors = {
"collective.dexteritytextindexer",
"collective.dexteritytextindexer.behavior.IDexterityTextIndexer",
}
ftis_to_fix = (
fti
for fti in portal_types.objectValues("Dexterity FTI")
if "collective.dexteritytextindexer" in fti.behaviors
if set(fti.behaviors) & old_behaviors
)

for fti in ftis_to_fix:
# Rename the behavior
behaviors = [
"plone.textindexer"
if behavior == "collective.dexteritytextindexer"
else behavior
"plone.textindexer" if behavior in old_behaviors else behavior
for behavior in fti.behaviors
]

Expand Down
13 changes: 10 additions & 3 deletions plone/app/upgrade/v60/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,25 @@ def test_rename_dexteritytextindexer_behavior(self):
fti = getUtility(IDexterityFTI, name="Document")

original_behaviors = fti.behaviors

expected_behaviors = original_behaviors + ("plone.textindexer",)
# If the dexteritytextindexer behavior is not present nothing should change
rename_dexteritytextindexer_behavior(portal)
self.assertTupleEqual(fti.behaviors, original_behaviors)

# If the dexteritytextindexer behavior is present it should be renamed
fti.behaviors = fti.behaviors + ("collective.dexteritytextindexer",)
rename_dexteritytextindexer_behavior(portal)
self.assertTupleEqual(fti.behaviors, original_behaviors + ("plone.textindexer",))
self.assertTupleEqual(fti.behaviors, expected_behaviors)

# If the old and new dexteritytextindexer behaviors are present,
# we should only have the new one
fti.behaviors = fti.behaviors + ("collective.dexteritytextindexer",)
rename_dexteritytextindexer_behavior(portal)
self.assertTupleEqual(fti.behaviors, original_behaviors + ("plone.textindexer",))
self.assertTupleEqual(fti.behaviors, expected_behaviors)

# Check that the fix also works with the interface identifier
fti.behaviors = original_behaviors + (
"collective.dexteritytextindexer.behavior.IDexterityTextIndexer",
)
rename_dexteritytextindexer_behavior(portal)
self.assertTupleEqual(fti.behaviors, expected_behaviors)

0 comments on commit 4b0a612

Please sign in to comment.