]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3223 Update script to clean reviews with deleted resource
authorFabrice Bellingard <bellingard@gmail.com>
Tue, 14 Feb 2012 12:55:31 +0000 (13:55 +0100)
committerFabrice Bellingard <bellingard@gmail.com>
Tue, 14 Feb 2012 12:56:52 +0000 (13:56 +0100)
sonar-server/src/main/webapp/WEB-INF/db/migrate/260_clean_reviews_with_deleted_users_or_resources.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/db/migrate/260_fix_reviews_with_deleted_user.rb [deleted file]

diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/260_clean_reviews_with_deleted_users_or_resources.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/260_clean_reviews_with_deleted_users_or_resources.rb
new file mode 100644 (file)
index 0000000..b73a34f
--- /dev/null
@@ -0,0 +1,54 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2012 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+#
+
+#
+# Sonar 2.14
+#
+class CleanReviewsWithDeletedUsersOrResources < ActiveRecord::Migration
+
+  def self.up
+    
+    Review.find(:all, :include => ['resource', 'assignee', 'user']).each do |review|
+      if review.resource_id && !review.resource
+        # For http://jira.codehaus.org/browse/SONAR-3223
+        review.destroy
+      else
+        # For http://jira.codehaus.org/browse/SONAR-3102
+        must_save=false
+        if review.user_id && !review.user
+          review.user_id=nil
+          must_save=true
+        end
+        if review.assignee_id && !review.assignee
+          review.assignee_id=nil
+          must_save=true
+        end
+        review.save if must_save
+      end      
+    end
+
+    # For http://jira.codehaus.org/browse/SONAR-3102
+    ReviewComment.find(:all, :include => 'user').each do |comment|
+      comment.delete if comment.user_id && !comment.user
+    end   
+    
+  end
+
+end
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/260_fix_reviews_with_deleted_user.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/260_fix_reviews_with_deleted_user.rb
deleted file mode 100644 (file)
index 11b303f..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#
-# Sonar, entreprise quality control tool.
-# Copyright (C) 2008-2012 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# Sonar is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# Sonar is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with Sonar; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
-#
-
-#
-# Sonar 2.14
-#
-class FixReviewsWithDeletedUser < ActiveRecord::Migration
-
-  def self.up
-    # For http://jira.codehaus.org/browse/SONAR-3102
-    must_save=false
-    Review.find(:all, :include => ['assignee', 'user']).each do |review|
-      if review.user_id && !review.user
-        review.user_id=nil
-        must_save=true
-      end
-      if review.assignee_id && !review.assignee
-        review.assignee_id=nil
-        must_save=true
-      end
-      review.save if must_save
-    end
-
-    ReviewComment.find(:all, :include => 'user').each do |comment|
-      comment.delete if comment.user_id && !comment.user
-    end
-  end
-
-end