From 1f4715f15d8d4a5d9771cfefd8a02dfb66577ec3 Mon Sep 17 00:00:00 2001
From: Arnaud Fontaine <arnaud.fontaine@nexedi.com>
Date: Sun, 26 Feb 2012 14:10:23 +0900
Subject: [PATCH] Add a Python script for migration to avoid performing the
 redirect into BusinessTemplate class.

Also, Rename *MigrateAllComponentFromFilesystem to *MigrateSourceCodeFromFilesystem.
---
 product/ERP5/Document/BusinessTemplate.py     | 26 ++----
 .../migrate_component_from_filesystem.xml     |  2 +-
 ...mplate_migrateSourceCodeFromFilesystem.xml | 79 +++++++++++++++++++
 ...MigrateSourceCodeFromFilesystemDialog.xml} |  6 +-
 .../listbox.xml                               |  0
 .../my_erase_existing.xml                     |  0
 .../my_version_priority.xml                   |  0
 .../ERP5/bootstrap/erp5_core/bt/change_log    |  4 +
 product/ERP5/bootstrap/erp5_core/bt/revision  |  2 +-
 9 files changed, 95 insertions(+), 24 deletions(-)
 create mode 100644 product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_migrateSourceCodeFromFilesystem.xml
 rename product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/{BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog.xml => BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog.xml} (93%)
 rename product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/{BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog => BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog}/listbox.xml (100%)
 rename product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/{BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog => BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog}/my_erase_existing.xml (100%)
 rename product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/{BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog => BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog}/my_version_priority.xml (100%)

diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py
index 19b22f40c3..a0c7149a26 100644
--- a/product/ERP5/Document/BusinessTemplate.py
+++ b/product/ERP5/Document/BusinessTemplate.py
@@ -5761,12 +5761,12 @@ 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.ModifyPortalContent,
-                              'migrateAllComponentFromFilesystem')
-    def migrateAllComponentFromFilesystem(self,
-                                          version_priority,
-                                          erase_existing=False,
-                                          **kw):
+    security.declareProtected(Permissions.ManagePortal,
+                              'migrateSourceCodeFromFilesystem')
+    def migrateSourceCodeFromFilesystem(self,
+                                        version_priority,
+                                        erase_existing=False,
+                                        **kw):
       component_tool = self.getPortalObject().portal_components
       failed_import_dict = {}
 
@@ -5802,19 +5802,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
 
       self.setTemplateExtensionIdList(extension_id_list)
 
-      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: %s" % \
-            ', '.join(failed_import_formatted_list)
-      else:
-        message = "All components were successfully imported " \
-            "from filesystem to ZODB."
-
-      return self.Base_redirect('view',
-                                keep_items={'portal_status_message': message})
+      return failed_import_dict
 
 # Block acquisition on all _item_name_list properties by setting
 # a default class value to None
diff --git a/product/ERP5/bootstrap/erp5_core/ActionTemplateItem/portal_types/Business%20Template/migrate_component_from_filesystem.xml b/product/ERP5/bootstrap/erp5_core/ActionTemplateItem/portal_types/Business%20Template/migrate_component_from_filesystem.xml
index 9c4c83ac7f..485c91b84b 100644
--- a/product/ERP5/bootstrap/erp5_core/ActionTemplateItem/portal_types/Business%20Template/migrate_component_from_filesystem.xml
+++ b/product/ERP5/bootstrap/erp5_core/ActionTemplateItem/portal_types/Business%20Template/migrate_component_from_filesystem.xml
@@ -77,7 +77,7 @@
       <dictionary>
         <item>
             <key> <string>text</string> </key>
-            <value> <string>string:${object_url}/BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog</string> </value>
+            <value> <string>string:${object_url}/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog</string> </value>
         </item>
       </dictionary>
     </pickle>
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
new file mode 100644
index 0000000000..3bcc6668e6
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_migrateSourceCodeFromFilesystem.xml
@@ -0,0 +1,79 @@
+<?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>failed_import_dict = context.migrateSourceCodeFromFilesystem(version_priority, erase_existing, **kw)\n
+\n
+if failed_import_dict:\n
+ failed_import_formatted_list = []\n
+ for name, error in failed_import_dict.iteritems():\n
+  failed_import_formatted_list.append("%s (%s)" % (name, error))\n
+\n
+ message = "The following component could not be imported: %s" % \', \'.join(failed_import_formatted_list)\n
+else:\n
+ message = "All components were successfully imported from filesystem to ZODB."\n
+\n
+return context.Base_redirect(\'view\',\n
+                             keep_items={\'portal_status_message\': message})\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>version_priority, 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_viewMigrateAllComponentFromFilesystemDialog.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog.xml
similarity index 93%
rename from product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog.xml
rename to product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog.xml
index 19d6c83a45..c090a6bcef 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog.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>migrateAllComponentFromFilesystem</string> </value>
+            <value> <string>BusinessTemplate_migrateSourceCodeFromFilesystem</string> </value>
         </item>
         <item>
             <key> <string>description</string> </key>
@@ -111,7 +111,7 @@
         </item>
         <item>
             <key> <string>id</string> </key>
-            <value> <string>BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog</string> </value>
+            <value> <string>BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog</string> </value>
         </item>
         <item>
             <key> <string>method</string> </key>
@@ -119,7 +119,7 @@
         </item>
         <item>
             <key> <string>name</string> </key>
-            <value> <string>BusinessTemplate_viewMigrateAllComponentFromFilesystem</string> </value>
+            <value> <string>BusinessTemplate_viewMigrateSourceCodeFromFilesystem</string> </value>
         </item>
         <item>
             <key> <string>pt</string> </key>
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog/listbox.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/listbox.xml
similarity index 100%
rename from product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog/listbox.xml
rename to product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/listbox.xml
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog/my_erase_existing.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/my_erase_existing.xml
similarity index 100%
rename from product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog/my_erase_existing.xml
rename to product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/my_erase_existing.xml
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog/my_version_priority.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/my_version_priority.xml
similarity index 100%
rename from product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateAllComponentFromFilesystemDialog/my_version_priority.xml
rename to product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewMigrateSourceCodeFromFilesystemDialog/my_version_priority.xml
diff --git a/product/ERP5/bootstrap/erp5_core/bt/change_log b/product/ERP5/bootstrap/erp5_core/bt/change_log
index 3209e669a7..92d0750cda 100644
--- a/product/ERP5/bootstrap/erp5_core/bt/change_log
+++ b/product/ERP5/bootstrap/erp5_core/bt/change_log
@@ -1,3 +1,7 @@
+2012-02-25 arnaud.fontaine
+* Add a Python script which performs the redirect rather than doing it in BusinessTemplate class.
+* Rename *MigrateAllComponentFromFilesystem to *MigrateSourceCodeFromFilesystem.
+
 2012-02-25 arnaud.fontaine
 * Rename Component modified transition to modify as per naming conventions.
 
diff --git a/product/ERP5/bootstrap/erp5_core/bt/revision b/product/ERP5/bootstrap/erp5_core/bt/revision
index e010b88207..9f02e3a811 100644
--- a/product/ERP5/bootstrap/erp5_core/bt/revision
+++ b/product/ERP5/bootstrap/erp5_core/bt/revision
@@ -1 +1 @@
-41010
\ No newline at end of file
+41011
\ No newline at end of file
-- 
GitLab