Skip to content

Commit 26d8ea2

Browse files
committed
Added upgrade step to added approved field
1 parent 56d1496 commit 26d8ea2

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/collective/iconifiedcategory/profiles/default/metadata.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<metadata>
3-
<version>2106</version>
3+
<version>2107</version>
44
<dependencies>
55
<dependency>profile-collective.documentviewer:default</dependency>
66
<dependency>profile-collective.fontawesome:default</dependency>

src/collective/iconifiedcategory/upgrades.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,31 @@ def upgrade_to_2105(context):
212212
def upgrade_to_2106(context):
213213
load_type_from_package('ContentCategoryConfiguration', 'profile-collective.iconifiedcategory:default')
214214
remove_gs_step('collective.iconifiedcategory:default-postInstall')
215+
216+
217+
def upgrade_to_2107(context):
218+
''' '''
219+
portal_types = _portal_types_using_behavior()
220+
catalog = api.portal.get_tool('portal_catalog')
221+
brains = catalog(portal_type=portal_types)
222+
223+
logger.info('Querying elements to update among "{0}" objects of portal_type "{1}"'.format(
224+
len(brains), ', '.join(portal_types)))
225+
parents_to_update = []
226+
for brain in brains:
227+
obj = brain.getObject()
228+
if not(base_hasattr(obj, 'approved')):
229+
setattr(obj, 'approved', False)
230+
231+
parent = obj.aq_parent
232+
if parent not in parents_to_update:
233+
parents_to_update.append(parent)
234+
235+
# finally update parents that contains categorized elements
236+
nb_of_parents_to_update = len(parents_to_update)
237+
i = 1
238+
for parent_to_update in parents_to_update:
239+
logger.info('Running update_all_categorized_elements for element {0}/{1} ({2})'.format(
240+
i, nb_of_parents_to_update, '/'.join(parent_to_update.getPhysicalPath())))
241+
i = i + 1
242+
update_all_categorized_elements(parent_to_update)

src/collective/iconifiedcategory/upgrades.zcml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,12 @@
6161
handler="collective.iconifiedcategory.upgrades.upgrade_to_2106"
6262
profile="collective.iconifiedcategory:default" />
6363

64+
<genericsetup:upgradeStep
65+
title="Updated ContentCategoryConfiguration type"
66+
description=""
67+
source="2106"
68+
destination="2107"
69+
handler="collective.iconifiedcategory.upgrades.upgrade_to_2107"
70+
profile="collective.iconifiedcategory:default" />
71+
6472
</configure>

0 commit comments

Comments
 (0)