Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ct = CallType.find_by(name: "Retention ")
- if ct
- ct.name = "Retention"
- ct.save
- end
- Outcome.all.each do |o|
- next if !o.name
- o.name = o.name.strip
- o.save
- end
- replace_cs = [[704, 700],
- [801, 800]]
- replace_cs.each do |original, replacement|
- CallStatus.where(status: original) do |cs|
- cs.status = replacement
- cs.save
- end
- Call.where(status: original).each do |c|
- c.status = replacement
- c.save
- end
- end
- move = [
- ['Greg Hutchison', 'Inbound', 'Brute Force'],
- ['Chase Kellas', 'Inbound', 'High Rollers'],
- ['Vartan Ouzounian', 'Inbound', 'High Rollers'],
- ['James Coats', 'Inbound', 'Brute Force'],
- ['Marilyn Perez', 'Inbound', 'Brute Force'],
- ['David Mares', 'Inbound', 'Brute Force'],
- ['Ryan Stone', 'Outbound', 'CAPTCHA Amerika'],
- ['David Schad', 'Outbound', 'CAPTCHA Amerika'],
- ['James Giles', 'Outbound', 'Retention'],
- ['Scott Mershon', 'Outbound', 'LXG'],
- ['Rachel Hammond', 'Outbound', 'CAPTCHA Amerika']
- ]
- cts = Company.find(47).call_types
- def to_map(skill_ids)
- skill_ids.map{ |id| [id, []] }.to_h
- end
- def replace(arr, old, n)
- arr.map{ |x| x == old ? n : x }
- end
- move.each do |row|
- first, last = row[0].split(' ')
- u = User.where(first_name: first, last_name: last).first!
- puts "#{row[0]} (#{u.id}): #{row[1]} --> #{row[2]}"
- ct_old = cts.select {|ct| ct.name == row[1]}.first
- ct_new = cts.select {|ct| ct.name == row[2]}.first
- replace_arr = [[45, 13],
- [53, 306]]
- calls = u.calls
- calls.each do |call|
- # outcome
- o_ids = []
- call.outcome_ids.each do |o_id|
- o_old = Outcome.find(o_id)
- o_ids << Outcome.where(call_type: ct_new, name: o_old.name).first!.id
- end
- call.outcome_ids = o_ids
- # tag
- tag_old = Tag.where(id: call.tag_id).first
- call.tag_id = tag_old.nil? ? nil : Tag.where(call_type: ct_new, name: tag_old.name).first!
- call.call_type = ct_new
- # skill
- call.events.each do |event|
- # call.skill_ids, event, eventskill, eventupdate
- skill_ids = event.skill_ids
- replaced = false
- replace_arr.each do |original, replacement|
- if skill_ids.include?(original)
- replaced = true
- skill_ids = replace(skill_ids, original, replacement)
- end
- end
- if replaced
- event.update_skills(to_map(skill_ids), 1157, "team_migration")
- end
- # qar
- QaRecord.where(event_id: event.id).each do |qar|
- qar.call_type_id = ct_new.id
- replace_arr.each do |original, replacement|
- if qar.skill_id == original
- qar.skill_id = replacement
- break
- end
- end
- qar.save
- end
- end
- # calltype
- call.call_type_id = ct_new.id
- call.save
- end
- puts "Moved #{calls.length} calls."
- # call type user
- ctu = CallTypeUserMembership.find_by(user_id: u.id, call_type_id: ct_old.id)
- if ctu
- ctu.active = true
- ctu.call_type_id = ct_new.id
- ctu.save
- puts "Moved to #{row[2]}"
- end
- # permitted ctskill
- replace_arr.each do |original, replacement|
- pcts = PermittedCallTypeSkill.find_by(call_type_id: ct_new.id, skill_id: original)
- if pcts
- pcts.skill_id = replacement
- pcts.save
- puts "Replaced CallTypeSkill ct_id: #{ct_new.id} #{original} --> #{replacement}"
- end
- end
- end
- # 45 -> 13
- # 53 -> 306
- # outcome
- # tag
- # event_skill
- # event.skill_ids
- # call.skill_ids
- # qa_records
- # event_updates
- # permitted_call_type_skills
- # TODO qa quizzes -- not that important
- #
Add Comment
Please, Sign In to add comment