Skip to content

Commit

Permalink
Correctly update all mail_notification options. #6549
Browse files Browse the repository at this point in the history
* Need to check for 't' values to support sqlite
* Need to check the membership count for the 'selected' option

Based on patch contributed by Felix Schäfer

git-svn-id: http://redmine.rubyforge.org/svn/trunk@4246 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
edavis10 committed Oct 10, 2010
1 parent 5a7fe2b commit 682f955
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions db/migrate/20100129193813_update_mail_notification_values.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
# Patch the data from a boolean change.
class UpdateMailNotificationValues < ActiveRecord::Migration
def self.up
User.update_all("mail_notification = 'all'", "mail_notification = '1'")
User.update_all("mail_notification = 'only_my_events'", "mail_notification = '0'")
User.record_timestamps = false
User.all.each do |u|
u.mail_notification = if u.mail_notification =~ /\A(1|t)\z/
# User set for all email (t is for sqlite)
'all'
else
# User wants to recieve notifications on specific projects?
if u.memberships.count(:conditions => {:mail_notification => true}) > 0
'selected'
else
'only_my_events'
end
end
u.save!
end
User.record_timestamps = true
end

def self.down
Expand Down

0 comments on commit 682f955

Please sign in to comment.