]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3825 fix migration of filters
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 7 Dec 2012 15:01:56 +0000 (16:01 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 7 Dec 2012 15:02:17 +0000 (16:02 +0100)
sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb
sonar-server/src/main/webapp/WEB-INF/db/migrate/360_move_filter_widgets.rb

index 6b83c961d89c0e16b998a4343640ff43af7337bf..7906ec0af08bc3670433bb03dd34badca02f1d6b 100644 (file)
@@ -37,12 +37,12 @@ class MoveExistingMeasureFilters < ActiveRecord::Migration
   class Resource < ActiveRecord::Base
     set_table_name 'projects'
   end
-  class Filter < ActiveRecord::Base
+  class OldFilter < ActiveRecord::Base
     set_table_name 'filters'
   end
 
   def self.up
-    old_filters = Filter.find(:all)
+    old_filters = OldFilter.find(:all)
     say_with_time "Moving #{old_filters.size} measure filters" do
       old_filters.each do |old_filter|
         move(old_filter)
@@ -103,15 +103,15 @@ class MoveExistingMeasureFilters < ActiveRecord::Migration
     metric_criteria_id=1
 
     old_criteria.each do |old|
-      if old.family=='qualifier' && old.text_value
+      if old.family=='qualifier' && old.text_value.present?
         data << "qualifiers=#{old.text_value}"
-      elsif old.family=='name' && old.text_value
+      elsif old.family=='name' && old.text_value.present?
         data << "nameSearch=#{old.text_value}"
-      elsif old.family=='key' && old.text_value
+      elsif old.family=='key' && old.text_value.present?
         data << "keyRegexp=#{old.text_value}"
-      elsif old.family=='language' && old.text_value
+      elsif old.family=='language' && old.text_value.present?
         data << "languages=#{old.text_value}"
-      elsif old.family=='date' && old.value && old.operator
+      elsif old.family=='date' && old.value && old.operator.present?
         data << "ageMaxDays=#{old.value}" if old.operator=='<'
         data << "ageMinDays=#{old.value}" if old.operator=='>'
       elsif old.family=='metric' && old.kee && old.operator && old.value
index ab3e3fe3ae85a9321ea4cbdd74159449dba145fe..1b30481a7a73755aa838d6a39f34e618d22d61d9 100644 (file)
@@ -26,6 +26,10 @@ class MoveFilterWidgets < ActiveRecord::Migration
   class MeasureFilter < ActiveRecord::Base
   end
 
+  class OldFilter < ActiveRecord::Base
+    set_table_name :filters
+  end
+
   class Widget < ActiveRecord::Base
   end
 
@@ -41,14 +45,17 @@ class MoveFilterWidgets < ActiveRecord::Migration
       widgets.each do |widget|
         dashboard = Dashboard.find_by_id(widget.dashboard_id)
         widget_property = WidgetProperty.find(:first, :conditions => {:widget_id => widget.id, :kee => 'filter'})
-        if dashboard && widget_property
-          filter = MeasureFilter.find(:first, :conditions => ['name=? and user_id=?', widget_property.text_value, dashboard.user_id]) if dashboard.user_id
-          filter = MeasureFilter.find(:first, :conditions => ['name=? and shared=?', widget_property.text_value, true]) unless filter
-          if filter
-            widget_property.text_value = filter.id.to_s
-            widget_property.save
-            widget.widget_key = (filter.data.include?('display=treemap') ? 'measure_filter_treemap' : 'measure_filter_list')
-            widget.save
+        if dashboard && widget_property && widget_property.text_value
+          old_filter = OldFilter.find_by_kee(widget_property.text_value)
+          if old_filter
+            filter = MeasureFilter.find(:first, :conditions => ['name=? and user_id=?', old_filter.name, old_filter.user_id]) if old_filter.user_id
+            filter = MeasureFilter.find(:first, :conditions => ['name=? and user_id is null', old_filter.name]) unless filter
+            if filter
+              widget_property.text_value = filter.id.to_s
+              widget_property.save
+              widget.widget_key = (filter.data.include?('display=treemap') ? 'measure_filter_treemap' : 'measure_filter_list')
+              widget.save
+            end
           end
         end
       end