Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add upgrade for get_icon #58

Merged
merged 2 commits into from
Nov 13, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Changelog

New:

- extended step to501 with reindexing get_icon (#1226)
[fgrcon]

- Removed fake kupu tool and related settings and resources.
[maurits]

Expand Down
18 changes: 18 additions & 0 deletions plone/app/upgrade/v50/final.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from plone.app.upgrade.utils import loadMigrationProfile
from plone.dexterity.interfaces import IDexterityContent
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.utils import safe_unicode
Expand Down Expand Up @@ -39,3 +40,20 @@ def _migrate_list(original_id, new_id=None):
def to501(context):
"""5.0 -> 5.0.1"""
loadMigrationProfile(context, 'profile-plone.app.upgrade.v50:to501')

def fix_get_icon(context):
"""
get_icon redefined: now boolean:
true if dexterity item is 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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indexing all indexes is not necessary and may take a long time. Indexing one index is much faster.
I propose to only reindex the specific index like so::

brain._unrestrictedGetObject().reindexObject(idx=['getIcon'])

I double checked if metadata gets updated if idx kwarg is given: This calls in depth then https://github.com/zopefoundation/Products.ZCatalog/blob/2.13.27/src/Products/ZCatalog/Catalog.py#L309 where all metadata is updated even if one index is given.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks , i will mod. when back ... !

cnt += 1
logger.info('Updated `getIcon` for %s dexterity items' % str(cnt))

fix_get_icon(context)