Commit f885e66d authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Revamp Business Template 'Migrate Components From Filesystem'.

* Use *Component temp_object instead of ad-hoc dicts (cleanup).
* Select 'version' for all the modules at once instead of per modules (not
  practical when migrating many modules, eg for migrating Products Documents).
* Fix naming of Form Fields (s/my_/your_/).
parent f218b756
...@@ -6293,10 +6293,36 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -6293,10 +6293,36 @@ Business Template is a set of definitions, such as skins, portal types and categ
setattr(self, 'template_portal_type_base_category', ()) setattr(self, 'template_portal_type_base_category', ())
return return
security.declareProtected(Permissions.ManagePortal,
'getMigratableSourceCodeFromFilesystemList')
def getMigratableSourceCodeFromFilesystemList(self, *args, **kwargs):
"""
Return the list of Business Template {Extension, Document, Test} Documents
and Products Documents which can be migrated to ZODB Components.
"""
migratable_component_list = []
component_tool = self.getPortalObject().portal_components
for portal_type, id_list in (
('Document Component', self.getTemplateDocumentIdList()),
('Extension Component', self.getTemplateExtensionIdList()),
('Test Component', self.getTemplateTestIdList())):
for id_ in id_list:
existing_component = getattr(component_tool, id_, None)
if existing_component is None:
obj = component_tool.newContent(id="tmp_source_code_migration_%s" % id_,
portal_type=portal_type,
reference=id_,
temp_object=1)
migratable_component_list.append(obj)
return sorted(migratable_component_list, key=lambda o: o.getReference())
security.declareProtected(Permissions.ManagePortal, security.declareProtected(Permissions.ManagePortal,
'migrateSourceCodeFromFilesystem') 'migrateSourceCodeFromFilesystem')
def migrateSourceCodeFromFilesystem(self, def migrateSourceCodeFromFilesystem(self,
component_portal_type_dict, version,
erase_existing=False, erase_existing=False,
**kw): **kw):
""" """
...@@ -6304,43 +6330,67 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -6304,43 +6330,67 @@ Business Template is a set of definitions, such as skins, portal types and categ
appropriate importFromFilesystem according to the destination Portal appropriate importFromFilesystem according to the destination Portal
Type and then update the Business Template property with migrated IDs Type and then update the Business Template property with migrated IDs
""" """
if not component_portal_type_dict: portal = self.getPortalObject()
return {} component_tool = portal.portal_components
component_tool = self.getPortalObject().portal_components
failed_import_dict = {} failed_import_dict = {}
def migrate(component_dict, component_class, template_id_list_method): list_selection_name = kw.get('list_selection_name')
migrated_id_list = []
for reference, version in component_dict.iteritems(): template_document_id_set = set(self.getTemplateDocumentIdList())
template_extension_id_set = set(self.getTemplateExtensionIdList())
template_test_id_set = set(self.getTemplateTestIdList())
for temp_obj in self.getMigratableSourceCodeFromFilesystemList():
try: try:
obj = component_class.importFromFilesystem(component_tool, obj = temp_obj.importFromFilesystem(component_tool,
reference, temp_obj.getReference(),
version, version,
erase_existing) erase_existing=erase_existing)
except Exception, e: except Exception, e:
failed_import_dict[reference] = str(e) failed_import_dict[temp_obj.getReference()] = str(e)
else: else:
migrated_id_list.append(obj.getId()) portal_type = obj.getPortalType()
if portal_type == 'Extension Component':
if migrated_id_list: id_set = template_extension_id_set
template_id_list_method(migrated_id_list) elif portal_type == 'Test Component':
id_set = template_test_id_set
component_dict = component_portal_type_dict.get('Document Component') # 'Document Component'
if component_dict: else:
from Products.ERP5Type.Core.DocumentComponent import DocumentComponent id_set = template_document_id_set
migrate(component_dict, DocumentComponent, self.setTemplateDocumentIdList)
id_set.discard(temp_obj.getReference())
component_dict = component_portal_type_dict.get('Extension Component') id_set.add(obj.getId())
if component_dict:
from Products.ERP5Type.Core.ExtensionComponent import ExtensionComponent if failed_import_dict:
migrate(component_dict, ExtensionComponent, self.setTemplateExtensionIdList) message = (
"The following component could not be imported: " +
component_dict = component_portal_type_dict.get('Test Component') ', '.join([ "%s (%s)" % (name, error)
if component_dict: for name, error in failed_import_dict.iteritems() ]))
from Products.ERP5Type.Core.TestComponent import TestComponent
migrate(component_dict, TestComponent, self.setTemplateTestIdList) if list_selection_name is not None:
return self.Base_redirect('view',
return failed_import_dict keep_items={'portal_status_message': message},
abort_transaction=True)
transaction.abort()
raise RuntimeError(message)
self.setTemplateDocumentIdList(sorted(template_document_id_set))
self.setTemplateExtensionIdList(sorted(template_extension_id_set))
self.setTemplateTestIdList(sorted(template_test_id_set))
if list_selection_name is not None:
message = (
"All components were successfully imported from filesystem to ZODB. "
"You can now delete them from your instance home and Products.")
if still_used_list_dict:
message = (
message +
" WARNING: Some migrated Documents have their filesystem Document "
"still being imported so code need to be updated (see log file).")
return self.Base_redirect('view',
keep_items={'portal_status_message': message})
# Block acquisition on all _item_name_list properties by setting # Block acquisition on all _item_name_list properties by setting
# a default class value to None # a default class value to None
......
template_document_id_list = context.getTemplateDocumentIdList()
template_extension_id_list = context.getTemplateExtensionIdList()
template_test_id_list = context.getTemplateTestIdList()
if not (template_document_id_list or template_extension_id_list or template_test_id_list):
return []
component_tool = context.getPortalObject().portal_components
from Products.ERP5Type.Document import newTempBase
def addLineListByType(id_list, destination_portal_type, line_list):
for component_id in id_list:
if getattr(component_tool, component_id, None) is not None:
continue
line = newTempBase(context,
'tmp_migrate_%s_%s' % (destination_portal_type, component_id),
uid=component_id,
name=component_id,
destination_portal_type=destination_portal_type)
line_list.append(line)
line_list = []
addLineListByType(template_document_id_list, 'Document Component', line_list)
addLineListByType(template_extension_id_list, 'Extension Component', line_list)
addLineListByType(template_test_id_list, 'Test Component', line_list)
return line_list
<?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>_params</string> </key>
<value> <string>*args, **kwargs</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>BusinessTemplate_getComponentMigratedFromFilesystemList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
request = context.REQUEST
object_list = context.portal_selections.getSelectionValueList(selection_name=request['listbox_list_selection_name'],
context=context,
REQUEST=request)
listbox_dict = request['listbox']
component_dict = {}
for object in object_list:
component_dict.setdefault(object.destination_portal_type,
{})[object.getUid()] = listbox_dict[object.getUrl()]['version_item_list']
failed_import_dict = context.migrateSourceCodeFromFilesystem(component_dict, erase_existing, **kw)
if failed_import_dict:
failed_import_formatted_list = []
for name, error in failed_import_dict.iteritems():
failed_import_formatted_list.append("%s (%s)" % (name, error))
message = "The following component could not be imported: " + ', '.join(failed_import_formatted_list)
abort_transaction = True
else:
message = "All components were successfully imported from filesystem to ZODB. You can now delete them from your instance home."
abort_transaction=False
return context.Base_redirect('view',
keep_items={'portal_status_message': message},
abort_transaction=abort_transaction)
<?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>_params</string> </key>
<value> <string>erase_existing=False, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>BusinessTemplate_migrateSourceCodeFromFilesystem</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
</item> </item>
<item> <item>
<key> <string>action</string> </key> <key> <string>action</string> </key>
<value> <string>BusinessTemplate_migrateSourceCodeFromFilesystem</string> </value> <value> <string>migrateSourceCodeFromFilesystem</string> </value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
...@@ -88,16 +88,15 @@ ...@@ -88,16 +88,15 @@
<item> <item>
<key> <string>hidden</string> </key> <key> <string>hidden</string> </key>
<value> <value>
<list> <list/>
<string>listbox_version_item_list</string>
</list>
</value> </value>
</item> </item>
<item> <item>
<key> <string>left</string> </key> <key> <string>left</string> </key>
<value> <value>
<list> <list>
<string>my_erase_existing</string> <string>your_erase_existing</string>
<string>your_version</string>
</list> </list>
</value> </value>
</item> </item>
......
...@@ -400,16 +400,14 @@ ...@@ -400,16 +400,14 @@
<value> <value>
<list> <list>
<tuple> <tuple>
<string>name</string> <string>reference</string>
<string>Name</string> <string>Name</string>
</tuple> </tuple>
<tuple> <tuple>
<string>destination_portal_type</string>
<string>Destination Portal Type</string>
</tuple> </tuple>
<tuple> <tuple>
<string>version_item_list</string> <string>portal_type</string>
<string>Version</string> <string>Destination Portal Type</string>
</tuple> </tuple>
</list> </list>
</value> </value>
...@@ -454,17 +452,12 @@ ...@@ -454,17 +452,12 @@
</item> </item>
<item> <item>
<key> <string>editable</string> </key> <key> <string>editable</string> </key>
<value> <int>1</int> </value> <value> <int>0</int> </value>
</item> </item>
<item> <item>
<key> <string>editable_columns</string> </key> <key> <string>editable_columns</string> </key>
<value> <value>
<list> <list/>
<tuple>
<string>version_item_list</string>
<string>Version</string>
</tuple>
</list>
</value> </value>
</item> </item>
<item> <item>
...@@ -504,7 +497,7 @@ ...@@ -504,7 +497,7 @@
<item> <item>
<key> <string>list_method</string> </key> <key> <string>list_method</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
<item> <item>
...@@ -630,7 +623,7 @@ ...@@ -630,7 +623,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>method_name</string> </key> <key> <string>method_name</string> </key>
<value> <string>BusinessTemplate_getComponentMigratedFromFilesystemList</string> </value> <value> <string>getMigratableSourceCodeFromFilesystemList</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>my_erase_existing</string> </value> <value> <string>your_erase_existing</string> </value>
</item> </item>
<item> <item>
<key> <string>message_values</string> </key> <key> <string>message_values</string> </key>
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>listbox_version_item_list</string> </value> <value> <string>your_version</string> </value>
</item> </item>
<item> <item>
<key> <string>message_values</string> </key> <key> <string>message_values</string> </key>
...@@ -68,10 +68,18 @@ ...@@ -68,10 +68,18 @@
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value> </value>
</item> </item>
<item>
<key> <string>size</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>target</string> </key> <key> <string>target</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary> </dictionary>
</value> </value>
</item> </item>
......
...@@ -8073,8 +8073,7 @@ class TestDocumentTemplateItem(BusinessTemplateMixin): ...@@ -8073,8 +8073,7 @@ class TestDocumentTemplateItem(BusinessTemplateMixin):
copied, = template_tool.manage_pasteObjects(cb_data) copied, = template_tool.manage_pasteObjects(cb_data)
copied_bt = template_tool._getOb(copied['new_id']) copied_bt = template_tool._getOb(copied['new_id'])
copied_bt.migrateSourceCodeFromFilesystem( copied_bt.migrateSourceCodeFromFilesystem(version='erp5')
{self.component_portal_type: {sequence['document_title']: 'erp5'}})
sequence.edit(current_bt=copied_bt) sequence.edit(current_bt=copied_bt)
......
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