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 ...@@ -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', ()) 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 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, security.declareProtected(Permissions.ManagePortal,
'migrateSourceCodeFromFilesystem') 'migrateSourceCodeFromFilesystem')
def migrateSourceCodeFromFilesystem(self, def migrateSourceCodeFromFilesystem(self,
component_portal_type_dict, version,
erase_existing=False, erase_existing=False,
REQUEST=None,
**kw): **kw):
""" """
Migrate the given components from filesystem to ZODB by calling the Migrate the given components from filesystem to ZODB by calling the
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:
return {}
component_tool = self.getPortalObject().portal_components component_tool = self.getPortalObject().portal_components
failed_import_dict = {} failed_import_dict = {}
def migrate(component_dict, component_class, template_id_list_method):
migrated_id_list = [] template_document_id_list = self.getTemplateDocumentIdList()
for reference, version in component_dict.iteritems(): template_extension_id_list = self.getTemplateExtensionIdList()
template_test_id_list = 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: template_extension_id_list.append(obj.getId())
template_id_list_method(migrated_id_list) elif portal_type == 'Test Component':
template_test_id_list.append(obj.getId())
component_dict = component_portal_type_dict.get('Document Component') # 'Document Component'
if component_dict: else:
from Products.ERP5Type.Core.DocumentComponent import DocumentComponent template_document_id_list.append(obj.getId())
migrate(component_dict, DocumentComponent, self.setTemplateDocumentIdList)
if failed_import_dict:
component_dict = component_portal_type_dict.get('Extension Component') message = (
if component_dict: "The following component could not be imported: " +
from Products.ERP5Type.Core.ExtensionComponent import ExtensionComponent ', '.join([ "%s (%s)" % (name, error)
migrate(component_dict, ExtensionComponent, self.setTemplateExtensionIdList) for name, error in failed_import_dict.iteritems() ]))
component_dict = component_portal_type_dict.get('Test Component') if REQUEST is not None:
if component_dict: return self.Base_redirect('view',
from Products.ERP5Type.Core.TestComponent import TestComponent keep_items={'portal_status_message': message},
migrate(component_dict, TestComponent, self.setTemplateTestIdList) abort_transaction=True)
return failed_import_dict 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 # 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>
......
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