From fbe45b36842750685115e635d01e8ab074d0f516 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 7 Dec 2012 16:01:56 +0100 Subject: [PATCH] SONAR-3825 fix migration of filters --- .../357_move_existing_measure_filters.rb | 14 +++++------ .../db/migrate/360_move_filter_widgets.rb | 23 ++++++++++++------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb index 6b83c961d89..7906ec0af08 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/360_move_filter_widgets.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/360_move_filter_widgets.rb index ab3e3fe3ae8..1b30481a7a7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/360_move_filter_widgets.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/360_move_filter_widgets.rb @@ -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 -- 2.39.5