Commit 199250fd 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 c9868753
......@@ -6293,54 +6293,100 @@ Business Template is a set of definitions, such as skins, portal types and categ
setattr(self, 'template_portal_type_base_category', ())
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 or
existing_component.getPortalType() != portal_type):
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,
'migrateSourceCodeFromFilesystem')
def migrateSourceCodeFromFilesystem(self,
component_portal_type_dict,
version,
erase_existing=False,
REQUEST=None,
**kw):
"""
Migrate the given components from filesystem to ZODB by calling the
appropriate importFromFilesystem according to the destination Portal
Type and then update the Business Template property with migrated IDs
"""
if not component_portal_type_dict:
return {}
component_tool = self.getPortalObject().portal_components
failed_import_dict = {}
def migrate(component_dict, component_class, template_id_list_method):
migrated_id_list = []
for reference, version in component_dict.iteritems():
template_document_id_list = self.getTemplateDocumentIdList()
template_extension_id_list = self.getTemplateExtensionIdList()
template_test_id_list = self.getTemplateTestIdList()
for temp_obj in self.getMigratableSourceCodeFromFilesystemList():
try:
obj = component_class.importFromFilesystem(component_tool,
reference,
obj = temp_obj.importFromFilesystem(component_tool,
temp_obj.getReference(),
version,
erase_existing)
erase_existing=erase_existing)
except Exception, e:
failed_import_dict[reference] = str(e)
failed_import_dict[temp_obj.getReference()] = str(e)
else:
migrated_id_list.append(obj.getId())
if migrated_id_list:
template_id_list_method(migrated_id_list)
component_dict = component_portal_type_dict.get('Document Component')
if component_dict:
from Products.ERP5Type.Core.DocumentComponent import DocumentComponent
migrate(component_dict, DocumentComponent, self.setTemplateDocumentIdList)
component_dict = component_portal_type_dict.get('Extension Component')
if component_dict:
from Products.ERP5Type.Core.ExtensionComponent import ExtensionComponent
migrate(component_dict, ExtensionComponent, self.setTemplateExtensionIdList)
component_dict = component_portal_type_dict.get('Test Component')
if component_dict:
from Products.ERP5Type.Core.TestComponent import TestComponent
migrate(component_dict, TestComponent, self.setTemplateTestIdList)
return failed_import_dict
portal_type = obj.getPortalType()
if portal_type == 'Extension Component':
template_extension_id_list.append(obj.getId())
elif portal_type == 'Test Component':
template_test_id_list.append(obj.getId())
# 'Document Component'
else:
template_document_id_list.append(obj.getId())
if failed_import_dict:
message = (
"The following component could not be imported: " +
', '.join([ "%s (%s)" % (name, error)
for name, error in failed_import_dict.iteritems() ]))
if REQUEST is not None:
return self.Base_redirect('view',
keep_items={'portal_status_message': message},
abort_transaction=True)
raise RuntimeError(message)
self.setTemplateDocumentIdList(sorted(template_document_id_list))
self.setTemplateExtensionIdList(sorted(template_extension_id_list))
self.setTemplateTestIdList(sorted(template_test_id_list))
if REQUEST 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
# 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 @@
</item>
<item>
<key> <string>action</string> </key>
<value> <string>BusinessTemplate_migrateSourceCodeFromFilesystem</string> </value>
<value> <string>migrateSourceCodeFromFilesystem</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -88,16 +88,15 @@
<item>
<key> <string>hidden</string> </key>
<value>
<list>
<string>listbox_version_item_list</string>
</list>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list>
<string>my_erase_existing</string>
<string>your_erase_existing</string>
<string>your_version</string>
</list>
</value>
</item>
......
......@@ -400,16 +400,14 @@
<value>
<list>
<tuple>
<string>name</string>
<string>reference</string>
<string>Name</string>
</tuple>
<tuple>
<string>destination_portal_type</string>
<string>Destination Portal Type</string>
</tuple>
<tuple>
<string>version_item_list</string>
<string>Version</string>
<string>portal_type</string>
<string>Destination Portal Type</string>
</tuple>
</list>
</value>
......@@ -454,17 +452,12 @@
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>1</int> </value>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>editable_columns</string> </key>
<value>
<list>
<tuple>
<string>version_item_list</string>
<string>Version</string>
</tuple>
</list>
<list/>
</value>
</item>
<item>
......@@ -504,7 +497,7 @@
<item>
<key> <string>list_method</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
......@@ -630,7 +623,7 @@
<dictionary>
<item>
<key> <string>method_name</string> </key>
<value> <string>BusinessTemplate_getComponentMigratedFromFilesystemList</string> </value>
<value> <string>getMigratableSourceCodeFromFilesystemList</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -16,7 +16,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_erase_existing</string> </value>
<value> <string>your_erase_existing</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
......
......@@ -18,7 +18,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>listbox_version_item_list</string> </value>
<value> <string>your_version</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
......@@ -68,10 +68,18 @@
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>size</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
......
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