diff --git a/app/models/legacy/object_state.rb b/app/models/legacy/object_state.rb index 8ab059d8d..9c7938c51 100644 --- a/app/models/legacy/object_state.rb +++ b/app/models/legacy/object_state.rb @@ -79,5 +79,19 @@ module Legacy map[state_id] end + + + class << self + def changes_dates_for domain_id + sql = %Q{SELECT t_2.id, state.* + FROM object_history t_2 + JOIN object_state state ON (t_2.historyid >= state.ohid_from + AND (t_2.historyid <= state.ohid_to OR state.ohid_to IS NULL)) + AND t_2.id = state.object_id + WHERE state.object_id=#{domain_id} + ORDER BY t_2.historyid;} + find_by_sql(sql).map{|e| e.attributes.values_at("valid_from", "valid_to") }.flatten.each_with_object({}){|e,h|h[e] = [self]} + end + end end end diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index d2e0a8b7b..0e790bf20 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -772,6 +772,8 @@ namespace :import do Legacy::DomainHistory.uniq.pluck(:id).each do |legacy_domain_id| # 1. add domain changes # 2. add states + # compose hash of change time -> Object changes + history = Legacy::ObjectState.changes_dates_for(legacy_domain_id) end