Skip to content

Commit

Permalink
Merge pull request #61 from plone/fix-geticon-archetypes
Browse files Browse the repository at this point in the history
fix: getIcon for archetypes
  • Loading branch information
jensens committed Dec 3, 2015
2 parents 7f880b7 + ec43e83 commit 0c33e74
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ New:
plone/Products.CMFPlone#124
[fgrcon]

- extended step to501 with reindexing getIcon (#1226)
[fgrcon]
- extended step to501 to recreate metadata for getIcon, see
plone/Products.CMFPlone#1226, #58, #60, #61
[fgrcon, gagaro, jensens]

- Removed fake kupu tool and related settings and resources.
[maurits]
Expand Down
47 changes: 33 additions & 14 deletions plone/app/upgrade/v50/final.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,38 @@ def to501(context):
"""5.0 -> 5.0.1"""
loadMigrationProfile(context, 'profile-plone.app.upgrade.v50:to501')

def reindex_getIcon(context):
def refresh_getIcon_catalog_metadata(context):
"""
get_icon redefined: now boolean:
true if dexterity item is image or has image field (named 'image') e.g. leadimage
get_icon redefined: now boolean:
needs to update metadata
true if item is type image or has image field (named 'image')
e.g. leadimage
see https://github.com/plone/Products.CMFPlone/issues/1226
"""
catalog = getToolByName(context, 'portal_catalog')
search = catalog.unrestrictedSearchResults
cnt=0
iface = "plone.dexterity.interfaces.IDexterityContent"
for brain in search(object_provides=iface):
brain._unrestrictedGetObject().reindexObject(idxs=['getIcon'])
cnt += 1
logger.info('Reindexed `getIcon` for %s dexterity items' % str(cnt))

reindex_getIcon(context)
"""
# Attention, this relies heavily on catalog internals.

# get the more visible zcatalog
zcatalog = getToolByName(context, 'portal_catalog')

# get the more hidden, inner (real) catalog implementation
catalog = zcatalog._catalog
try:
# check if there is a getIcon at all, this may not exist in some
# customizations, who knows, but always exists in default Plone
catalog.names.index('getIcon')
except ValueError:
logger.info('`getIcon` not in metadata, skip upgrade step')
return
cnt = 0
# search whole catalog
for brain in zcatalog.unrestrictedSearchResults():
# create and apply metadata
catalog.data[brain.getRID()] = catalog.recordify(
# wake up object
brain._unrestrictedGetObject()
)
cnt += 1 # we are curious
# done
logger.info('Reindexed `getIcon` for %s items' % str(cnt))

refresh_getIcon_catalog_metadata(context)

0 comments on commit 0c33e74

Please sign in to comment.