Created
September 27, 2019 12:04
-
-
Save theareba/0d38561941ab20c4be6ab3fc36e85105 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Add "ZS Marketing" and "ZS Employer Branding" Tags to Gaggle 4441 | |
new_organization = Organization.find(4441) | |
marketing_tag = Tag.find_by(organization_id: 4441, name: 'ZS Employer Branding') # ZS Marketing tag already exists | |
branding_tag = Tag.create(organization_id: 4441, name: 'ZS Employer Branding') # create ZS Employer Branding tag | |
# 2. Tag all current Members in Gaggle 4441 with “ZS Marketing” | |
new_organization.stakeholders.includes(:tags).each do |s| | |
next if s.tags.include? marketing_tag | |
marketing_tag.stakeholders << s | |
end | |
# 3. Add all Members from Gaggle 5892 to Gaggle 4441 | |
old_organization = Organization.find(5892) | |
old_organization.stakeholders.each do |stakeholder| | |
next if stakeholder.organization_ids.include?(new_organization.id) | |
affiliation = Affiliation.find_or_create_by( | |
organization_id: new_organization.id, | |
stakeholder_id: stakeholder.id, | |
membership_status: :approved | |
) | |
end | |
# 4. Tag all newly add Members in 4441 with "ZS Employer Branding" | |
new_organization.stakeholders.includes(:tags).where(tags: { id: nil } ).each do |s| | |
branding_tag.stakeholders << s | |
end | |
# 5. Update all foreign keys on objects in Gaggle 5892 to point to | |
# Gaggle 4441: Activities, Campaigns, Rewards, Broadcasts | |
old_organization.member_activities.update_all(organization_id: new_organization.id) | |
old_organization.campaigns.update_all(campaignable_id: new_organization.id, campaignable_type: 'Organization') | |
old_organization.rewards.update_all(organization_id: new_organization.id) | |
old_organization.broadcasts.update_all(broadcastable_id: new_organization.id, broadcastable_type: 'Organization') | |
### this needs confirmation from Jason | |
## other objects: Managers, Merge Fields, Suggested Messages, Reward Tags | |
## Rewards tags should be carried with reward/tags update | |
new_organization_user_ids = new_organization.user_ids | |
old_organization.managers.each do |manager| | |
next if manager.user_id.in? new_organization_user_ids | |
manager.update(organization_id: new_organization.id) | |
end | |
old_organization.merge_fields.update_all(fieldable_id: new_organization, fieldable_type: 'Organization') | |
old_organization.suggested_messages.update_all(organization_id: new_organization.id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment