incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [2/5] git commit: [#5727] ticket:264 Command for fixing tracker's discussions
Date Tue, 12 Feb 2013 16:59:06 GMT
[#5727] ticket:264 Command for fixing tracker's discussions


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/53aef826
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/53aef826
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/53aef826

Branch: refs/heads/master
Commit: 53aef826c109fbea2833e3f48f93d28bb5ec3814
Parents: ba2f013
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Feb 1 11:26:38 2013 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Tue Feb 12 16:58:47 2013 +0000

----------------------------------------------------------------------
 .../forgetracker/command/fix_discussion.py         |   29 +++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/53aef826/ForgeTracker/forgetracker/command/fix_discussion.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/command/fix_discussion.py b/ForgeTracker/forgetracker/command/fix_discussion.py
index bfac130..14d1482 100644
--- a/ForgeTracker/forgetracker/command/fix_discussion.py
+++ b/ForgeTracker/forgetracker/command/fix_discussion.py
@@ -1,9 +1,12 @@
 from bson import ObjectId
 from bson.errors import InvalidId
+from ming.orm import ThreadLocalORMSession
+from pylons import tmpl_context as c
 
 from allura.command import base
 from allura import model as M
 from allura.lib import exceptions as exc
+from forgetracker.model import Ticket
 
 
 class FixDiscussion(base.Command):
@@ -48,6 +51,32 @@ class FixDiscussion(base.Command):
             self.fix_for_project(project)
         else:
             base.log.info('Checking discussion instances for each tracker in all projects')
+            for project in M.Project.query.find():
+                self.fix_for_project(project)
 
     def fix_for_project(self, project):
+        c.project = project
         base.log.info('Checking discussion instances for each tracker in project %s' % project.shortname)
+        trackers = [ac for ac in project.app_configs
+                       if ac.tool_name.lower() == 'tickets']
+        for tracker in trackers:
+            base.log.info('Found tracker %s' % tracker)
+            for ticket in Ticket.query.find({'app_config_id': tracker._id}):
+                base.log.info('Processing ticket %s [#%s] %s'
+                        % (ticket._id, ticket.ticket_num, ticket.summary))
+                if ticket.discussion_thread.discussion.app_config_id != tracker._id:
+                    # Some tickets were moved from this tracker,
+                    # and Discussion instance for entire tracker was mived too.
+                    # Should move it back.
+                    base.log.info("Some tickets were moved from this tracker. "
+                            "Moving tracker's discussion instance back.")
+                    ticket.discussion_thread.discussion.app_config_id = tracker._id
+
+                if ticket.discussion_thread.discussion_id != tracker.discussion_id:
+                    # Ticket was moved from another tracker.
+                    # Should bind his comment thread to tracker's Discussion
+                    base.log.info("Ticket was moved from another tracker. "
+                            "Bind ticket's comment thread to tracker's Discussion instance.")
+                    ticket.discussion_thread.discussion_id = tracker.discussion_id
+
+            ThreadLocalORMSession.flush_all()


Mime
View raw message