-
Notifications
You must be signed in to change notification settings - Fork 3
/
__init__.py
48 lines (40 loc) · 1.72 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding:utf-8 -*-
from collective.nitf.config import PROJECTNAME
from plone.app.upgrade.utils import loadMigrationProfile
import logging
def fix_collections(context):
"""Update to 1008 version."""
logger = logging.getLogger(PROJECTNAME)
collections = context.portal_catalog(portal_type='Collection')
logger.info('About to update {0} objects'.format(len(collections)))
for col in collections:
obj = col.getObject()
# XXX: To fix the query we need a list of dicts describing it.
# With collections based on Archetypes we use getRawQuery;
# with collections based on Dexterity (e.g., if
# plone.app.contenttypes is installed) we need to use
# getQuery because we have an API inconsistency.
# See: https://github.com/plone/plone.app.contenttypes/issues/283
try:
query = obj.getRawQuery() # Archetypes
except AttributeError:
query = obj.getQuery() # Dexterity
if query is None:
continue # collection has no query defined
fixed_query = []
for item in query:
fixed_item = dict(item)
if item['i'] == 'urgency':
fixed_item['o'] = 'plone.app.querystring.operation.intselection.is'
fixed_query.append(fixed_item)
obj.setQuery(fixed_query)
logger.info(
'Collection %s at %s updated' % (col.id, col.getPath())
)
logger.info('Done')
def apply_profile(context):
"""Update to 1008 version."""
logger = logging.getLogger(PROJECTNAME)
profile = 'profile-collective.nitf.upgrades.v1008:default'
loadMigrationProfile(context, profile)
logger.info('Updated to version 1008')