Skip to content

Commit

Permalink
Merge pull request #62 from plone/fix-getIcon-to501
Browse files Browse the repository at this point in the history
fix: update getIcon metadata only in to501
  • Loading branch information
jensens committed Dec 4, 2015
2 parents 0c33e74 + 24de095 commit c6bb01d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions plone/app/upgrade/v50/final.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,27 @@ def refresh_getIcon_catalog_metadata(context):
# get the more hidden, inner (real) catalog implementation
catalog = zcatalog._catalog
try:
# Get the getIcon index value and
# 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')
metadata_index = 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()
)
# First get the new value
obj = brain._unrestrictedGetObject()
new_value = bool(getattr(obj.aq_base, 'image', False))

# We can now update the record with the new getIcon value
record = list(catalog.data[brain.getRID()])
record[metadata_index] = new_value
catalog.data[brain.getRID()] = tuple(record)

cnt += 1 # we are curious
# done
logger.info('Reindexed `getIcon` for %s items' % str(cnt))
Expand Down

0 comments on commit c6bb01d

Please sign in to comment.