From: Maurits v. R. <svn...@pl...> - 2008-08-31 20:24:18
|
Author: maurits Date: Sun Aug 31 20:24:15 2008 New Revision: 70958 Modified: Products.Poi/trunk/Products/Poi/HISTORY.txt Products.Poi/trunk/Products/Poi/configure.zcml Products.Poi/trunk/Products/Poi/migration.py Products.Poi/trunk/Products/Poi/tests/migration.txt Log: Added migration step to migrate workflow changes (in the responses) from ids to titles. Modified: Products.Poi/trunk/Products/Poi/HISTORY.txt ============================================================================== --- Products.Poi/trunk/Products/Poi/HISTORY.txt (original) +++ Products.Poi/trunk/Products/Poi/HISTORY.txt Sun Aug 31 20:24:15 2008 @@ -6,6 +6,9 @@ 1.2rc1 (unreleased) ------------------- +- Added migration step to migrate workflow changes (in the responses) + from ids to titles. [maurits] + - Only show the add response form the the user is allowed to add a response. [maurits] Modified: Products.Poi/trunk/Products/Poi/configure.zcml ============================================================================== --- Products.Poi/trunk/Products/Poi/configure.zcml (original) +++ Products.Poi/trunk/Products/Poi/configure.zcml Sun Aug 31 20:24:15 2008 @@ -94,4 +94,13 @@ sortkey="2" profile="Products.Poi:default" /> + <gs:upgradeStep + title="Workflow titles in responses" + description="Migrate workflow changes from ids to titles." + source="1.1" + destination="1.2" + handler="Products.Poi.migration.migrate_workflow_changes" + sortkey="3" + profile="Products.Poi:default" /> + </configure> Modified: Products.Poi/trunk/Products/Poi/migration.py ============================================================================== --- Products.Poi/trunk/Products/Poi/migration.py (original) +++ Products.Poi/trunk/Products/Poi/migration.py Sun Aug 31 20:24:15 2008 @@ -60,6 +60,7 @@ # This seems a good time to reindex the issue for good measure. issue.reindexObject() + def migrate_responses(context): log.info("Starting migration of old style to new style responses.") catalog = getToolByName(context, 'portal_catalog') @@ -78,6 +79,51 @@ tracker.setSendNotificationEmails(original_send_emails) +def migrate_workflow_changes(context): + """Migrate workflow changes from ids to titles. + + When a response changes the workflow state of an issue, this + change is recorded in that response. This used to be done by + storing review state ids. Currently this is done by storing + review state titles. Friendlier for the end user and translatable + to boot. This migration finds responses with review state ids in + them and turns them into titles. + """ + log.info("Starting migration of workflow changes.") + catalog = getToolByName(context, 'portal_catalog') + wftool = getToolByName(context, 'portal_workflow') + + def get_state_title(state_id): + # This neatly returns the input when there is no such review + # state id, which happens when the 'state_id' is already a + # title. + return wftool.getTitleForStateOnType(state_id, 'PoiIssue') + + issue_brains = catalog.searchResults(portal_type='PoiIssue') + log.info("Found %s PoiIssues.", len(issue_brains)) + fixed = 0 + for brain in issue_brains: + issue = brain.getObject() + folder = IResponseContainer(issue) + made_changes = False + for response in folder: + for change in response.changes: + #def add_change(self, id, name, before, after): + if change['id'] != 'review_state': + continue + before = get_state_title(change['before']) + if change['before'] != before: + made_changes = True + change['before'] = before + change['after'] = get_state_title(change['after']) + if made_changes: + fixed += 1 + if fixed % 100 == 0: + log.info("Fixed %s PoiIssues so far; still busy...", fixed) + log.info("Migration completed. %s PoiIssues needed fixing.", fixed) + + + def fix_descriptions(context): """Fix issue Descriptions. Modified: Products.Poi/trunk/Products/Poi/tests/migration.txt ============================================================================== --- Products.Poi/trunk/Products/Poi/tests/migration.txt (original) +++ Products.Poi/trunk/Products/Poi/tests/migration.txt Sun Aug 31 20:24:15 2008 @@ -174,3 +174,34 @@ ... issue = issue.getObject() ... rc = IResponseContainer(issue) ... self.assertEqual(len(rc), 4) + + +Migrate workflow changes from ids to titles +------------------------------------------- + +When a response changes the workflow state of an issue, this change is +recorded in that response. This used to be done by storing review +state ids. Currently this is done by storing review state titles. +Friendlier for the end user and translatable to boot. We have a +migration step that finds responses with review state ids in them and +turns them into titles. + + >>> from Products.Poi.migration import migrate_workflow_changes + >>> for brain in issues: + ... issue = brain.getObject() + ... rc = IResponseContainer(issue) + ... for response in rc: + ... self.assertEquals(len(response.changes), 0) + ... # Add change with review state ids: + ... response.add_change('review_state', u'Issue state', 'unconfirmed', 'open') + ... self.assertEquals(response.changes[0]['before'], 'unconfirmed') + ... self.assertEquals(response.changes[0]['after'], 'open') + >>> migrate_workflow_changes(self.portal) + >>> for brain in issues: + ... issue = brain.getObject() + ... rc = IResponseContainer(issue) + ... for response in rc: + ... self.assertEquals(len(response.changes), 1) + ... # The review state ids are now titles: + ... self.assertEquals(response.changes[0]['before'], 'Unconfirmed') + ... self.assertEquals(response.changes[0]['after'], 'Confirmed') |