diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py index a3c431f316d1c23f02c854913fed3e0e4fdc12ff..68f29e4ce744e762c80444d4083f87bda8cd7c07 100644 --- a/product/ERP5/Document/BusinessTemplate.py +++ b/product/ERP5/Document/BusinessTemplate.py @@ -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', ()) 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, 'migrateSourceCodeFromFilesystem') def migrateSourceCodeFromFilesystem(self, - component_portal_type_dict, + version, erase_existing=False, **kw): """ @@ -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 Type and then update the Business Template property with migrated IDs """ - if not component_portal_type_dict: - return {} - - component_tool = self.getPortalObject().portal_components + portal = self.getPortalObject() + component_tool = portal.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(): - try: - obj = component_class.importFromFilesystem(component_tool, - reference, - version, - erase_existing) - except Exception, e: - failed_import_dict[reference] = 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) + list_selection_name = kw.get('list_selection_name') - 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) + template_document_id_set = set(self.getTemplateDocumentIdList()) + template_extension_id_set = set(self.getTemplateExtensionIdList()) + template_test_id_set = set(self.getTemplateTestIdList()) - 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 + for temp_obj in self.getMigratableSourceCodeFromFilesystemList(): + try: + obj = temp_obj.importFromFilesystem(component_tool, + temp_obj.getReference(), + version, + erase_existing=erase_existing) + except Exception, e: + failed_import_dict[temp_obj.getReference()] = str(e) + else: + portal_type = obj.getPortalType() + if portal_type == 'Extension Component': + id_set = template_extension_id_set + elif portal_type == 'Test Component': + id_set = template_test_id_set + # 'Document Component' + else: + id_set = template_document_id_set + + id_set.discard(temp_obj.getReference()) + id_set.add(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 list_selection_name is not None: + return self.Base_redirect('view', + 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 # a default class value to None diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getComponentMigratedFromFilesystemList.py b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getComponentMigratedFromFilesystemList.py deleted file mode 100644 index b5f76c8ef0d65d93bc4fef4e532d1aa1c550a4bd..0000000000000000000000000000000000000000 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getComponentMigratedFromFilesystemList.py +++ /dev/null @@ -1,27 +0,0 @@ -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 diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getComponentMigratedFromFilesystemList.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getComponentMigratedFromFilesystemList.xml deleted file mode 100644 index fa812b582bd2ccbdbc26cab85cf1c0eb6c6fc0d0..0000000000000000000000000000000000000000 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getComponentMigratedFromFilesystemList.xml +++ /dev/null @@ -1,62 +0,0 @@ -<?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> diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_migrateSourceCodeFromFilesystem.py b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_migrateSourceCodeFromFilesystem.py deleted file mode 100644 index d6967a4c68e3fe6ec6319486e69fc2265c373a5b..0000000000000000000000000000000000000000 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_migrateSourceCodeFromFilesystem.py +++ /dev/null @@ -1,28 +0,0 @@ -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) diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_migrateSourceCodeFromFilesystem.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_migrateSourceCodeFromFilesystem.xml deleted file mode 100644 index 9e4ed6abe2aa5dcee74f2168765b947bd454472d..0000000000000000000000000000000000000000 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_migrateSourceCodeFromFilesystem.xml +++ /dev/null @@ -1,62 +0,0 @@ -<?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> diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog.xml index c53c7d3ef71e6ada40a548a61df009a787b9db92..e6dee50516fb8359bef18bfadb9ef1e9beb48f24 100644 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog.xml +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog.xml @@ -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> diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/listbox.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/listbox.xml index 1c359d42abf91029b8d691bf87d7b632b88308da..2b7d364e3dd1b326a59ba6312151a653d49f268f 100644 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/listbox.xml +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/listbox.xml @@ -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> diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/my_erase_existing.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/your_erase_existing.xml similarity index 97% rename from product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/my_erase_existing.xml rename to product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/your_erase_existing.xml index 3cdad61e59debcee507c4675a44ae8f95bbe6da3..3add4183ffc413758f4c4cf57c30b2d309a3685c 100644 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/my_erase_existing.xml +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/your_erase_existing.xml @@ -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> diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/listbox_version_item_list.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/your_version.xml similarity index 92% rename from product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/listbox_version_item_list.xml rename to product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/your_version.xml index 1d7bfc734d91e275ec73269b3f19d1b20e1619de..2e78cb2a605f2ba6743f817bba0ed7327f1846e4 100644 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/listbox_version_item_list.xml +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/your_version.xml @@ -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> diff --git a/product/ERP5/tests/testBusinessTemplate.py b/product/ERP5/tests/testBusinessTemplate.py index 35ba127cbe9c262b06a978fc3a4df559eb91fc2d..51a9be37e3a7054b7728ab13ba1d47bb820b908c 100644 --- a/product/ERP5/tests/testBusinessTemplate.py +++ b/product/ERP5/tests/testBusinessTemplate.py @@ -8068,8 +8068,7 @@ class TestDocumentTemplateItem(BusinessTemplateMixin): copied, = template_tool.manage_pasteObjects(cb_data) copied_bt = template_tool._getOb(copied['new_id']) - copied_bt.migrateSourceCodeFromFilesystem( - {self.component_portal_type: {sequence['document_title']: 'erp5'}}) + copied_bt.migrateSourceCodeFromFilesystem(version='erp5') sequence.edit(current_bt=copied_bt)