Skip to content

Instantly share code, notes, and snippets.

@herestomwiththeweather
Created October 11, 2010 22:24
Show Gist options
  • Save herestomwiththeweather/621333 to your computer and use it in GitHub Desktop.
Save herestomwiththeweather/621333 to your computer and use it in GitHub Desktop.
1. create a group -> group_id
2. delete new group's forum and assign old main forum to new group:
Forum.find_by_group_id(group_id).delete
g = Group.find(group_id)
f = Forum.first(:conditions => ['group_id IS ?',nil])
f.group = g
f.save
3. change all members' default accounts to belong to the new group:
accounts = Account.all(:conditions => ['group_id IS ?',nil])
accounts.each {|a| a.group = g;a.save}
4. add everyone to the new group:
Person.all {|p| Membership.request(p,g,false) unless g.owner?(p)}
5. in Req, Offer, Exchange models, temporarily comment out attr_readonly line for group_id
6. assign objects belonging to nil group to the new group:
reqs = Req.all(:conditions => ['group_id IS ?',nil])
reqs.each {|r| r.group=g;r.save}
offers = Offer.all(:conditions => ['group_id IS ?',nil])
offers.each {|o| o.group=g;o.save}
bids = Bid.all(:conditions => ['group_id IS ?',nil])
bids.each {|b| b.group=g;b.save}
exchanges = Exchange.all(:conditions => ['group_id IS ?',nil])
exchanges.each {|e| e.group=g;e.save}
7. uncomment attr_readonly lines previously commented out in Req, Offer, Exchange models
8. update code with groupy branch and rake db:migrate
9. assign everyone's default group to the new group:
Person.all.each {|p| p.default_group = g;p.save}
10. assign each group owner the role of admin for that group:
Group.all.each do |g|
m = Membership.mem(g.owner,g)
unless m.nil? # owner may have left group
unless m.is?(:admin)
puts "Making #{g.owner.name}(#{g.owner.id}) admin of #{g.id}:#{g.name}"
m.add_role('admin')
m.save
else
puts "#{g.owner.name}(#{g.owner.id}) is already admin of #{g.id}:#{g.name}"
end
else
unless g.owner.nil? # owner may be deleted
puts "*** WARNING #{g.owner.name} left #{g.id}:#{g.name}."
else
puts "*** WARNING owner of #{g.id}:#{g.name} deleted."
end
puts "*** Please assign a new owner and make admin"
end
end
11. create a MemberPreference object for each Membership:
Membership.all.each {|m| MemberPreference.create!(:membership => m)}
12. set the default group for new registrations:
p = Preference.first
p.default_group_id = group_id
p.save
13. log out and log in and you should be taken to the new default group!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment