Commit dbfbdcd4 authored by Jérome Perrin's avatar Jérome Perrin

upgrader: really execute the whole `upgrade` step in one transaction

Documentation says this step is done in one transaction, so implement
this as documented.

Detecting developer mistake and automagically running this step in smaller
transactions if more than 100 documents seems unnecessary. At least, it
contredicts documentation.
parent 59cce559
......@@ -50,19 +50,14 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
"""\n
<value> <string>"""\n
Run Upgrade step\n
\n
IMPORTANT: Don\'t use the constraint_type upgrader to data migration or big amount of objects,\n
because this step is suppose to run all constraints in the same transaction. \n
To not kill the instance, searchAndActivate will be used if countResults() > REINDEX_SPLIT_COUNT\n
"""\n
\n
REINDEX_SPLIT_COUNT = 100\n
portal = context.getPortalObject()\n
portal_alarms = portal.portal_alarms\n
\n
_, type_per_constraint_type = context.Base_getConstraintTypeListPerPortalType()\n
portal_type_list = type_per_constraint_type.get(\'upgrader\', [])\n
......@@ -82,22 +77,16 @@ with context.defaultActivateParameterDict(activate_kw, placeless=True):\n
\'activate_kw\': activate_kw,\n
}\n
\n
# always run on portal_templates, regardless of catalog state.\n
portal.portal_templates.Base_postCheckConsistencyResult(**method_kw)\n
for portal_type in portal_type_list:\n
if portal.portal_catalog.countResults(\n
portal_type=portal_type_list)[0][0] > REINDEX_SPLIT_COUNT:\n
portal.portal_catalog.searchAndActivate(\'Base_postCheckConsistencyResult\',\n
activate_kw=activate_kw,\n
portal_type=portal_type,\n
method_kw=method_kw)\n
else:\n
for result in portal.portal_catalog(portal_type=portal_type):\n
\n
# run on all portal_types with an `upgrader` constraint, except portal_templates we already run before.\n
if portal_type_list:\n
for result in portal.portal_catalog(portal_type=portal_type_list):\n
result.Base_postCheckConsistencyResult(**method_kw)\n
\n
context.setEnabled(False)\n
]]></string> </value>
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
......
......@@ -333,28 +333,12 @@ class TestUpgrader(ERP5TypeTestCase):
self.assertEqual({'immediateReindexObject', 'unindexObject'},
{x.method_id for x in portal_activities.getMessageList()})
def stepCreateBigIncosistentData(self, sequence=None):
for _ in range(101):
self.portal.organisation_module.newContent(
portal_type="Organisation",
title="org_%s" % self.portal.organisation_module.getLastId())
def stepCreateSmallIncosistentData(self, sequence=None):
for _ in range(4):
self.portal.organisation_module.newContent(
portal_type="Organisation",
title="org_%s" % self.portal.organisation_module.getLastId())
def stepCheckActivitiesCreated(self, sequence=None):
portal_activities = self.getActivityTool()
self.assertEqual({'Alarm_runUpgrader', 'notify'},
{x.method_id for x in portal_activities.getMessageList()})
for message in portal_activities.getMessageList():
portal_activities.manageInvoke(message.object_path, message.method_id)
self.commit()
self.assertIn('Base_postCheckConsistencyResult',
{x.method_id for x in portal_activities.getMessageList()})
def stepUninstallERP5UpgraderTestBT(self, sequence=None):
bt5 = self.portal.portal_templates.getInstalledBusinessTemplate('erp5_web')
bt5.uninstall()
......@@ -568,12 +552,6 @@ class TestUpgrader(ERP5TypeTestCase):
stepTic
stepRunUpgrader
stepCheckNoActivitiesCreated
stepCreateBigIncosistentData
stepTic
stepActiveSenseUpgradeAlarm
stepTic
stepRunUpgrader
stepCheckActivitiesCreated
stepRemoveConstraintFromOrganisationPortalType
"""
sequence_list.addSequenceString(sequence_string)
......
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