erp5_upgrader: new feature allowing to rename categories and update objects
<?xml version="1.0"?> | |||
<ZopeData> | |||
<record id="1" aka="AAAAAAAAAAE="> | |||
<pickle> | |||
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/> | |||
</pickle> | |||
<pickle> | |||
<dictionary> | |||
<item> | |||
<key> <string>Script_magic</string> </key> | |||
<value> <int>3</int> </value> | |||
</item> | |||
<item> | |||
<key> <string>_bind_names</string> </key> | |||
<value> | |||
<object> | |||
<klass> | |||
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> | |||
</klass> | |||
<tuple/> | |||
<state> | |||
<dictionary> | |||
<item> | |||
<key> <string>_asgns</string> </key> | |||
<value> | |||
<dictionary> | |||
<item> | |||
<key> <string>name_container</string> </key> | |||
<value> <string>container</string> </value> | |||
</item> | |||
<item> | |||
<key> <string>name_context</string> </key> | |||
<value> <string>context</string> </value> | |||
</item> | |||
<item> | |||
<key> <string>name_m_self</string> </key> | |||
<value> <string>script</string> </value> | |||
</item> | |||
<item> | |||
<key> <string>name_subpath</string> </key> | |||
<value> <string>traverse_subpath</string> </value> | |||
</item> | |||
</dictionary> | |||
</value> | |||
</item> | |||
</dictionary> | |||
</state> | |||
</object> | |||
</value> | |||
</item> | |||
<item> | |||
<key> <string>_body</string> </key> | |||
<value> <string>"""\n | |||
This script should returns a list of tuples, each containing 2 elements \n | |||
- The current name of the category, which was set before the upgrade\n | |||
- The new name of the category\n | |||
|
|||
"""\n | |||
\n | |||
return None\n | |||
</string> </value> | |||
</item> | |||
<item> | |||
<key> <string>_params</string> </key> | |||
<value> <string></string> </value> | |||
</item> | |||
<item> | |||
<key> <string>id</string> </key> | |||
<value> <string>Base_getUpgradeCategoryNameList</string> </value> | |||
</item> | |||
</dictionary> | |||
</pickle> | |||
</record> | |||
</ZopeData> |
<?xml version="1.0"?> | |||
<ZopeData> | |||
<record id="1" aka="AAAAAAAAAAE="> | |||
<pickle> | |||
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/> | |||
</pickle> | |||
<pickle> | |||
<dictionary> | |||
<item> | |||
<key> <string>Script_magic</string> </key> | |||
<value> <int>3</int> </value> | |||
</item> | |||
<item> | |||
<key> <string>_bind_names</string> </key> | |||
<value> | |||
<object> | |||
<klass> | |||
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> | |||
</klass> | |||
<tuple/> | |||
<state> | |||
<dictionary> | |||
<item> | |||
<key> <string>_asgns</string> </key> | |||
<value> | |||
<dictionary> | |||
<item> | |||
<key> <string>name_container</string> </key> | |||
<value> <string>container</string> </value> | |||
</item> | |||
<item> | |||
<key> <string>name_context</string> </key> | |||
<value> <string>context</string> </value> | |||
</item> | |||
<item> | |||
<key> <string>name_m_self</string> </key> | |||
<value> <string>script</string> </value> | |||
</item> | |||
<item> | |||
<key> <string>name_subpath</string> </key> | |||
<value> <string>traverse_subpath</string> </value> | |||
</item> | |||
</dictionary> | |||
</value> | |||
</item> | |||
</dictionary> | |||
</state> | |||
</object> | |||
</value> | |||
</item> | |||
<item> | |||
<key> <string>_body</string> </key> | |||
<value> <string># This script is called as a "script constraint"\n | |||
# It will replace an old category name by a new name, and update all related\n | |||
|
|||
# objects.\n | |||
# To get the list of changes, we use the same idea as in TemplateTool_checkBusinessTemplateInstallation :\n | |||
# we get a list of tuples containing the old names and new names from a Script (Python),\n | |||
# which should be overriden in the custom sites\' upgraders.\n | |||
# Because this script is called during the post-upgrade phase, we are\n | |||
# looking for the category by its new name.\n | |||
\n | |||
portal = context.getPortalObject()\n | |||
\n | |||
error_list = []\n | |||
\n | |||
upgrade_list = context.Base_getUpgradeCategoryNameList()\n | |||
\n | |||
if not upgrade_list:\n | |||
return []\n | |||
\n | |||
for old_category_name, new_category_name in upgrade_list:\n | |||
\n | |||
sensitive_portal_types = []\n | |||
|
|||
\n | |||
# We gather portal types having the new category defined as a property\n | |||
for portal_type in portal.portal_types.listTypeInfo():\n | |||
if new_category_name in portal_type.getInstancePropertyAndBaseCategoryList():\n | |||
sensitive_portal_types.append(portal_type.getId())\n | |||
\n | |||
# if sensitive_portal_types is empty, we don\'t want to check all objects\n | |||
if fixit and sensitive_portal_types:\n | |||
updateRelatedCategory = portal.portal_categories.updateRelatedCategory\n | |||
\n | |||
# We list objects defined by the sensitive portal types\n | |||
for obj in portal.portal_catalog(portal_type=sensitive_portal_types):\n | |||
|
|||
obj = obj.getObject()\n | |||
new_categories_list = []\n | |||
obj_categories_list = obj.getCategoriesList()\n | |||
for category in obj_categories_list:\n | |||
new_category = updateRelatedCategory(category, old_category_name, new_category_name)\n | |||
new_categories_list.append(new_category)\n | |||
if new_categories_list != obj_categories_list:\n | |||
obj.setCategoriesList(new_categories_list)\n | |||
\n | |||
for portal_type in sensitive_portal_types:\n | |||
error_list.append(\'Portal Type %s still contains the category %s\' % (portal_type, old_category_name))\n | |||
\n | |||
return error_list\n | |||
</string> </value> | |||
</item> | |||
<item> | |||
<key> <string>_params</string> </key> | |||
<value> <string>fixit=False, **kw</string> </value> | |||
</item> | |||
<item> | |||
<key> <string>id</string> </key> | |||
<value> <string>CategoryTool_checkCategoryNameConsistency</string> </value> | |||
</item> | |||
</dictionary> | |||
</pickle> | |||
</record> | |||
</ZopeData> |