]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3825 upgrade existing widgets on deprecated measure filters
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 4 Dec 2012 12:40:11 +0000 (13:40 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 4 Dec 2012 12:40:11 +0000 (13:40 +0100)
sonar-server/src/main/webapp/WEB-INF/db/migrate/360_move_filter_widgets.rb

index 406963346b907e3a6e6da031f11e4b1ec7c0f135..ec3d14405d0fa0336548b82bd7533f05c345e59c 100644 (file)
@@ -26,8 +26,32 @@ class MoveFilterWidgets < ActiveRecord::Migration
   class MeasureFilter < ActiveRecord::Base
   end
 
-  def self.up
+  class Widget < ActiveRecord::Base
+  end
+
+  class WidgetProperty < ActiveRecord::Base
+  end
 
+  class Dashboard < ActiveRecord::Base
+  end
+
+  def self.up
+    widgets = Widget.find(:all, :conditions => ["widget_key='filter'"])
+    say_with_time "Updading #{widgets.size} widgets" do
+    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
+        end
+      end
+    end
   end
 
 end