Commit 2661fc03 authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_upgrader: TemplateTool_checkCategoryNameConsistency constraint now runs...

erp5_upgrader: TemplateTool_checkCategoryNameConsistency constraint now runs only one activity per object susceptible of being updated, instead of one per object and per declared change.

This commit divides the number of activities runned by the length of the list returned by Base_getUpgradeCategoryNameList
parent 0186ac99
portal = context.getPortalObject()
updateRelatedCategory = portal.portal_categories.updateRelatedCategory
new_category_list = []
object_category_list = context.getCategoriesList()
old_category_list = object_category_list[::]
new_category_name = kw['new_category_name']
old_category_name = kw['old_category_name']
upgrade_list = kw['upgrade_list']
for category in object_category_list:
new_category = updateRelatedCategory(category, old_category_name, new_category_name)
new_category_list.append(new_category)
for old_category_name, new_category_name in upgrade_list:
new_category_list = []
if new_category_list != object_category_list:
for category in object_category_list:
new_category = updateRelatedCategory(category, old_category_name, new_category_name)
new_category_list.append(new_category)
# object_category_list becomes new_category_list for the next loop
# (several categories can change during a same upgrade)
object_category_list = new_category_list[::]
# Write only once in case of change
if old_category_list != new_category_list:
context.setCategoriesList(new_category_list)
......@@ -9,6 +9,7 @@
portal = context.getPortalObject()
sensitive_portal_type_list = []
error_list = []
upgrade_list = context.Base_getUpgradeCategoryNameList()
......@@ -18,7 +19,6 @@ if not upgrade_list:
for old_category_name, new_category_name in upgrade_list:
sensitive_portal_type_list = []
new_base_category_id = new_category_name.split('/')[0]
# We gather portal types having the new category defined as a property
......@@ -26,17 +26,16 @@ for old_category_name, new_category_name in upgrade_list:
if new_base_category_id in portal_type.getInstancePropertyAndBaseCategoryList():
sensitive_portal_type_list.append(portal_type.getId())
# if sensitive_portal_type_list is empty, we don't want to check all objects
if fixit and sensitive_portal_type_list:
context.portal_catalog.searchAndActivate('Base_updateRelatedCategory',
activate_kw=activate_kw,
portal_type=sensitive_portal_type_list,
method_kw={'fixit': fixit,
'old_category_name': old_category_name,
'new_category_name': new_category_name,}
)
for portal_type in sensitive_portal_type_list:
error_list.append('Portal Type %s still contains the category %s' % (portal_type, old_category_name))
# if sensitive_portal_type_list is empty, we don't want to check all objects
if fixit and sensitive_portal_type_list:
context.portal_catalog.searchAndActivate('Base_updateRelatedCategory',
activate_kw=activate_kw,
portal_type=sensitive_portal_type_list,
method_kw={'fixit': fixit,
'upgrade_list': upgrade_list,}
)
for portal_type in sensitive_portal_type_list:
error_list.append('Portal Type %s still contains the category %s' % (portal_type, old_category_name))
return error_list
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment