From 8921803e04974b94a3bab8974ddcee5c9b0a2bb0 Mon Sep 17 00:00:00 2001
From: Tristan Cavelier <tristan.cavelier@tiolive.com>
Date: Wed, 12 Nov 2014 15:34:58 +0100
Subject: [PATCH] Update erp5_upgrader business template

- Rename some upgrader scripts
- Add upgrader script to check for table existence
- Rename some upgrade constraints
- Add upgrade constraint (table existence)
- Clean up some files
---
 .../property_sheet_list.xml                   |  4 +-
 ...BusinessTemplateInstallationConstraint.xml | 66 ++++++++++++++
 ...ness_template_installation_constraint.xml} |  4 +-
 ... TemplateToolTableExistenceConstraint.xml} |  2 +-
 .../table_existence_constraint.xml}           |  4 +-
 ...oolWorkflowChainConsistencyConstraint.xml} |  2 +-
 .../workflow_chain_consistency_constraint.xml | 80 +++++++++++++++++
 ...ool_checkBusinessTemplateInstallation.xml} |  2 +-
 .../TemplateTool_checkTableExistence.xml      | 86 +++++++++++++++++++
 ...ateTool_checkWorkflowChainConsistency.xml} |  2 +-
 .../template_portal_type_property_sheet_list  |  5 +-
 .../bt/template_property_sheet_id_list        |  5 +-
 bt5/erp5_upgrader/bt/test_dependency_list     |  2 +-
 13 files changed, 250 insertions(+), 14 deletions(-)
 create mode 100644 bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolBusinessTemplateInstallationConstraint.xml
 rename bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/{TemplateToolUpgraderConstraint/business_template_installed_constraint.xml => TemplateToolBusinessTemplateInstallationConstraint/business_template_installation_constraint.xml} (92%)
 rename bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/{TemplateToolPostUpgradeConstraint.xml => TemplateToolTableExistenceConstraint.xml} (95%)
 rename bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/{TemplateToolPostUpgradeConstraint/workflow_chain_constraint.xml => TemplateToolTableExistenceConstraint/table_existence_constraint.xml} (92%)
 rename bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/{TemplateToolUpgraderConstraint.xml => TemplateToolWorkflowChainConsistencyConstraint.xml} (94%)
 create mode 100644 bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolWorkflowChainConsistencyConstraint/workflow_chain_consistency_constraint.xml
 rename bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/{TemplateTool_checkUpgradeConsistency.xml => TemplateTool_checkBusinessTemplateInstallation.xml} (96%)
 create mode 100644 bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkTableExistence.xml
 rename bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/{TemplateTool_checkPostUpgradeWorkflowChainConsistency.xml => TemplateTool_checkWorkflowChainConsistency.xml} (97%)

diff --git a/bt5/erp5_upgrader/PortalTypePropertySheetTemplateItem/property_sheet_list.xml b/bt5/erp5_upgrader/PortalTypePropertySheetTemplateItem/property_sheet_list.xml
index 4d9dfac0f9..59a6bbff6c 100644
--- a/bt5/erp5_upgrader/PortalTypePropertySheetTemplateItem/property_sheet_list.xml
+++ b/bt5/erp5_upgrader/PortalTypePropertySheetTemplateItem/property_sheet_list.xml
@@ -1,5 +1,7 @@
 <property_sheet_list>
  <portal_type id="Template Tool">
-  <item>TemplateToolUpgraderConstraint</item>
+  <item>TemplateToolBusinessTemplateInstallationConstraint</item>
+  <item>TemplateToolTableExistenceConstraint</item>
+  <item>TemplateToolWorkflowChainConsistencyConstraint</item>
  </portal_type>
 </property_sheet_list>
\ No newline at end of file
diff --git a/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolBusinessTemplateInstallationConstraint.xml b/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolBusinessTemplateInstallationConstraint.xml
new file mode 100644
index 0000000000..53ddadc6a1
--- /dev/null
+++ b/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolBusinessTemplateInstallationConstraint.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="Property Sheet" module="erp5.portal_type"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_count</string> </key>
+            <value>
+              <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+            </value>
+        </item>
+        <item>
+            <key> <string>_mt_index</string> </key>
+            <value>
+              <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
+            </value>
+        </item>
+        <item>
+            <key> <string>_tree</string> </key>
+            <value>
+              <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
+            </value>
+        </item>
+        <item>
+            <key> <string>description</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>TemplateToolBusinessTemplateInstallationConstraint</string> </value>
+        </item>
+        <item>
+            <key> <string>portal_type</string> </key>
+            <value> <string>Property Sheet</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="2" aka="AAAAAAAAAAI=">
+    <pickle>
+      <global name="Length" module="BTrees.Length"/>
+    </pickle>
+    <pickle> <int>0</int> </pickle>
+  </record>
+  <record id="3" aka="AAAAAAAAAAM=">
+    <pickle>
+      <global name="OOBTree" module="BTrees.OOBTree"/>
+    </pickle>
+    <pickle>
+      <none/>
+    </pickle>
+  </record>
+  <record id="4" aka="AAAAAAAAAAQ=">
+    <pickle>
+      <global name="OOBTree" module="BTrees.OOBTree"/>
+    </pickle>
+    <pickle>
+      <none/>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolUpgraderConstraint/business_template_installed_constraint.xml b/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolBusinessTemplateInstallationConstraint/business_template_installation_constraint.xml
similarity index 92%
rename from bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolUpgraderConstraint/business_template_installed_constraint.xml
rename to bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolBusinessTemplateInstallationConstraint/business_template_installation_constraint.xml
index 7274842742..632a3b3745 100644
--- a/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolUpgraderConstraint/business_template_installed_constraint.xml
+++ b/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolBusinessTemplateInstallationConstraint/business_template_installation_constraint.xml
@@ -34,7 +34,7 @@
         </item>
         <item>
             <key> <string>id</string> </key>
-            <value> <string>business_template_installed_constraint</string> </value>
+            <value> <string>business_template_installation_constraint</string> </value>
         </item>
         <item>
             <key> <string>portal_type</string> </key>
@@ -42,7 +42,7 @@
         </item>
         <item>
             <key> <string>script_id</string> </key>
-            <value> <string>TemplateTool_checkUpgradeConsistency</string> </value>
+            <value> <string>TemplateTool_checkBusinessTemplateInstallation</string> </value>
         </item>
       </dictionary>
     </pickle>
diff --git a/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolPostUpgradeConstraint.xml b/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolTableExistenceConstraint.xml
similarity index 95%
rename from bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolPostUpgradeConstraint.xml
rename to bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolTableExistenceConstraint.xml
index 7272bad134..46ef6c57b1 100644
--- a/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolPostUpgradeConstraint.xml
+++ b/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolTableExistenceConstraint.xml
@@ -32,7 +32,7 @@
         </item>
         <item>
             <key> <string>id</string> </key>
-            <value> <string>TemplateToolPostUpgradeConstraint</string> </value>
+            <value> <string>TemplateToolTableExistenceConstraint</string> </value>
         </item>
         <item>
             <key> <string>portal_type</string> </key>
diff --git a/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolPostUpgradeConstraint/workflow_chain_constraint.xml b/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolTableExistenceConstraint/table_existence_constraint.xml
similarity index 92%
rename from bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolPostUpgradeConstraint/workflow_chain_constraint.xml
rename to bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolTableExistenceConstraint/table_existence_constraint.xml
index c5d84a2132..4ecf7cb583 100644
--- a/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolPostUpgradeConstraint/workflow_chain_constraint.xml
+++ b/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolTableExistenceConstraint/table_existence_constraint.xml
@@ -34,7 +34,7 @@
         </item>
         <item>
             <key> <string>id</string> </key>
-            <value> <string>workflow_chain_constraint</string> </value>
+            <value> <string>table_existence_constraint</string> </value>
         </item>
         <item>
             <key> <string>portal_type</string> </key>
@@ -42,7 +42,7 @@
         </item>
         <item>
             <key> <string>script_id</string> </key>
-            <value> <string>TemplateTool_checkPostUpgradeWorkflowChainConsistency</string> </value>
+            <value> <string>TemplateTool_checkTableExistence</string> </value>
         </item>
       </dictionary>
     </pickle>
diff --git a/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolUpgraderConstraint.xml b/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolWorkflowChainConsistencyConstraint.xml
similarity index 94%
rename from bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolUpgraderConstraint.xml
rename to bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolWorkflowChainConsistencyConstraint.xml
index 25b4f6959b..46778af094 100644
--- a/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolUpgraderConstraint.xml
+++ b/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolWorkflowChainConsistencyConstraint.xml
@@ -32,7 +32,7 @@
         </item>
         <item>
             <key> <string>id</string> </key>
-            <value> <string>TemplateToolUpgraderConstraint</string> </value>
+            <value> <string>TemplateToolWorkflowChainConsistencyConstraint</string> </value>
         </item>
         <item>
             <key> <string>portal_type</string> </key>
diff --git a/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolWorkflowChainConsistencyConstraint/workflow_chain_consistency_constraint.xml b/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolWorkflowChainConsistencyConstraint/workflow_chain_consistency_constraint.xml
new file mode 100644
index 0000000000..e0888f12df
--- /dev/null
+++ b/bt5/erp5_upgrader/PropertySheetTemplateItem/portal_property_sheets/TemplateToolWorkflowChainConsistencyConstraint/workflow_chain_consistency_constraint.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="Script Constraint" module="erp5.portal_type"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_identity_criterion</string> </key>
+            <value>
+              <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+            </value>
+        </item>
+        <item>
+            <key> <string>_range_criterion</string> </key>
+            <value>
+              <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
+            </value>
+        </item>
+        <item>
+            <key> <string>categories</string> </key>
+            <value>
+              <tuple>
+                <string>constraint_type/post_upgrade</string>
+              </tuple>
+            </value>
+        </item>
+        <item>
+            <key> <string>description</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>workflow_chain_consistency_constraint</string> </value>
+        </item>
+        <item>
+            <key> <string>portal_type</string> </key>
+            <value> <string>Script Constraint</string> </value>
+        </item>
+        <item>
+            <key> <string>script_id</string> </key>
+            <value> <string>TemplateTool_checkWorkflowChainConsistency</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="2" aka="AAAAAAAAAAI=">
+    <pickle>
+      <global name="PersistentMapping" module="Persistence.mapping"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>data</string> </key>
+            <value>
+              <dictionary/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="3" aka="AAAAAAAAAAM=">
+    <pickle>
+      <global name="PersistentMapping" module="Persistence.mapping"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>data</string> </key>
+            <value>
+              <dictionary/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkUpgradeConsistency.xml b/bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkBusinessTemplateInstallation.xml
similarity index 96%
rename from bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkUpgradeConsistency.xml
rename to bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkBusinessTemplateInstallation.xml
index 4194fc7f31..62e1edf191 100644
--- a/bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkUpgradeConsistency.xml
+++ b/bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkBusinessTemplateInstallation.xml
@@ -64,7 +64,7 @@ return template_tool.upgradeSite(bt5_list,\n
         </item>
         <item>
             <key> <string>id</string> </key>
-            <value> <string>TemplateTool_checkUpgradeConsistency</string> </value>
+            <value> <string>TemplateTool_checkBusinessTemplateInstallation</string> </value>
         </item>
       </dictionary>
     </pickle>
diff --git a/bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkTableExistence.xml b/bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkTableExistence.xml
new file mode 100644
index 0000000000..225d932808
--- /dev/null
+++ b/bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkTableExistence.xml
@@ -0,0 +1,86 @@
+<?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>"""\n
+Check for some table existence according to the create table list.\n
+If `fixit` is True, then it uses the associated sql_method to create it.\n
+"""\n
+create_table_list = [\n
+  # ("category", "z_create_category"), # example\n
+  ("catalog_full_text", "z_create_catalog_fulltext"),\n
+]\n
+sql_catalog = context.portal_catalog.getSQLCatalog()\n
+table_list = [r[0] for r in sql_catalog.z_show_tables(table="not needed so far")]\n
+report_list = []\n
+for create_table_information in create_table_list:\n
+  if not callable(getattr(sql_catalog, create_table_information[1], None)):\n
+    continue\n
+  if create_table_information[0] not in table_list:\n
+    if fixit:\n
+      getattr(sql_catalog, create_table_information[1], None)()\n
+    else:\n
+      report_list.append("Table `%s` not created (%s)" % create_table_information)\n
+return report_list\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>fixit=False</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>TemplateTool_checkTableExistence</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkPostUpgradeWorkflowChainConsistency.xml b/bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkWorkflowChainConsistency.xml
similarity index 97%
rename from bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkPostUpgradeWorkflowChainConsistency.xml
rename to bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkWorkflowChainConsistency.xml
index 3162958008..87e807ce81 100644
--- a/bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkPostUpgradeWorkflowChainConsistency.xml
+++ b/bt5/erp5_upgrader/SkinTemplateItem/portal_skins/erp5_upgrader/TemplateTool_checkWorkflowChainConsistency.xml
@@ -119,7 +119,7 @@ return error_list\n
         </item>
         <item>
             <key> <string>id</string> </key>
-            <value> <string>TemplateTool_checkPostUpgradeWorkflowChainConsistency</string> </value>
+            <value> <string>TemplateTool_checkWorkflowChainConsistency</string> </value>
         </item>
       </dictionary>
     </pickle>
diff --git a/bt5/erp5_upgrader/bt/template_portal_type_property_sheet_list b/bt5/erp5_upgrader/bt/template_portal_type_property_sheet_list
index 1675f72d04..59235b0f50 100644
--- a/bt5/erp5_upgrader/bt/template_portal_type_property_sheet_list
+++ b/bt5/erp5_upgrader/bt/template_portal_type_property_sheet_list
@@ -1,2 +1,3 @@
-Template Tool | TemplateToolPostUpgradeConstraint
-Template Tool | TemplateToolUpgraderConstraint
\ No newline at end of file
+Template Tool | TemplateToolBusinessTemplateInstallationConstraint
+Template Tool | TemplateToolTableExistenceConstraint
+Template Tool | TemplateToolWorkflowChainConsistencyConstraint
\ No newline at end of file
diff --git a/bt5/erp5_upgrader/bt/template_property_sheet_id_list b/bt5/erp5_upgrader/bt/template_property_sheet_id_list
index 15fa743cdc..83e0b0c521 100644
--- a/bt5/erp5_upgrader/bt/template_property_sheet_id_list
+++ b/bt5/erp5_upgrader/bt/template_property_sheet_id_list
@@ -1,2 +1,3 @@
-TemplateToolUpgraderConstraint
-TemplateToolPostUpgradeConstraint
\ No newline at end of file
+TemplateToolBusinessTemplateInstallationConstraint
+TemplateToolWorkflowChainConsistencyConstraint
+TemplateToolTableExistenceConstraint
\ No newline at end of file
diff --git a/bt5/erp5_upgrader/bt/test_dependency_list b/bt5/erp5_upgrader/bt/test_dependency_list
index eb1f0199f1..576e46274b 100644
--- a/bt5/erp5_upgrader/bt/test_dependency_list
+++ b/bt5/erp5_upgrader/bt/test_dependency_list
@@ -1,3 +1,3 @@
-erp5_full_text_mroonga_catalog
+erp5_full_text_myisam_catalog
 erp5_base
 erp5_upgrader_test
\ No newline at end of file
-- 
2.30.9