Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. # 1. Add "ZS Marketing" and "ZS Employer Branding" Tags to Gaggle 4441
  2. new_organization = Organization.find(4441)
  3. marketing_tag = Tag.find_by(organization_id: 4441, name: 'ZS Employer Branding') # ZS Marketing tag already exists
  4. branding_tag = Tag.create(organization_id: 4441, name: 'ZS Employer Branding') # create ZS Employer Branding tag
  5.  
  6. # 2. Tag all current Members in Gaggle 4441 with “ZS Marketing”
  7. new_organization.stakeholders.includes(:tags).each do |s|
  8. next if s.tags.include? marketing_tag
  9. marketing_tag.stakeholders << s
  10. end
  11.  
  12. # 3. Add all Members from Gaggle 5892 to Gaggle 4441
  13. old_organization = Organization.find(5892)
  14. old_organization.stakeholders.each do |stakeholder|
  15. next if stakeholder.organization_ids.include?(new_organization.id)
  16. affiliation = Affiliation.find_or_create_by(
  17. organization_id: new_organization.id,
  18. stakeholder_id: stakeholder.id,
  19. membership_status: :approved
  20. )
  21. end
  22.  
  23. # 4. Tag all newly add Members in 4441 with "ZS Employer Branding"
  24. new_organization.stakeholders.includes(:tags).where(tags: { id: nil } ).each do |s|
  25. branding_tag.stakeholders << s
  26. end
  27.  
  28. # 5. Update all foreign keys on objects in Gaggle 5892 to point to
  29. # Gaggle 4441: Activities, Campaigns, Rewards, Broadcasts
  30. old_organization.member_activities.update_all(organization_id: new_organization.id)
  31. old_organization.campaigns.update_all(campaignable_id: new_organization.id, campaignable_type: 'Organization')
  32. old_organization.rewards.update_all(organization_id: new_organization.id)
  33. old_organization.broadcasts.update_all(broadcastable_id: new_organization.id, broadcastable_type: 'Organization')
  34.  
  35. ### this needs confirmation from Jason
  36. ## other objects: Managers, Merge Fields, Suggested Messages, Reward Tags
  37. ## Rewards tags should be carried with reward/tags update
  38. new_organization_user_ids = new_organization.user_ids
  39. old_organization.managers.each do |manager|
  40. next if manager.user_id.in? new_organization_user_ids
  41. manager.update(organization_id: new_organization.id)
  42. end
  43. old_organization.merge_fields.update_all(fieldable_id: new_organization, fieldable_type: 'Organization')
  44. old_organization.suggested_messages.update_all(organization_id: new_organization.id)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement