summaryrefslogtreecommitdiff
path: root/db/migrate
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-07-12 10:31:00 +0200
committerPeter Kozak <spag@golwen.net>2013-07-12 10:31:00 +0200
commitab8c251a06b81cbc700a0aa0bd16cb8089d3f611 (patch)
treea5627b3f534199c157880e40a6f30eaaa465a06d /db/migrate
parentddbc75fa1ac525b8721fc5b2f40f91b9df94ee2f (diff)
try to adapt existing call forwarding entries to new table structure
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20130225091200_add_destinationable_to_call_forward.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/db/migrate/20130225091200_add_destinationable_to_call_forward.rb b/db/migrate/20130225091200_add_destinationable_to_call_forward.rb
index 89e4b3b..56f7df4 100644
--- a/db/migrate/20130225091200_add_destinationable_to_call_forward.rb
+++ b/db/migrate/20130225091200_add_destinationable_to_call_forward.rb
@@ -4,7 +4,19 @@ class AddDestinationableToCallForward < ActiveRecord::Migration
add_column :call_forwards, :destinationable_id, :integer
CallForward.all.each do |call_forward|
- call_forward.update_attributes(:destinationable_type => call_forward.call_forwardable_type, :destinationable_id => call_forward.call_forwardable_id, :call_forwardable_type => 'PhoneNumber', :call_forwardable_id => call_forward.phone_number_id )
+ phone_number = PhoneNumber.where(:id => call_forward.phone_number_id).first
+ if phone_number and phone_number.phone_numberable.class == SipAccount
+ account = phone_number.phone_numberable
+ result = call_forward.update_attributes(:destinationable_type => call_forward.call_forwardable_type, :destinationable_id => call_forward.call_forwardable_id, :call_forwardable_type => account.class.to_s, :call_forwardable_id => account.id)
+ else
+ call_forward.update_attributes(:destinationable_type => call_forward.call_forwardable_type, :destinationable_id => call_forward.call_forwardable_id, :call_forwardable_type => 'PhoneNumber', :call_forwardable_id => call_forward.phone_number_id)
+ end
+ end
+
+ cf_groups = CallForward.order('active DESC').all.group_by{|cf| [cf.call_forwardable_type, cf.call_forwardable_id, cf.call_forward_case_id, cf.destinationable_type, cf.destinationable_id, cf.destination, cf.source]}
+ cf_groups.values.each do |duplicates|
+ first_item = duplicates.shift
+ duplicates.each{|duplicate| duplicate.destroy}
end
remove_column :call_forwards, :phone_number_id