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)
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
class MeasureFilter < ActiveRecord::Base
end
+ class OldFilter < ActiveRecord::Base
+ set_table_name :filters
+ end
+
class Widget < ActiveRecord::Base
end
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